@@ -13,13 +13,23 @@ jobs:
1313 deploy-site :
1414 permissions :
1515 actions : read # for dawidd6/action-download-artifact to query and download artifacts
16- issues : write # for actions-cool/maintain-one-comment to modify or create issue comments
17- pull-requests : write # for actions-cool/maintain-one-comment to modify or create PR comments
16+ issues : write
17+ pull-requests : write
1818 name : deploy preview
1919 runs-on : ubuntu-latest
2020 if : ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}
2121
2222 steps :
23+ - name : Resolve PR number
24+ id : pr
25+ run : |
26+ pr_number="${{ github.event.workflow_run.pull_requests[0].number }}"
27+ if [ -z "$pr_number" ]; then
28+ echo "No pull request associated with workflow run"
29+ exit 1
30+ fi
31+ echo "number=$pr_number" >> "$GITHUB_OUTPUT"
32+
2333 - name : Download site artifact
2434 uses : dawidd6/action-download-artifact@v2
2535 with :
@@ -30,49 +40,82 @@ jobs:
3040 - name : Upload surge service
3141 id : deploy
3242 run : |
33- export DEPLOY_DOMAIN=https://preview-${{ github.event .number }}-oceanbase-design.surge.sh
43+ export DEPLOY_DOMAIN=https://preview-${{ steps.pr.outputs .number }}-oceanbase-design.surge.sh
3444 npx surge --project ./ --domain $DEPLOY_DOMAIN --token ${{ secrets.SURGE_TOKEN }}
3545
46+ - name : Find preview comment
47+ if : success()
48+ uses : peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3
49+ id : find-comment
50+ with :
51+ issue-number : ${{ steps.pr.outputs.number }}
52+ body-includes : ' <!-- AUTO_PREVIEW_HOOK -->'
53+
3654 - name : Update status comment
37- uses : actions-cool/maintain-one-comment@v3
55+ if : success()
56+ uses : peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
3857 with :
39- token : ${{ secrets.GITHUB_TOKEN }}
58+ comment-id : ${{ steps.find-comment.outputs.comment-id }}
59+ issue-number : ${{ steps.pr.outputs.number }}
60+ edit-mode : replace
4061 body : |
41- <a href="https://preview-${{ github.event .number }}-oceanbase-design.surge.sh" target="_blank">
62+ <a href="https://preview-${{ steps.pr.outputs .number }}-oceanbase-design.surge.sh" target="_blank">
4263 <img width="360" src="https://mdn.alipayobjects.com/huamei_n8rchn/afts/img/A*biIGSYhvfOQAAAAAAAAAAAAADvSFAQ/original">
4364 </a>
4465 <!-- AUTO_PREVIEW_HOOK -->
45- body-include : ' <!-- AUTO_PREVIEW_HOOK -->'
46- number : ${{ github.event.number }}
4766
48- - name : The job has failed
49- if : ${{ failure() }}
50- uses : actions-cool/maintain-one-comment@v3
67+ - name : Find preview comment (deploy failed)
68+ if : failure()
69+ uses : peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3
70+ id : find-comment-failed
71+ with :
72+ issue-number : ${{ steps.pr.outputs.number }}
73+ body-includes : ' <!-- AUTO_PREVIEW_HOOK -->'
74+
75+ - name : Update status comment (deploy failed)
76+ if : failure()
77+ uses : peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
5178 with :
52- token : ${{ secrets.GITHUB_TOKEN }}
79+ comment-id : ${{ steps.find-comment-failed.outputs.comment-id }}
80+ issue-number : ${{ steps.pr.outputs.number }}
81+ edit-mode : replace
5382 body : |
5483 😭 Preview Deploy failed.
5584 <img width="300" src="https://user-images.githubusercontent.com/507615/90250824-4e066700-de6f-11ea-8230-600ecc3d6a6b.png">
5685 <!-- AUTO_PREVIEW_HOOK -->
57- body-include : ' <!-- AUTO_PREVIEW_HOOK -->'
58- number : ${{ github.event.number }}
5986
6087 build-site-failed :
6188 permissions :
62- actions : read # for dawidd6/action-download-artifact to query and download artifacts
63- issues : write # for actions-cool/maintain-one-comment to modify or create issue comments
64- pull-requests : write # for actions-cool/maintain-one-comment to modify or create PR comments
89+ issues : write
90+ pull-requests : write
6591 name : build preview failed
6692 runs-on : ubuntu-latest
6793 if : ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'failure' }}
6894
6995 steps :
70- - name : The job has failed
71- uses : actions-cool/maintain-one-comment@v3
96+ - name : Resolve PR number
97+ id : pr
98+ run : |
99+ pr_number="${{ github.event.workflow_run.pull_requests[0].number }}"
100+ if [ -z "$pr_number" ]; then
101+ echo "No pull request associated with workflow run"
102+ exit 1
103+ fi
104+ echo "number=$pr_number" >> "$GITHUB_OUTPUT"
105+
106+ - name : Find preview comment
107+ uses : peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3
108+ id : find-comment
109+ with :
110+ issue-number : ${{ steps.pr.outputs.number }}
111+ body-includes : ' <!-- AUTO_PREVIEW_HOOK -->'
112+
113+ - name : Update status comment
114+ uses : peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
72115 with :
73- token : ${{ secrets.GITHUB_TOKEN }}
116+ comment-id : ${{ steps.find-comment.outputs.comment-id }}
117+ issue-number : ${{ steps.pr.outputs.number }}
118+ edit-mode : replace
74119 body : |
75120 <img width="534" src="https://user-images.githubusercontent.com/5378891/75333447-1e63a280-58c1-11ea-975d-235367fd1522.png">
76121 <!-- AUTO_PREVIEW_HOOK -->
77- body-include : ' <!-- AUTO_PREVIEW_HOOK -->'
78- number : ${{ github.event.number }}
0 commit comments