Skip to content

Commit 47578f7

Browse files
committed
feat: 移除旧的文档差异生成脚本并引入新的实现,更新工作流以支持新的文档差异评论功能
1 parent 1aaadcb commit 47578f7

6 files changed

Lines changed: 294 additions & 282 deletions

File tree

.github/scripts/build_doc_diff_comment.dart

Lines changed: 0 additions & 205 deletions
This file was deleted.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# 构建完成后:单独发布「文档变更 diff」PR 评论(与预览评论分离)
2+
name: PR 文档 diff 评论
3+
4+
on:
5+
workflow_run:
6+
workflows: ["PR 文档预览构建"]
7+
types:
8+
- completed
9+
10+
permissions:
11+
pull-requests: write
12+
13+
jobs:
14+
发布文档-diff评论:
15+
runs-on: ubuntu-latest
16+
if: >
17+
github.event.workflow_run.event == 'pull_request' &&
18+
github.event.workflow_run.conclusion == 'success'
19+
steps:
20+
- name: 下载 PR 元数据
21+
uses: actions/download-artifact@v4
22+
with:
23+
name: pr-metadata
24+
run-id: ${{ github.event.workflow_run.id }}
25+
github-token: ${{ secrets.GITHUB_TOKEN }}
26+
27+
- name: 解析 PR 编号
28+
id: pr
29+
run: echo "number=$(cat pr-number.txt)" >> $GITHUB_OUTPUT
30+
31+
- name: 组装文档 diff 评论正文
32+
run: |
33+
{
34+
echo '<details>'
35+
echo '<summary>📄 文档变更 diff(点击展开)</summary>'
36+
echo ''
37+
cat doc-diff-comment.md
38+
echo ''
39+
echo '</details>'
40+
echo ''
41+
echo '<!-- AUTO_DOC_DIFF_HOOK -->'
42+
} > pr-doc-diff-comment.md
43+
44+
- name: 更新 PR 文档 diff 评论
45+
uses: TDesignOteam/workflows/actions/maintain-one-comment@main
46+
with:
47+
token: ${{ secrets.GITHUB_TOKEN }}
48+
body-path: pr-doc-diff-comment.md
49+
number: ${{ steps.pr.outputs.number }}
50+
body-include: "<!-- AUTO_DOC_DIFF_HOOK -->"
51+
52+
构建失败通知:
53+
runs-on: ubuntu-latest
54+
if: >
55+
github.event.workflow_run.event == 'pull_request' &&
56+
github.event.workflow_run.conclusion == 'failure'
57+
steps:
58+
- name: 解析 PR 编号
59+
id: pr
60+
run: |
61+
PR_URL="${{ github.event.workflow_run.pull_requests[0].url }}"
62+
echo "number=${PR_URL##*/}" >> $GITHUB_OUTPUT
63+
64+
- name: 标记文档 diff 评论为构建失败
65+
uses: TDesignOteam/workflows/actions/maintain-one-comment@main
66+
with:
67+
token: ${{ secrets.GITHUB_TOKEN }}
68+
body: |
69+
_文档 diff 未生成:预览构建失败。_
70+
<!-- AUTO_DOC_DIFF_HOOK -->
71+
number: ${{ steps.pr.outputs.number }}
72+
body-include: "<!-- AUTO_DOC_DIFF_HOOK -->"
Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# 构建完成后:部署 Surge 预览,并更新 PR 预览评论(文档 diff 见 doc-diff-comment.yml)
12
name: PR 预览发布
23

34
on:
@@ -7,29 +8,27 @@ on:
78
- completed
89

