-
Notifications
You must be signed in to change notification settings - Fork 92
136 lines (117 loc) · 4.89 KB
/
deploy-preview.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
name: 部署 (预览环境) 后处理
on:
workflow_run:
workflows:
- 部署 (预览环境)
types:
- completed
env:
PR_NUM: 0
jobs:
on-success:
name: 推送到 Netlify
runs-on: ubuntu-latest
permissions:
pull-requests: write
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: 下载工作流信息
uses: dawidd6/action-download-artifact@v6
with:
workflow_conclusion: success
run_id: ${{ github.event.workflow_run.id }}
name: pr-num
path: pr-num
allow_forks: true
- name: 获取 PR 编号
id: pr-num
run: |
echo "PR_NUM=$(cat pr-num/pr_num)" >> $GITHUB_ENV
- name: 下载构建内容
uses: dawidd6/action-download-artifact@v6
with:
workflow_conclusion: success
run_id: ${{ github.event.workflow_run.id }}
name: build-result
allow_forks: true
- name: 解压构建文件
run: |
tar -xvf dist.tar .vitepress/dist
# ls -R -a
- name: 推送到 Netlify
id: netlify
uses: nwtgck/actions-netlify@v3.0
with:
publish-dir: ".vitepress/dist"
deploy-message: "Deploy from GitHub Actions"
production-deploy: false
alias: deploy-preview-wiki-${{ env.PR_NUM }}
enable-commit-comment: false
enable-pull-request-comment: false
enable-commit-status: false
enable-github-deployment: false
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
timeout-minutes: 1
- name: 查找评论 ID
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ env.PR_NUM }}
comment-author: "github-actions[bot]"
body-includes: <!-- auto message -->
- name: 创建或更新评论
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ env.PR_NUM }}
body: |
## ✅ 成功部署预览!
| 类型 | 链接 |
|:-----------:|:----------------------------------------------------------------------------------------------------:|
| 预览地址 | ${{ steps.netlify.outputs.deploy-url }} |
| 最新提交 | ${{ github.sha }} |
| 部署日志 | [${{ github.event.workflow_run.name }} #${{ github.event.workflow_run.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}) |
<!-- auto message -->
edit-mode: replace
on-failure:
name: 提示构建预览失败
runs-on: ubuntu-latest
permissions:
pull-requests: write
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- name: 下载构建内容 (工作流信息)
uses: dawidd6/action-download-artifact@v6
with:
workflow_conclusion: success
run_id: ${{ github.event.workflow_run.id }}
name: pr-num
path: pr-num
allow_forks: true
- name: 获取 PR 编号
id: pr-num
run: |
echo "PR_NUM=$(cat pr-num/pr_num)" >> $GITHUB_ENV
- name: 查找评论 ID
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ env.PR_NUM }}
comment-author: "github-actions[bot]"
body-includes: <!-- auto message -->
- name: 创建或更新评论:失败
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ env.PR_NUM }}
body: |
## ❌ 部署预览失败
| 类型 | 链接 |
|:-----------:|:----------------------------------------------------------------------------------------------------:|
| 预览地址 | 部署失败,请查看工作流运行日志。 |
| 最新提交 | ${{ github.sha }} |
| 部署日志 | [${{ github.event.workflow_run.name }} #${{ github.event.workflow_run.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}) |
<!-- auto message -->
edit-mode: replace