-
Notifications
You must be signed in to change notification settings - Fork 310
82 lines (72 loc) · 2.9 KB
/
preview-publish.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
name: PREVIEW_PUBLISH
on:
workflow_run:
workflows: ["MAIN_PULL_REQUEST"]
types:
- completed
jobs:
preview-success:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
- name: download _site artifact
uses: dawidd6/action-download-artifact@v2
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
run_id: ${{ github.event.workflow_run.id }}
name: _site
- shell: bash
run: |
if [ -f "_site.zip" ];then
unzip _site.zip
else
echo "文件不存在" && exit 1
fi
- run: ls
- name: save PR id
id: pr
run: echo "::set-output name=id::$(<_site/pr-id.txt)"
- name: Upload surge service and generate preview URL
id: deploy
run: |
repository=${{github.repository}}
project_name=${repository#*/}
export DEPLOY_DOMAIN=https://preview-pr${{ steps.pr.outputs.id }}-$project_name.surge.sh
npx surge --project ./_site --domain $DEPLOY_DOMAIN --token ${{ secrets.TDESIGN_SURGE_TOKEN }}
echo the preview URL is $DEPLOY_DOMAIN
echo "::set-output name=url::$DEPLOY_DOMAIN"
- name: update status comment
uses: actions-cool/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
tdesign-vue preview 地址:(如果你有 DOM 变动请自行在对应技术栈仓库中发起 PR)
<a href="${{steps.deploy.outputs.url}}"><img height="96" alt="完成" src="https://user-images.githubusercontent.com/15634204/150816437-9f5bb788-cd67-4cbc-9897-b82d74e9aa65.png" /></a>
<!-- [工作流地址](${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}) -->
<!-- AUTO_PREVIEW_HOOK -->
number: ${{ steps.pr.outputs.id }}
body-include: "<!-- AUTO_PREVIEW_HOOK -->"
- run: |
rm -rf _site/
- name: The job failed
if: ${{ failure() }}
uses: actions-cool/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
[<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}})
<!-- AUTO_PREVIEW_HOOK -->
number: ${{ steps.pr.outputs.id }}
body-include: "<!-- AUTO_PREVIEW_HOOK -->"
preview-failed:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'failure'
steps:
- name: The job failed
run: |
id=${{ github.event.workflow_run.id }}
echo 工作流 $id 失败了