910
env:
10-
FAILURE_BODY: |
11+
BUILD_FAILURE_BODY: |
12+
[<img height="96" alt="失败" src="https://user-images.githubusercontent.com/5378891/75333447-1e63a280-58c1-11ea-975d-235367fd1522.png">](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }})
13+
<!-- AUTO_PREVIEW_HOOK -->
14+
DEPLOY_FAILURE_BODY: |
1115
[<img height="96" alt="失败" src="https://user-images.githubusercontent.com/5378891/75333447-1e63a280-58c1-11ea-975d-235367fd1522.png">](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
1216
<!-- AUTO_PREVIEW_HOOK -->
1317
18+
permissions:
19+
pull-requests: write
20+
1421
jobs:
1522
部署预览并评论:
1623
runs-on: ubuntu-latest
1724
if: >
1825
github.event.workflow_run.event == 'pull_request' &&
1926
github.event.workflow_run.conclusion == 'success'
2027
steps:
21-
- name: 下载 PR 编号
22-
uses: actions/download-artifact@v4
23-
with:
24-
name: pr-number
25-
run-id: ${{ github.event.workflow_run.id }}
26-
github-token: ${{ secrets.GITHUB_TOKEN }}
27-
28-
- name: 下载文档 diff 评论
28+
- name: 下载 PR 元数据
2929
uses: actions/download-artifact@v4
30-
continue-on-error: true
3130
with:
32-
name: preview-metadata
31+
name: pr-metadata
3332
run-id: ${{ github.event.workflow_run.id }}
3433
github-token: ${{ secrets.GITHUB_TOKEN }}
3534

@@ -52,22 +51,18 @@ jobs:
5251
npx surge --project ./tdesign-flutter-web --domain $DEPLOY_DOMAIN --token ${{ secrets.TDESIGN_SURGE_TOKEN }}
5352
echo "url=$DEPLOY_DOMAIN" >> $GITHUB_OUTPUT
5453
55-
- name: 组装 PR 评论正文
54+
- name: 组装 PR 预览评论正文
5655
env:
5756
PREVIEW_URL: ${{ steps.deploy.outputs.url }}
5857
run: |
59-
printf '%s\n' \
60-
"<a href=\"${PREVIEW_URL}\"><img height=\"96\" alt=\"完成\" src=\"https://user-images.githubusercontent.com/15634204/150816437-9f5bb788-cd67-4cbc-9897-b82d74e9aa65.png\" /></a>" \
61-
'' \
62-
"**预览地址**: [${{ PREVIEW_URL}](${PREVIEW_URL})" \
63-
'' > pr-comment.md
64-
if [ -f doc-diff-comment.md ]; then
65-
echo "---" >> pr-comment.md
66-
echo "" >> pr-comment.md
67-
cat doc-diff-comment.md >> pr-comment.md
68-
fi
69-
echo "" >> pr-comment.md
70-
echo "<!-- AUTO_PREVIEW_HOOK -->" >> pr-comment.md
58+
{
59+
printf '%s\n' \
60+
"<a href=\"${PREVIEW_URL}\"><img height=\"96\" alt=\"完成\" src=\"https://user-images.githubusercontent.com/15634204/150816437-9f5bb788-cd67-4cbc-9897-b82d74e9aa65.png\" /></a>" \
61+
'' \
62+
"**预览地址**: [${PREVIEW_URL}](${PREVIEW_URL})" \
63+
'' \
64+
'<!-- AUTO_PREVIEW_HOOK -->'
65+
} > pr-comment.md
7166
7267
- name: 更新 PR 预览评论
7368
uses: TDesignOteam/workflows/actions/maintain-one-comment@main
@@ -78,11 +73,11 @@ jobs:
7873
body-include: "<!-- AUTO_PREVIEW_HOOK -->"
7974

8075
- name: 部署失败时标记 PR 评论
81-
if: ${{ failure() }}
76+
if: failure()
8277
uses: TDesignOteam/workflows/actions/maintain-one-comment@main
8378
with:
8479
token: ${{ secrets.GITHUB_TOKEN }}
85-
body: ${{ env.FAILURE_BODY }}
80+
body: ${{ env.DEPLOY_FAILURE_BODY }}
8681
number: ${{ steps.pr.outputs.number }}
8782
body-include: "<!-- AUTO_PREVIEW_HOOK -->"
8883

@@ -92,21 +87,16 @@ jobs:
9287
github.event.workflow_run.event == 'pull_request' &&
9388
github.event.workflow_run.conclusion == 'failure'
9489
steps:
95-
- name: 下载 PR 编号
96-
uses: actions/download-artifact@v4
97-
with:
98-
name: pr-number
99-
run-id: ${{ github.event.workflow_run.id }}
100-
github-token: ${{ secrets.GITHUB_TOKEN }}
101-
10290
- name: 解析 PR 编号
10391
id: pr
104-
run: echo "number=$(cat pr-number.txt)" >> $GITHUB_OUTPUT
92+
run: |
93+
PR_URL="${{ github.event.workflow_run.pull_requests[0].url }}"
94+
echo "number=${PR_URL##*/}" >> $GITHUB_OUTPUT
10595
10696
- name: 更新 PR 失败评论
10797
uses: TDesignOteam/workflows/actions/maintain-one-comment@main
10898
with:
10999
token: ${{ secrets.GITHUB_TOKEN }}
110-
body: ${{ env.FAILURE_BODY }}
100+
body: ${{ env.BUILD_FAILURE_BODY }}
111101
number: ${{ steps.pr.outputs.number }}
112102
body-include: "<!-- AUTO_PREVIEW_HOOK -->"

0 commit comments

Comments
 (0)