@@ -43,33 +43,84 @@ jobs:
4343 npx surge --project ./ --domain $DEPLOY_DOMAIN --token ${{ secrets.SURGE_TOKEN }}
4444
4545 - name : Comment PR with preview link
46- uses : actions-cool/maintain-one-comment@v3
46+ uses : actions/github-script@v9
4747 with :
48- token : ${{ secrets.GITHUB_TOKEN }}
49- body : |
50- 🚀 Surge Preview has been successfully deployed!
51-
52- **Preview URL:** https://doocs-md-preview-pr-${{ steps.pr.outputs.id }}.surge.sh
53-
54- <sub>Built with commit ${{ github.event.workflow_run.head_sha }}</sub>
55-
56- <!-- Surge Preview Comment -->
57- body-include : ' <!-- Surge Preview Comment -->'
58- number : ${{ steps.pr.outputs.id }}
48+ github-token : ${{ secrets.GITHUB_TOKEN }}
49+ script : |
50+ const prNumber = ${{ steps.pr.outputs.id }};
51+ const deployUrl = 'https://doocs-md-preview-pr-${{ steps.pr.outputs.id }}.surge.sh';
52+ const commitSha = '${{ github.event.workflow_run.head_sha }}';
53+ const body = [
54+ '🚀 Surge Preview has been successfully deployed!',
55+ '',
56+ `**Preview URL:** ${deployUrl}`,
57+ '',
58+ `<sub>Built with commit ${commitSha}</sub>`,
59+ '',
60+ '<!-- Surge Preview Comment -->',
61+ ].join('\n');
62+
63+ // Upsert: find existing comment and update, or create new
64+ const { data: comments } = await github.rest.issues.listComments({
65+ owner: context.repo.owner,
66+ repo: context.repo.repo,
67+ issue_number: prNumber,
68+ });
69+ const existing = comments.find(c => c.body.includes('<!-- Surge Preview Comment -->'));
70+ if (existing) {
71+ await github.rest.issues.updateComment({
72+ owner: context.repo.owner,
73+ repo: context.repo.repo,
74+ comment_id: existing.id,
75+ body,
76+ });
77+ } else {
78+ await github.rest.issues.createComment({
79+ owner: context.repo.owner,
80+ repo: context.repo.repo,
81+ issue_number: prNumber,
82+ body,
83+ });
84+ }
5985
6086 - name : Deploy failed
6187 if : ${{ failure() }}
62- uses : actions-cool/maintain-one-comment@v3
88+ uses : actions/github-script@v9
6389 with :
64- token : ${{ secrets.GITHUB_TOKEN }}
65- body : |
66- 😭 Surge Preview deployment failed.
67-
68- Please check the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.
69-
70- <!-- Surge Preview Comment -->
71- body-include : ' <!-- Surge Preview Comment -->'
72- number : ${{ steps.pr.outputs.id }}
90+ github-token : ${{ secrets.GITHUB_TOKEN }}
91+ script : |
92+ const prNumber = ${{ steps.pr.outputs.id }};
93+ const workflowRunUrl = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}';
94+ const body = [
95+ '😭 Surge Preview deployment failed.',
96+ '',
97+ `Please check the [workflow run](${workflowRunUrl}) for details.`,
98+ '',
99+ '<!-- Surge Preview Comment -->',
100+ ].join('\n');
101+
102+ // Upsert: find existing comment and update, or create new
103+ const { data: comments } = await github.rest.issues.listComments({
104+ owner: context.repo.owner,
105+ repo: context.repo.repo,
106+ issue_number: prNumber,
107+ });
108+ const existing = comments.find(c => c.body.includes('<!-- Surge Preview Comment -->'));
109+ if (existing) {
110+ await github.rest.issues.updateComment({
111+ owner: context.repo.owner,
112+ repo: context.repo.repo,
113+ comment_id: existing.id,
114+ body,
115+ });
116+ } else {
117+ await github.rest.issues.createComment({
118+ owner: context.repo.owner,
119+ repo: context.repo.repo,
120+ issue_number: prNumber,
121+ body,
122+ });
123+ }
73124
74125 failed :
75126 runs-on : ubuntu-latest
@@ -93,14 +144,39 @@ jobs:
93144 echo "id=$pr_id" >> $GITHUB_OUTPUT
94145
95146 - name : Comment PR with build failure
96- uses : actions-cool/maintain-one-comment@v3
147+ uses : actions/github-script@v9
97148 with :
98- token : ${{ secrets.GITHUB_TOKEN }}
99- body : |
100- 😭 Surge Preview build failed.
101-
102- Please check the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}) for details.
103-
104- <!-- Surge Preview Comment -->
105- body-include : ' <!-- Surge Preview Comment -->'
106- number : ${{ steps.pr.outputs.id }}
149+ github-token : ${{ secrets.GITHUB_TOKEN }}
150+ script : |
151+ const prNumber = ${{ steps.pr.outputs.id }};
152+ const workflowRunUrl = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}';
153+ const body = [
154+ '😭 Surge Preview build failed.',
155+ '',
156+ `Please check the [workflow run](${workflowRunUrl}) for details.`,
157+ '',
158+ '<!-- Surge Preview Comment -->',
159+ ].join('\n');
160+
161+ // Upsert: find existing comment and update, or create new
162+ const { data: comments } = await github.rest.issues.listComments({
163+ owner: context.repo.owner,
164+ repo: context.repo.repo,
165+ issue_number: prNumber,
166+ });
167+ const existing = comments.find(c => c.body.includes('<!-- Surge Preview Comment -->'));
168+ if (existing) {
169+ await github.rest.issues.updateComment({
170+ owner: context.repo.owner,
171+ repo: context.repo.repo,
172+ comment_id: existing.id,
173+ body,
174+ });
175+ } else {
176+ await github.rest.issues.createComment({
177+ owner: context.repo.owner,
178+ repo: context.repo.repo,
179+ issue_number: prNumber,
180+ body,
181+ });
182+ }
0 commit comments