Skip to content

Commit 246ab64

Browse files
author
pptfz
committed
更新构建通知,新增构建时长展示
1 parent ec0ed2d commit 246ab64

1 file changed

Lines changed: 116 additions & 18 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 116 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,106 @@
1+
# name: Deploy to GitHub Pages
2+
3+
# on:
4+
# push:
5+
# branches:
6+
# - master
7+
# # Review gh actions docs if you want to further define triggers, paths, etc
8+
# # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on
9+
10+
# jobs:
11+
# build:
12+
# name: Build Docusaurus
13+
# runs-on: ubuntu-latest
14+
# steps:
15+
# - uses: actions/checkout@v4
16+
# with:
17+
# fetch-depth: 0
18+
# - uses: actions/setup-node@v4
19+
# with:
20+
# node-version: 20
21+
# cache: npm
22+
23+
# # - name: Install dependencies
24+
# # run: yarn install --frozen-lockfile
25+
# # - name: Build website
26+
# # run: yarn build
27+
28+
# - name: Install dependencies
29+
# run: npm ci
30+
31+
# - name: Build website
32+
# env:
33+
# ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
34+
# ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
35+
# ALGOLIA_INDEX_NAME: ${{ secrets.ALGOLIA_INDEX_NAME }}
36+
# run: npm run build
37+
38+
# - name: Upload Build Artifact
39+
# uses: actions/upload-pages-artifact@v3
40+
# with:
41+
# path: build
42+
43+
# - name: Extract commit message
44+
# id: extract_commit_message
45+
# run: echo "COMMIT_MSG=$(git log -1 --pretty=%B | tr -d '\n')" >> $GITHUB_ENV
46+
47+
# - name: Send notification on success
48+
# if: success()
49+
# env:
50+
# WEBHOOK_KEY: ${{ secrets.WECHAT_WEBHOOK_KEY }}
51+
# COMMIT_MSG: ${{ env.COMMIT_MSG }}
52+
# run: |
53+
# TIMESTAMP=$(TZ=Asia/Shanghai date "+%Y-%m-%d %H:%M:%S")
54+
# curl -X POST -H 'Content-Type: application/json' \
55+
# -d '{
56+
# "msgtype": "markdown",
57+
# "markdown": {
58+
# "content": "**发布结果通知**\n\n**申请标题:** '"${COMMIT_MSG}"'\n\n**应用名称:** docusaurus\n\n**应用版本**: master#${{ github.sha }}\n\n**执行人员:** Webhook\n\n**发布结果:** <font color=\"info\">成功</font>\n\n**发布时间:** '"${TIMESTAMP}"'\n\n> 来自 GitHub Actions"
59+
# }
60+
# }' \
61+
# https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${WEBHOOK_KEY}
62+
63+
# - name: Send failure notification
64+
# if: failure()
65+
# env:
66+
# WEBHOOK_KEY: ${{ secrets.WECHAT_WEBHOOK_KEY }}
67+
# COMMIT_MSG: ${{ env.COMMIT_MSG }}
68+
# run: |
69+
# TIMESTAMP=$(TZ=Asia/Shanghai date "+%Y-%m-%d %H:%M:%S")
70+
# curl -X POST -H 'Content-Type: application/json' \
71+
# -d '{
72+
# "msgtype": "markdown",
73+
# "markdown": {
74+
# "content": "**发布结果通知**\n\n申请标题: '"${COMMIT_MSG}"'\n\n应用名称: docusaurus\n\n应用版本: master#${{ github.sha }}\n\n执行人员: Webhook\n\n发布结果: <font color=\"waring\">失败</font>\n\n发布时间: '"${TIMESTAMP}"'\n\n> 来自 GitHub Actions"
75+
# }
76+
# }' \
77+
# https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${WEBHOOK_KEY}
78+
79+
# deploy:
80+
# name: Deploy to GitHub Pages
81+
# needs: build
82+
83+
# # Grant GITHUB_TOKEN the permissions required to make a Pages deployment
84+
# permissions:
85+
# pages: write # to deploy to Pages
86+
# id-token: write # to verify the deployment originates from an appropriate source
87+
88+
# # Deploy to the github-pages environment
89+
# environment:
90+
# name: github-pages
91+
# url: ${{ steps.deployment.outputs.page_url }}
92+
93+
# runs-on: ubuntu-latest
94+
# steps:
95+
# - name: Deploy to GitHub Pages
96+
# id: deployment
97+
# uses: actions/deploy-pages@v4
198
name: Deploy to GitHub Pages
299

3100
on:
4101
push:
5102
branches:
6103
- master
7-
# Review gh actions docs if you want to further define triggers, paths, etc
8-
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on
9104

