From a54d512215165d32c064baf4d006eec073d336ce Mon Sep 17 00:00:00 2001 From: John Mertic Date: Mon, 1 Dec 2025 11:18:45 -0500 Subject: [PATCH 1/3] Enhance Jekyll PR preview workflow with cleanup Updated GitHub Actions workflow for Jekyll PR previews. Added cleanup job for closed PRs and improved deployment steps. Signed-off-by: John Mertic --- .github/workflows/preview.yml | 71 ++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 8f2f686fb..ce4b96747 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -2,18 +2,16 @@ name: Jekyll PR Previews on: pull_request: + types: [opened, synchronize, reopened, closed] permissions: - contents: read - pages: write - id-token: write + contents: write # Required to push to preview branch pull-requests: write jobs: - build: + build-preview: + if: github.event.action != 'closed' runs-on: ubuntu-latest - outputs: - pr_path: ${{ steps.setpath.outputs.pr_path }} steps: - name: Checkout @@ -22,45 +20,48 @@ jobs: - name: Setup Ruby uses: ruby/setup-ruby@8aeb6ff8030dd539317f8e1769a044873b56ea71 # v1.268.0 with: - ruby-version: "3.2" + ruby-version: 3.2 bundler-cache: true - # Determine output folder: main → root, PR → /pr-/ - - name: Determine output path - id: setpath - run: | - echo "pr_path=pr-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT - - # Build Jekyll - name: Build Jekyll run: | - DEST="./_site/${{ steps.setpath.outputs.pr_path }}" - mkdir -p "$DEST" - bundle exec jekyll build --destination "$DEST" --trace --baseurl "/pr-${{ github.event.pull_request.number }}/" + bundle exec jekyll build --destination _site - # Upload the artifact for deployment - - name: Upload Pages Artifact - uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0 + # Deploy ONLY the preview to a separate branch + - name: Deploy Preview to pr-previews branch + uses: JamesIves/github-pages-deploy-action@v4 with: - path: _site - - deploy: - runs-on: ubuntu-latest - needs: build + folder: _site + branch: pr-previews # Completely isolated from gh-pages + target-folder: pr-${{ github.event.number }} + clean: false # Do NOT wipe other previews - # Deploy for both PRs and main - steps: - - name: Deploy to GitHub Pages - id: deploy - uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5 - - # Comment PR preview URL - - name: Comment PR Preview URL + # Comment preview link onto the PR + - name: Comment Preview Link uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 with: issue-number: ${{ github.event.pull_request.number }} body: | - 🔍 **Unique Jekyll PR Preview Ready** + 🚀 **PR Preview Ready** + Your preview is available at: - Preview URL: **https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-${{ github.event.pull_request.number }}/** + + cleanup: + if: github.event.action == 'closed' + runs-on: ubuntu-latest + + steps: + - name: Checkout preview branch + uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + with: + ref: pr-previews + + - name: Remove PR preview folder + run: | + rm -rf pr-${{ github.event.pull_request.number }} + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add -A + git commit -m "Remove preview for PR #${{ github.event.pull_request.number }}" || echo "Nothing to delete" + git push From b46fb090084a87c52bfc7b25a4f106d8a6475ef2 Mon Sep 17 00:00:00 2001 From: John Mertic Date: Mon, 1 Dec 2025 11:23:37 -0500 Subject: [PATCH 2/3] Update Jekyll build command for preview deployment Signed-off-by: John Mertic --- .github/workflows/preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index ce4b96747..0ce4b9548 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -25,7 +25,7 @@ jobs: - name: Build Jekyll run: | - bundle exec jekyll build --destination _site + bundle exec jekyll build --destination _site --baseurl "/pr-${{ github.event.number }}" # Deploy ONLY the preview to a separate branch - name: Deploy Preview to pr-previews branch From d034a4ed4945d2610b60479882286ae0bced2568 Mon Sep 17 00:00:00 2001 From: John Mertic Date: Mon, 1 Dec 2025 11:29:11 -0500 Subject: [PATCH 3/3] Update preview workflow to remove CNAME and change branch Removed CNAME file before building Jekyll and changed deployment branch from 'pr-previews' to 'main'. Signed-off-by: John Mertic --- .github/workflows/preview.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 0ce4b9548..cbc76e459 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -22,6 +22,8 @@ jobs: with: ruby-version: 3.2 bundler-cache: true + - name: Remove CNAME if present + run: rm -f CNAME - name: Build Jekyll run: | @@ -32,7 +34,7 @@ jobs: uses: JamesIves/github-pages-deploy-action@v4 with: folder: _site - branch: pr-previews # Completely isolated from gh-pages + branch: main target-folder: pr-${{ github.event.number }} clean: false # Do NOT wipe other previews