Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
f-hollow committed Dec 9, 2024
1 parent e629288 commit 00fe8f7
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions .github/workflows/pr-deploy-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,51 @@ jobs:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

# - name: Post Preview Link to PR
# uses: actions/github-script@v7
# with:
# github-token: ${{secrets.GITHUB_TOKEN}}
# script: |
# github.rest.issues.createComment({
# issue_number: context.issue.number,
# owner: context.repo.owner,
# repo: context.repo.repo,
# body: `πŸŽ‰ A preview of this PR is available at: ${{ env.HUGO_BASEURL }} `
# })

- name: Post Preview Link to PR
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
const commentIdentifier = "πŸŽ‰ A preview of this PR is available at:"; // Unique identifier for the preview comment
// Fetch existing comments
const { data: comments } = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `πŸŽ‰ A preview of this PR is available at: ${{ env.HUGO_BASEURL }} `
})
});
invalidate-cache:
needs: build-and-deploy-preview
runs-on: ubuntu-latest
steps:
let previewComment = comments.find(comment => comment.body.includes(commentIdentifier));
if (previewComment) {
// Update the existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: previewComment.id,
body: `πŸŽ‰ A preview of this PR is available at: ${process.env.HUGO_BASEURL}`,
});
} else {
// Post a new comment if none exists
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `πŸŽ‰ A preview of this PR is available at: ${process.env.HUGO_BASEURL}`,
});
}
- name: Invalidate CloudFront cache for PR
uses: chetan/invalidate-cloudfront-action@v2
Expand Down

0 comments on commit 00fe8f7

Please sign in to comment.