From 2a35205c8e56620ba1e1ecd32afcb773f75690c5 Mon Sep 17 00:00:00 2001 From: Yoren Chang Date: Thu, 18 Sep 2025 21:31:48 +0900 Subject: [PATCH] Update GitHub Actions workflows to replace pr-preview-action with github-pages-deploy-action, enhance PR preview deployment and cleanup processes, and add sticky comments with timestamps. --- .github/workflows/pr-deploy-preview.yml | 27 +++++++++++++++----- .github/workflows/pr-preview-cleanup.yml | 32 ++++++++++++++++++++---- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/.github/workflows/pr-deploy-preview.yml b/.github/workflows/pr-deploy-preview.yml index 50827d694..d1a1b73b0 100644 --- a/.github/workflows/pr-deploy-preview.yml +++ b/.github/workflows/pr-deploy-preview.yml @@ -59,10 +59,25 @@ jobs: run: find ./site -maxdepth 4 -type f | head -100 - name: Deploy PR Preview - uses: rossjrw/pr-preview-action@v1 + uses: JamesIves/github-pages-deploy-action@v4 with: - source-dir: ./site - preview-branch: gh-pages - umbrella-dir: pr-preview - pages-base-url: wpaccessibility.org - action: deploy \ No newline at end of file + branch: gh-pages + folder: ./site + target-folder: pr-preview/pr-${{ steps.pr.outputs.pr_number }} + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Get timestamp (UTC) + id: ts + run: echo "utc=$(date -u '+%Y-%m-%d %H:%M UTC')" >> "$GITHUB_OUTPUT" + + - name: Post preview link as sticky PR comment + uses: marocchino/sticky-pull-request-comment@v2 + with: + number: ${{ steps.pr.outputs.pr_number }} + header: pr-preview + message: | + [PR Preview](https://wpaccessibility.org/pr-preview/pr-${{ steps.pr.outputs.pr_number }}/) + :---: + Preview deployed for PR #${{ steps.pr.outputs.pr_number }}. + ${{ steps.ts.outputs.utc }} + \ No newline at end of file diff --git a/.github/workflows/pr-preview-cleanup.yml b/.github/workflows/pr-preview-cleanup.yml index 69cf76686..ff2d55a8f 100644 --- a/.github/workflows/pr-preview-cleanup.yml +++ b/.github/workflows/pr-preview-cleanup.yml @@ -6,6 +6,7 @@ on: permissions: contents: write + pull-requests: write concurrency: group: pr-cleanup-${{ github.event.pull_request.number }} @@ -18,9 +19,30 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Cleanup PR Preview for PR #${{ github.event.pull_request.number }} - uses: rossjrw/pr-preview-action@v1 + - name: Create empty deploy folder + run: mkdir -p empty + + - name: Remove PR Preview folder using GitHub Pages Deploy Action + uses: JamesIves/github-pages-deploy-action@v4 + with: + branch: gh-pages + folder: ./empty + target-folder: pr-preview/pr-${{ github.event.pull_request.number }} + token: ${{ secrets.GITHUB_TOKEN }} + clean: true + + - name: Get timestamp (UTC) + id: ts + run: echo "utc=$(date -u '+%Y-%m-%d %H:%M UTC')" >> "$GITHUB_OUTPUT" + + - name: Post removal sticky PR comment + uses: marocchino/sticky-pull-request-comment@v2 with: - preview-branch: gh-pages - umbrella-dir: pr-preview - action: remove \ No newline at end of file + number: ${{ github.event.pull_request.number }} + header: pr-preview + message: | + [PR Preview Action](https://github.com/rossjrw/pr-preview-action) v1 + :---: + Preview removed because the pull request was closed. + ${{ steps.ts.outputs.utc }} + \ No newline at end of file