-
Notifications
You must be signed in to change notification settings - Fork 25
121 lines (107 loc) · 4.41 KB
/
Copy pathpreview-deploy.yml
File metadata and controls
121 lines (107 loc) · 4.41 KB
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
name: Preview Deploy
on:
workflow_run:
workflows: [Preview Build]
types:
- completed
permissions:
contents: read
jobs:
deploy-site:
permissions:
actions: read # for dawidd6/action-download-artifact to query and download artifacts
issues: write
pull-requests: write
name: deploy preview
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Resolve PR number
id: pr
run: |
pr_number="${{ github.event.workflow_run.pull_requests[0].number }}"
if [ -z "$pr_number" ]; then
echo "No pull request associated with workflow run"
exit 1
fi
echo "number=$pr_number" >> "$GITHUB_OUTPUT"
- 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
- name: Upload surge service
id: deploy
run: |
export DEPLOY_DOMAIN=https://preview-${{ steps.pr.outputs.number }}-oceanbase-design.surge.sh
npx surge --project ./ --domain $DEPLOY_DOMAIN --token ${{ secrets.SURGE_TOKEN }}
- name: Find preview comment
if: success()
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3
id: find-comment
with:
issue-number: ${{ steps.pr.outputs.number }}
body-includes: '<!-- AUTO_PREVIEW_HOOK -->'
- name: Update status comment
if: success()
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ steps.pr.outputs.number }}
edit-mode: replace
body: |
<a href="https://preview-${{ steps.pr.outputs.number }}-oceanbase-design.surge.sh" target="_blank">
<img width="360" src="https://mdn.alipayobjects.com/huamei_n8rchn/afts/img/A*biIGSYhvfOQAAAAAAAAAAAAADvSFAQ/original">
</a>
<!-- AUTO_PREVIEW_HOOK -->
- name: Find preview comment (deploy failed)
if: failure()
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3
id: find-comment-failed
with:
issue-number: ${{ steps.pr.outputs.number }}
body-includes: '<!-- AUTO_PREVIEW_HOOK -->'
- name: Update status comment (deploy failed)
if: failure()
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
with:
comment-id: ${{ steps.find-comment-failed.outputs.comment-id }}
issue-number: ${{ steps.pr.outputs.number }}
edit-mode: replace
body: |
😭 Preview Deploy failed.
<img width="300" src="https://user-images.githubusercontent.com/507615/90250824-4e066700-de6f-11ea-8230-600ecc3d6a6b.png">
<!-- AUTO_PREVIEW_HOOK -->
build-site-failed:
permissions:
issues: write
pull-requests: write
name: build preview failed
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'failure' }}
steps:
- name: Resolve PR number
id: pr
run: |
pr_number="${{ github.event.workflow_run.pull_requests[0].number }}"
if [ -z "$pr_number" ]; then
echo "No pull request associated with workflow run"
exit 1
fi
echo "number=$pr_number" >> "$GITHUB_OUTPUT"
- name: Find preview comment
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3
id: find-comment
with:
issue-number: ${{ steps.pr.outputs.number }}
body-includes: '<!-- AUTO_PREVIEW_HOOK -->'
- name: Update status comment
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ steps.pr.outputs.number }}
edit-mode: replace
body: |
<img width="534" src="https://user-images.githubusercontent.com/5378891/75333447-1e63a280-58c1-11ea-975d-235367fd1522.png">
<!-- AUTO_PREVIEW_HOOK -->