From b4ddbc7dc9322c4074ed9c45e5eb62beae50ab39 Mon Sep 17 00:00:00 2001 From: Raunak Madan Date: Tue, 14 Apr 2026 02:50:31 +0530 Subject: [PATCH 1/3] Prune old PR previews Signed-off-by: Raunak Madan --- .github/workflows/build-and-preview-docs.yml | 41 ++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/.github/workflows/build-and-preview-docs.yml b/.github/workflows/build-and-preview-docs.yml index a809779f2aaa9..9fd40febcc713 100644 --- a/.github/workflows/build-and-preview-docs.yml +++ b/.github/workflows/build-and-preview-docs.yml @@ -93,6 +93,47 @@ jobs: action: auto comment: false + - name: Checkout gh-pages for preview retention + if: github.event.action != 'closed' + uses: actions/checkout@v6 + with: + ref: gh-pages + fetch-depth: 0 + path: gh-pages-maintenance + + - name: Prune old PR previews + if: github.event.action != 'closed' + run: | + cd gh-pages-maintenance + mkdir -p pr-preview + + mapfile -t previews < <( + while IFS= read -r preview; do + timestamp="$(git log -1 --format=%ct -- "pr-preview/$preview" 2>/dev/null || echo 0)" + printf '%s %s\n' "$timestamp" "$preview" + done < <(find pr-preview -mindepth 1 -maxdepth 1 -type d -name 'pr-*' -printf '%f\n') \ + | sort -nr \ + | awk '{print $2}' + ) + + if (( ${#previews[@]} <= 6 )); then + exit 0 + fi + + for preview in "${previews[@]:6}"; do + rm -rf "pr-preview/$preview" + done + + if git diff --quiet -- pr-preview; then + exit 0 + fi + + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add pr-preview + git commit -m "Prune old PR previews" + git push + - name: Comment PR with Preview URL if: github.event.action != 'closed' uses: marocchino/sticky-pull-request-comment@v2 From 2fad432f945ac76897d696f78774785632ae742f Mon Sep 17 00:00:00 2001 From: Raunak Madan <143412156+CodexRaunak@users.noreply.github.com> Date: Tue, 14 Apr 2026 02:53:44 +0530 Subject: [PATCH 2/3] Update hugo.toml Signed-off-by: Raunak Madan <143412156+CodexRaunak@users.noreply.github.com> --- docs/hugo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/hugo.toml b/docs/hugo.toml index 3ff3f9916f008..75919639a94d5 100644 --- a/docs/hugo.toml +++ b/docs/hugo.toml @@ -55,7 +55,7 @@ pygmentsStyle = "tango" [permalinks] blog = "/:section/:year/:month/:day/:slug/" -# Image processing configuration. + [imaging] resampleFilter = "CatmullRom" quality = 75 From 7e818958c0fabe3fff79f5899d1b4de6bace322d Mon Sep 17 00:00:00 2001 From: Raunak Madan Date: Tue, 14 Apr 2026 21:49:10 +0530 Subject: [PATCH 3/3] Comment on pruned PR previews Signed-off-by: Raunak Madan --- .github/workflows/build-and-preview-docs.yml | 66 +++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-and-preview-docs.yml b/.github/workflows/build-and-preview-docs.yml index 79e85098663c7..9ff1561efd865 100644 --- a/.github/workflows/build-and-preview-docs.yml +++ b/.github/workflows/build-and-preview-docs.yml @@ -22,12 +22,16 @@ defaults: run: shell: bash +env: + PREVIEW_RETENTION_LIMIT: 6 + jobs: build-and-deploy-preview: runs-on: ubuntu-24.04 + outputs: + removed_prs_json: ${{ steps.prune-previews.outputs.removed_prs_json }} env: HUGO_VERSION: 0.157.0 - PREVIEW_RETENTION_LIMIT: 6 steps: - name: Checkout PR code @@ -103,10 +107,12 @@ jobs: path: gh-pages-maintenance - name: Prune old PR previews + id: prune-previews if: github.event.action != 'closed' run: | cd gh-pages-maintenance mkdir -p pr-preview + removed_prs=() mapfile -t previews < <( while IFS= read -r preview; do @@ -118,14 +124,18 @@ jobs: ) if (( ${#previews[@]} <= PREVIEW_RETENTION_LIMIT )); then + echo "removed_prs_json=[]" >> "$GITHUB_OUTPUT" exit 0 fi for preview in "${previews[@]:PREVIEW_RETENTION_LIMIT}"; do rm -rf "pr-preview/$preview" + removed_prs+=("${preview#pr-}") done if git diff --quiet -- pr-preview; then + echo "removed_prs=" >> "$GITHUB_OUTPUT" + echo "removed_prs_json=[]" >> "$GITHUB_OUTPUT" exit 0 fi @@ -135,6 +145,9 @@ jobs: git commit -m "Prune old PR previews" git push + echo "removed_prs=$(IFS=,; echo "${removed_prs[*]}")" >> "$GITHUB_OUTPUT" + echo "removed_prs_json=$(printf '%s\n' "${removed_prs[@]}" | jq -R . | jq -sc .)" >> "$GITHUB_OUTPUT" + - name: Comment PR with Preview URL if: github.event.action != 'closed' uses: marocchino/sticky-pull-request-comment@v2 @@ -146,6 +159,57 @@ jobs: 🌐 **Preview URL**: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.pull_request.number }}/ _This preview will be updated automatically when you push new commits to this PR._ + + - name: Comment on pruned previews + if: github.event.action != 'closed' && steps.prune-previews.outputs.removed_prs_json != '[]' + uses: actions/github-script@v7 + env: + REMOVED_PRS_JSON: ${{ steps.prune-previews.outputs.removed_prs_json }} + PREVIEW_RETENTION_LIMIT: ${{ env.PREVIEW_RETENTION_LIMIT }} + with: + script: | + const removedPrs = JSON.parse(process.env.REMOVED_PRS_JSON); + const retentionLimit = process.env.PREVIEW_RETENTION_LIMIT; + const header = "pr-preview"; + const marker = ``; + + for (const prNumber of removedPrs) { + const body = + `Preview deployment for PR #${prNumber} removed.\n\n` + + `This PR preview was automatically pruned because we keep only the ${retentionLimit} most recently updated previews on GitHub Pages to stay within deployment size limits.\n\n` + + `If needed, push a new commit to this PR to generate a fresh preview.\n` + + `${marker}`; + + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: Number(prNumber), + per_page: 100, + }); + + const existingComment = [...comments].reverse().find((comment) => + comment.user?.login === "github-actions[bot]" && + comment.body?.includes(marker) + ); + + if (existingComment) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: existingComment.id, + body, + }); + continue; + } + + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: Number(prNumber), + body, + }); + } + - name: Cleanup PR preview on close if: github.event.action == 'closed' uses: rossjrw/pr-preview-action@v1.6.3