11#! /bin/sh
2+ # https://stackoverflow.com/questions/13872048/bash-script-what-does-bin-bash-mean
3+ echo " 1/5: checking TRAVIS_TEST_RESULT"
24if [ " $TRAVIS_TEST_RESULT " != " 0" ]
35then
46 echo " build not success, bye"
57 exit 1
68fi
79
8- git remote add github https://$GITHUB_TOKEN @github.com/FEMessage/el-form-renderer.git > /dev/null 2>&1
10+ ORG_NAME=$( echo " $TRAVIS_REPO_SLUG " | cut -d ' /' -f 1)
11+ REPO_NAME=$( echo " $TRAVIS_REPO_SLUG " | cut -d ' /' -f 2)
12+
13+ echo " 2/5: pushing commit and tag to github"
14+ # 该命令很可能报错,但不影响实际进行,因而不能简单地在脚本开头 set -e
15+ git remote add github https://$GITHUB_TOKEN @github.com/$TRAVIS_REPO_SLUG .git > /dev/null 2>&1
916git push github HEAD:master --follow-tags
1017
18+ echo " 3/5: generating github release notes"
1119GREN_GITHUB_TOKEN=$GITHUB_TOKEN yarn release
1220
13- url=https://api.github.com/repos/FEMessage/el-form-renderer/releases/latest
21+ # 避免发送错误信息
22+ if [ $? -ne 0 ]
23+ then
24+ echo " gren fails, bye"
25+ exit 1
26+ fi
27+
28+ echo " 4/5: downloading github release info"
29+ url=https://api.github.com/repos/$TRAVIS_REPO_SLUG /releases/latest
1430resp_tmp_file=resp.tmp
1531
1632curl -H " Authorization: token $GITHUB_TOKEN " $url > $resp_tmp_file
@@ -19,8 +35,11 @@ html_url=$(sed -n 5p $resp_tmp_file | sed 's/\"html_url\"://g' | awk -F '"' '{pr
1935body=$( grep body < $resp_tmp_file | sed ' s/\"body\"://g;s/\"//g' )
2036version=$( echo $html_url | awk -F ' /' ' {print $NF}' )
2137
22- msg=' {"msgtype": "markdown", "markdown": {"title": "el-form-renderer更新", "text": "@所有人\n# [el-form-renderer(' $version ' )](' $html_url ' )\n' $body ' "}}'
38+ echo " 5/5: notifying with dingtalk bot"
39+ msg=' {"msgtype": "markdown", "markdown": {"title": "' $REPO_NAME ' 更新", "text": "@所有人\n# [' $REPO_NAME ' (' $version ' )](' $html_url ' )\n' $body ' "}}'
2340
2441curl -X POST https://oapi.dingtalk.com/robot/send\? access_token\= $DINGTALK_ROBOT_TOKEN -H ' Content-Type: application/json' -d " $msg "
2542
2643rm $resp_tmp_file
44+
45+ echo " executing notify.sh successfully"
0 commit comments