10105
jobs:
11106
build:
@@ -15,16 +110,12 @@ jobs:
15110
- uses: actions/checkout@v4
16111
with:
17112
fetch-depth: 0
113+
18114
- uses: actions/setup-node@v4
19115
with:
20116
node-version: 20
21117
cache: npm
22118

23-
# - name: Install dependencies
24-
# run: yarn install --frozen-lockfile
25-
# - name: Build website
26-
# run: yarn build
27-
28119
- name: Install dependencies
29120
run: npm ci
30121

@@ -50,12 +141,19 @@ jobs:
50141
WEBHOOK_KEY: ${{ secrets.WECHAT_WEBHOOK_KEY }}
51142
COMMIT_MSG: ${{ env.COMMIT_MSG }}
52143
run: |
144+
# 计算构建耗时
145+
START_TS=$(date -d "${GITHUB_RUN_STARTED_AT}" +%s)
146+
END_TS=$(date +%s)
147+
DURATION=$((END_TS - START_TS))
148+
DURATION_FMT="$(($DURATION / 60)) 分 $(($DURATION % 60)) 秒"
149+
53150
TIMESTAMP=$(TZ=Asia/Shanghai date "+%Y-%m-%d %H:%M:%S")
151+
54152
curl -X POST -H 'Content-Type: application/json' \
55153
-d '{
56154
"msgtype": "markdown",
57155
"markdown": {
58-
"content": "**发布结果通知**\n\n**申请标题:** '"${COMMIT_MSG}"'\n\n**应用名称:** docusaurus\n\n**应用版本**: master#${{ github.sha }}\n\n**执行人员:** Webhook\n\n**发布结果:** <font color=\"info\">成功</font>\n\n**发布时间:** '"${TIMESTAMP}"'\n\n> 来自 GitHub Actions"
156+
"content": "**发布结果通知**\n\n**申请标题:** '"${COMMIT_MSG}"'\n\n**应用名称:** docusaurus\n\n**应用版本:** master#${{ github.sha }}\n\n**执行人员:** Webhook\n\n**发布结果:** <font color=\"info\">成功</font>\n\n**构建耗时:** '"${DURATION_FMT}"'\n\n**发布时间:** '"${TIMESTAMP}"'\n\n> 来自 GitHub Actions"
59157
}
60158
}' \
61159
https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${WEBHOOK_KEY}
@@ -66,34 +164,34 @@ jobs:
66164
WEBHOOK_KEY: ${{ secrets.WECHAT_WEBHOOK_KEY }}
67165
COMMIT_MSG: ${{ env.COMMIT_MSG }}
68166
run: |
167+
# 计算构建耗时
168+
START_TS=$(date -d "${GITHUB_RUN_STARTED_AT}" +%s)
169+
END_TS=$(date +%s)
170+
DURATION=$((END_TS - START_TS))
171+
DURATION_FMT="$(($DURATION / 60)) 分 $(($DURATION % 60)) 秒"
172+
69173
TIMESTAMP=$(TZ=Asia/Shanghai date "+%Y-%m-%d %H:%M:%S")
174+
70175
curl -X POST -H 'Content-Type: application/json' \
71176
-d '{
72177
"msgtype": "markdown",
73178
"markdown": {
74-
"content": "**发布结果通知**\n\n申请标题: '"${COMMIT_MSG}"'\n\n应用名称: docusaurus\n\n应用版本: master#${{ github.sha }}\n\n执行人员: Webhook\n\n发布结果: <font color=\"waring\">失败</font>\n\n发布时间: '"${TIMESTAMP}"'\n\n> 来自 GitHub Actions"
179+
"content": "**发布结果通知**\n\n申请标题: '"${COMMIT_MSG}"'\n\n应用名称: docusaurus\n\n应用版本: master#${{ github.sha }}\n\n执行人员: Webhook\n\n发布结果: <font color=\"waring\">失败</font>\n\n**构建耗时:** '"${DURATION_FMT}"'\n\n发布时间: '"${TIMESTAMP}"'\n\n> 来自 GitHub Actions"
75180
}
76181
}' \
77182
https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${WEBHOOK_KEY}
78183
79184
deploy:
80185
name: Deploy to GitHub Pages
81186
needs: build
82-
83-
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
84187
permissions:
85-
pages: write # to deploy to Pages
86-
id-token: write # to verify the deployment originates from an appropriate source
87-
88-
# Deploy to the github-pages environment
188+
pages: write
189+
id-token: write
89190
environment:
90191
name: github-pages
91192
url: ${{ steps.deployment.outputs.page_url }}
92-
93193
runs-on: ubuntu-latest
94194
steps:
95195
- name: Deploy to GitHub Pages
96196
id: deployment
97197
uses: actions/deploy-pages@v4
98-
99-

0 commit comments

Comments
 (0)