@@ -67,22 +67,51 @@ jobs:
6767 AWS_ACCESS_KEY_ID : ${{ secrets.AWS_ACCESS_KEY_ID }}
6868 AWS_SECRET_ACCESS_KEY : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
6969
70+ # - name: Post Preview Link to PR
71+ # uses: actions/github-script@v7
72+ # with:
73+ # github-token: ${{secrets.GITHUB_TOKEN}}
74+ # script: |
75+ # github.rest.issues.createComment({
76+ # issue_number: context.issue.number,
77+ # owner: context.repo.owner,
78+ # repo: context.repo.repo,
79+ # body: `🎉 A preview of this PR is available at: ${{ env.HUGO_BASEURL }} `
80+ # })
81+
7082 - name : Post Preview Link to PR
7183 uses : actions/github-script@v7
7284 with :
73- github-token : ${{secrets.GITHUB_TOKEN}}
85+ github-token : ${{ secrets.GITHUB_TOKEN }}
7486 script : |
75- github.rest.issues.createComment({
87+ const commentIdentifier = "🎉 A preview of this PR is available at:"; // Unique identifier for the preview comment
88+
89+ // Fetch existing comments
90+ const { data: comments } = await github.rest.issues.listComments({
7691 issue_number: context.issue.number,
7792 owner: context.repo.owner,
7893 repo: context.repo.repo,
79- body: `🎉 A preview of this PR is available at: ${{ env.HUGO_BASEURL }} `
80- })
94+ });
8195
82- invalidate-cache :
83- needs : build-and-deploy-preview
84- runs-on : ubuntu-latest
85- steps :
96+ let previewComment = comments.find(comment => comment.body.includes(commentIdentifier));
97+
98+ if (previewComment) {
99+ // Update the existing comment
100+ await github.rest.issues.updateComment({
101+ owner: context.repo.owner,
102+ repo: context.repo.repo,
103+ comment_id: previewComment.id,
104+ body: `🎉 A preview of this PR is available at: ${process.env.HUGO_BASEURL}`,
105+ });
106+ } else {
107+ // Post a new comment if none exists
108+ await github.rest.issues.createComment({
109+ issue_number: context.issue.number,
110+ owner: context.repo.owner,
111+ repo: context.repo.repo,
112+ body: `🎉 A preview of this PR is available at: ${process.env.HUGO_BASEURL}`,
113+ });
114+ }
86115
87116 - name : Invalidate CloudFront cache for PR
88117 uses : chetan/invalidate-cloudfront-action@v2
0 commit comments