Skip to content

Commit 1eb45c4

Browse files
yanglbmeclaude
andcommitted
chore: replace deprecated maintain-one-comment with github-script
The actions-cool/maintain-one-comment action has been removed. Replace all 4 usages across cloudflare-preview.yml and surge-preview-deploy.yml with actions/github-script@9 calling issues.createComment directly. Also restore the single-comment behavior by listing PR comments, locating the existing one via the HTML marker, and updating it instead of creating duplicates on every re-run. Comment bodies are now built with array.join('\n') to avoid leading-space Markdown issues. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 51ffa3e commit 1eb45c4

2 files changed

Lines changed: 145 additions & 43 deletions

File tree

.github/workflows/cloudflare-preview.yml

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,42 @@ jobs:
6161
echo "Preview URL: $PREVIEW_URL"
6262
6363
- name: Comment PR with preview link
64-
uses: actions-cool/maintain-one-comment@v3
64+
uses: actions/github-script@v9
6565
with:
66-
token: ${{ secrets.GITHUB_TOKEN }}
67-
body: |
68-
🚀 Cloudflare Workers Preview has been successfully deployed!
66+
github-token: ${{ secrets.GITHUB_TOKEN }}
67+
script: |
68+
const prNumber = ${{ github.event.pull_request.number }};
69+
const deployUrl = '${{ steps.deployment-url.outputs.url }}';
70+
const commitSha = '${{ github.event.pull_request.head.sha }}';
71+
const body = [
72+
'🚀 Cloudflare Workers Preview has been successfully deployed!',
73+
'',
74+
`**Preview URL:** ${deployUrl}`,
75+
'',
76+
`<sub>Built with commit ${commitSha}</sub>`,
77+
'',
78+
'<!-- Cloudflare Preview Comment -->',
79+
].join('\n');
6980
70-
**Preview URL:** ${{ steps.deployment-url.outputs.url }}
71-
72-
<sub>Built with commit ${{ github.event.pull_request.head.sha }}</sub>
73-
74-
<!-- Cloudflare Preview Comment -->
75-
body-include: '<!-- Cloudflare Preview Comment -->'
76-
number: ${{ github.event.pull_request.number }}
81+
// Upsert: find existing comment and update, or create new
82+
const { data: comments } = await github.rest.issues.listComments({
83+
owner: context.repo.owner,
84+
repo: context.repo.repo,
85+
issue_number: prNumber,
86+
});
87+
const existing = comments.find(c => c.body.includes('<!-- Cloudflare Preview Comment -->'));
88+
if (existing) {
89+
await github.rest.issues.updateComment({
90+
owner: context.repo.owner,
91+
repo: context.repo.repo,
92+
comment_id: existing.id,
93+
body,
94+
});
95+
} else {
96+
await github.rest.issues.createComment({
97+
owner: context.repo.owner,
98+
repo: context.repo.repo,
99+
issue_number: prNumber,
100+
body,
101+
});
102+
}

.github/workflows/surge-preview-deploy.yml

Lines changed: 108 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)