Skip to content

Commit 5471f7e

Browse files
committed
update workflow
1 parent 74fd275 commit 5471f7e

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

.github/workflows/docs_preview_deploy_cf.yaml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,34 @@ jobs:
7777
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
7878
command: pages deploy downloaded-artifact/public --project-name toolbox-docs --branch pr-${{ steps.get_pr.outputs.pr_number }}
7979

80-
- name: Comment
80+
- name: Post Preview URL Comment
8181
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
8282
with:
8383
script: |
8484
const prNumber = parseInt('${{ steps.get_pr.outputs.pr_number }}', 10);
8585
const deployUrl = '${{ steps.cf_deploy.outputs.pages-deployment-alias-url }}';
86+
const marker = '<!-- cf-preview-comment-marker -->';
8687
87-
await github.rest.issues.createComment({
88+
// Fetch all comments on the PR
89+
const { data: comments } = await github.rest.issues.listComments({
90+
owner: context.repo.owner,
91+
repo: context.repo.repo,
8892
issue_number: prNumber,
93+
});
94+
95+
// Look for the invisible HTML marker
96+
const existingComment = comments.find(c => c.body.includes(marker));
97+
98+
// Exit early if we've already posted a comment for this PR to avoid duplicates
99+
if (existingComment) {
100+
console.log("Preview link already posted on this PR. Skipping.");
101+
return;
102+
}
103+
104+
// Create the comment since it's the first deployment for this PR
105+
await github.rest.issues.createComment({
89106
owner: context.repo.owner,
90107
repo: context.repo.repo,
91-
body: `🚀 **Cloudflare Preview Ready!**\n\n🔎 View Preview: ${deployUrl}\n\n*(Note: It may take a minute or two for Cloudflare to finish deploying the branch)*`
108+
issue_number: prNumber,
109+
body: `${marker}\n🚀 **Cloudflare Preview Ready!**\n\n🔎 View Preview: ${deployUrl}\n\n*(Note: Subsequent pushes to this PR will automatically update the preview at this same URL)*`
92110
});

0 commit comments

Comments
 (0)