diff --git a/.github/workflows/pr-build-preview.yml b/.github/workflows/pr-build-preview.yml index 9c6342277..22087f9dc 100644 --- a/.github/workflows/pr-build-preview.yml +++ b/.github/workflows/pr-build-preview.yml @@ -27,6 +27,21 @@ jobs: with: submodules: recursive + - name: Extract PR URL + id: get-pr-url + run: | + PR_URL=$(jq -r '.pull_request.html_url' "$GITHUB_EVENT_PATH") + echo "PR_URL=$PR_URL" >> $GITHUB_ENV + PR_LINK_TEXT=${PR_URL#https://} + echo "PR_LINK_TEXT=$PR_LINK_TEXT" >> $GITHUB_ENV + + - name: Append preview snippet to header file + run: | + PREVIEW_HTML="
+ This site is a preview for ${{ env.PR_LINK_TEXT }} +
" + echo "$PREVIEW_HTML" >> layouts/partials/header/basic.html + - name: Build website with Hugo env: # For maximum backward compatibility with Hugo modules diff --git a/.github/workflows/prw-deploy-preview.yml b/.github/workflows/prw-deploy-preview.yml index 34bd9a987..e3a9a26f3 100644 --- a/.github/workflows/prw-deploy-preview.yml +++ b/.github/workflows/prw-deploy-preview.yml @@ -66,12 +66,40 @@ 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) { + // Delete the existing comment + await github.rest.issues.deleteComment({ + comment_id: existingComment.id, + owner: context.repo.owner, + repo: context.repo.repo + }); + } + + // 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 diff --git a/content/_index.md b/content/_index.md index 23806a9a0..e4913fee2 100755 --- a/content/_index.md +++ b/content/_index.md @@ -15,7 +15,7 @@ cascade: {{< article link="/blog/2024/10/what-is-the-esp-registry/" >}}