脚本要求
- 将已存在的org转成html
- 把html复制到nginx的代理目录形成可查看的链接
- 把nginx的链接和最新的git提交信息发送给钉钉通知群
脚本内容
#!/bin/bash
ls -l target
datetime=`date +'%%Y%%m%%d%%H%%M%%S'`
reportname=batch-api-test-rpt-$datetime.zip
emacs -batch -l ~/.emacs.d/elpa-29.2/htmlize-20210825.2150/htmlize.el target/Batch测试报告.org -f org-html-export-to-html --kill
# 切换到目标目录
cd target || { echo "Directory not found: chutian-front/target"; exit 1; }
# zip -r $reportname *
mv Batch测试报告.html index.html
report_link="http://192.168.0.134:8110/batch/api/$datetime/index.html"
html_head='
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Batch-API测试报告</title>
<meta name="author" content="青岛红创-Batch" />
<meta name="generator" content="Org Mode" />
<link rel="stylesheet" type="text/css" href="https://hcapplet.3vyd.com/org-theme/src/readtheorg_theme/css/htmlize.css"/>
<link rel="stylesheet" type="text/css" href="https://hcapplet.3vyd.com/org-theme/src/readtheorg_theme/css/readtheorg.css"/>
<script src="https://hcapplet.3vyd.com/org-theme/src/lib/js/jquery.min.js"></script>
<script src="https://hcapplet.3vyd.com/org-theme/src/lib/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://hcapplet.3vyd.com/org-theme/src/lib/js/jquery.stickytableheaders.min.js"></script>
<script type="text/javascript" src="https://hcapplet.3vyd.com/org-theme/src/readtheorg_theme/js/readtheorg.js"></script>
</head>
'
# 将新文本写入临时文件
echo "$html_head" > temp_file.html
# 将原文件内容追加到临时文件后
cat index.html >> temp_file.html
# 用临时文件替换原文件
mv temp_file.html index.html
mkdir -p /Users/a123/Downloads/test-report/batch/api/$datetime
cp -r * /Users/a123/Downloads/test-report/batch/api/$datetime/
# 定义文件路径
file_path="ding-msg.edn"
# 读取文件内容并去掉首尾的双引号
file_content=$(sed 's/^"\(.*\)"$/\1/' "$file_path")
# 拼接字符串
combined_content="${file_content}\n [点击链接查看报告详情](${report_link})"
# 打印拼接后的内容
echo -e "$combined_content"
# 发送消息到DingTalk
curl --location 'https://oapi.dingtalk.com/robot/send?access_token=43d9635c7a20220071dbf0cfee918f1baddaf08039719bd14190b9db0996450f' \
--header 'Content-Type: application/json' \
--data "{
\"msgtype\": \"markdown\",
\"at\": {\"isAtAll\": true},
\"markdown\": {\"title\": \"楚天Batch API测试报告\",
\"text\": \"## 楚天Batch(API单元测试结果) \n ${combined_content} \"}
}"
说明
- 通过emacs的org转html要安装emacs的插件,htmlize
- git的msg不是这个脚本获取的,而是其他地方获取后放在ding-msg.edn中的
-
效果截图
image.png