From 32b3d1880d2f3131b6962bb2583dcdb82ced6d52 Mon Sep 17 00:00:00 2001 From: "kirill.chalov" Date: Wed, 25 Dec 2024 19:44:46 +0800 Subject: [PATCH 1/3] ci[pr-preview]: keep only one comment with PR preview link --- .github/workflows/prw-deploy-preview.yml | 40 ++++++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) 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 From 6d88bde2ad0ab42a0689da1e14685190df7689c4 Mon Sep 17 00:00:00 2001 From: "kirill.chalov" Date: Thu, 26 Dec 2024 16:53:35 +0800 Subject: [PATCH 2/3] ci[pr-preview]: in header of preview site add link back to pr --- .github/workflows/pr-build-preview.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 From 1ab69e7310b7bb3a597417ce80f04cb2541f4a22 Mon Sep 17 00:00:00 2001 From: "kirill.chalov" Date: Thu, 26 Dec 2024 15:56:29 +0800 Subject: [PATCH 3/3] fix: improve button shortcodes --- content/_index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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/" >}}
-{{< button href="#button" target="_self" href=/blog/ >}} +{{< button href="blog/" target="_self" >}} More Articles {{< /button >}} @@ -26,7 +26,7 @@ Dive into our latest workshops and master the skills you need to maximize the po {{< article link="/workshops/esp-idf-with-esp32-c6/introduction/" >}}
-{{< button href="#button" target="_self" href=/workshops/ >}} +{{< button href="workshops/" target="_self" >}} More Workshops {{< /button >}} @@ -37,6 +37,6 @@ Here you can follow the current status of the new chip support in various Espres {{< article link="/pages/chip-support-status/esp32c61/" >}}
-{{< button href="#button" target="_self" href=/events/ >}} +{{< button href="events/" target="_self" >}} More Events {{< /button >}}