Skip to content

Commit

Permalink
ci[pr-preview]: keep only one comment with PR preview link
Browse files Browse the repository at this point in the history
  • Loading branch information
f-hollow committed Dec 25, 2024
1 parent c298a4a commit 1f74bce
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions .github/workflows/prw-deploy-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,41 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: ${{ env.PR_NUMBER }},
owner: context.repo.owner,
repo: context.repo.repo,
body: `🎉 A preview for this PR is available at: ${{ env.HUGO_BASEURL }}pr${{ env.PR_NUMBER }}/`
});
try {
const { data: comments } = await github.rest.issues.listComments({
issue_number: ${{ env.PR_NUMBER }},
owner: context.repo.owner,
repo: context.repo.repo
});
// Define the comment body
const commentBody = `🎉 A preview for this PR is available at: ${{ env.HUGO_BASEURL }}pr${{ env.PR_NUMBER }}/`;
// Look for an existing comment containing the specific text
const existingComment = comments.find(comment =>
comment.body.includes("🎉 A preview for this PR is available at:")
);
if (existingComment) {
// Update the existing comment
await github.rest.issues.updateComment({
comment_id: existingComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
} else {
// Create a new comment
await github.rest.issues.createComment({
issue_number: ${{ env.PR_NUMBER }},
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
}
} catch (error) {
core.setFailed(`Failed to manage PR comment: ${error.message}`);
}
- name: Invalidate CloudFront cache for PR
uses: chetan/invalidate-cloudfront-action@v2
Expand Down

0 comments on commit 1f74bce

Please sign in to comment.