Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 68 additions & 32 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
@@ -1,66 +1,102 @@
name: Jekyll PR Previews
name: Jekyll PR Preview

on:
pull_request:
types: [opened, reopened, synchronize, closed]

permissions:
contents: read
pages: write
deployments: write
id-token: write
pull-requests: write
checks: write

env:
BUILD_DIR: _site

jobs:

# ----------------------------
# Build PR Preview
# ----------------------------
build:
if: github.event.action != 'closed'
runs-on: ubuntu-latest
outputs:
pr_path: ${{ steps.setpath.outputs.pr_path }}
page_url: ${{ steps.deploy.outputs.page_url }}

steps:
- name: Checkout
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0

# Cache gems for faster builds
- name: Cache Bundler
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: vendor/bundle
key: bundler-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: bundler-

- name: Setup Ruby
uses: ruby/setup-ruby@8aeb6ff8030dd539317f8e1769a044873b56ea71 # v1.268.0
- uses: ruby/setup-ruby@8aeb6ff8030dd539317f8e1769a044873b56ea71 # v1.268.0
with:
ruby-version: "3.2"
bundler-cache: true

# Determine output folder: main → root, PR → /pr-<number>/
- 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 $BUILD_DIR \
--baseurl "/"

# Upload the artifact for deployment
- name: Upload Pages Artifact
uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0
# Deploy preview to a unique PR environment
- name: Deploy PR Preview
id: deploy
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5
with:
path: _site
artifact_path: ${{ env.BUILD_DIR }}
environment: pr-${{ github.event.pull_request.number }}

deploy:
runs-on: ubuntu-latest
needs: build
# Add GitHub Check summary
- name: Create check summary
run: |
echo "### 🚀 Preview Ready" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Preview URL:**" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.deploy.outputs.page_url }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Automatically updates on new commits." >> $GITHUB_STEP_SUMMARY

# Deploy for both PRs and main
# ----------------------------
# PR comment (auto-updating single comment)
# ----------------------------
comment:
needs: build
if: github.event.action != 'closed'
runs-on: ubuntu-latest
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
- name: Create or update PR comment
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**
🚀 **Preview Ready**

Preview URL:
**https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-${{ github.event.pull_request.number }}/**
**${{ needs.build.outputs.page_url }}**

This link updates automatically whenever you push commits to this PR.

# ----------------------------
# Cleanup when PR closes
# ----------------------------
cleanup:
if: github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- name: Delete PR preview environment
run: |
gh api \
repos/${{ github.repository }}/environments/pr-${{ github.event.pull_request.number }} \
-X DELETE || echo "Environment already removed"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Loading