Skip to content
Open
Show file tree
Hide file tree
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
76 changes: 39 additions & 37 deletions .github/workflows/build-and-deploy-site.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,51 @@
name: Build and Deploy Site

on:
push:
branches: [master]
paths-ignore:
- .github/*

workflow_dispatch:
workflow_call:


permissions:
contents: write

concurrency:
group: "pages-deployment"
cancel-in-progress: true

defaults:
run:
shell: bash

jobs:
build-and-deploy:
runs-on: ubuntu-latest
deploy:
runs-on: ubuntu-24.04
steps:
- name: Checkout 🛎️
uses: actions/checkout@master
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 1

# - name: Cache Gatsby .cache and public folders
# uses: actions/cache@v5
# id: gatsby-cache
# with:
# path: |
# public
# .cache
# key: ${{ runner.os }}-gatsby-${{ hashFiles('**/package-lock.json') }}
# restore-keys: |
# ${{ runner.os }}-gatsby-

- name: Install 🔧
run: make setup

- name: Build 🏗️
# Always run the full production build explicitly.
# Do NOT use `make clean` here — that target is a developer convenience
# command whose recipe has changed multiple times, causing blog posts and
# other collections to be silently excluded from the deployed site when
# it ran a lite/dev build instead of the full production build.
# `npm run build` is the canonical, stable production build command:
# cross-env BUILD_FULL_SITE=true gatsby build
run: npm run build

- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4
fetch-depth: 0

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Install dependencies
run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"

- name: Build site
run: |
npm run build
touch public/.nojekyll

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
branch: site # The branch the action should deploy to.
folder: public # The folder the action should deploy.
clean: true
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
publish_branch: gh-pages
keep_files: true
126 changes: 92 additions & 34 deletions .github/workflows/build-and-preview-site.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,103 @@
name: Build and Preview Site

on:
pull_request:
pull_request_target:
branches: [master]
types: [opened, synchronize, reopened]
types: [opened, synchronize, reopened, closed]

permissions:
contents: write
pull-requests: write

concurrency:
group: "preview-${{ github.event.pull_request.number || github.run_id }}"
cancel-in-progress: true

jobs:
site-preview:
runs-on: ubuntu-latest
build-and-deploy-preview:
runs-on: ubuntu-24.04
steps:
- name: Checkout 🛎️
uses: actions/checkout@master
- name: Checkout PR
if: github.event.action != 'closed'
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0

- name: Checkout for cleanup
if: github.event.action == 'closed'
uses: actions/checkout@v6
with:
ref: gh-pages
fetch-depth: 0

- name: Setup Node
if: github.event.action != 'closed'
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Install dependencies
if: github.event.action != 'closed'
run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"

- name: Resolve preview URLs
if: github.event.action != 'closed'
id: preview-vars
env:
PREVIEW_SITE_URL: ${{ vars.PREVIEW_SITE_URL }}
run: |
repo_name="${GITHUB_REPOSITORY#*/}"
base_url="${PREVIEW_SITE_URL:-https://${GITHUB_REPOSITORY_OWNER}.github.io/${repo_name}}"
base_url="${base_url%/}"
path_prefix="/pr-preview/pr-${{ github.event.pull_request.number }}"

echo "base_url=${base_url}" >> "$GITHUB_OUTPUT"
echo "path_prefix=${path_prefix}" >> "$GITHUB_OUTPUT"

- name: Build PR preview
if: github.event.action != 'closed'
env:
GATSBY_PREVIEW: "true"
GATSBY_SITE_URL: ${{ steps.preview-vars.outputs.base_url }}
PATH_PREFIX: ${{ steps.preview-vars.outputs.path_prefix }}
run: |
npm run build:preview

# Block all crawlers from indexing PR previews.
cat > public/robots.txt <<'EOF'
User-agent: *
Disallow: /
EOF
touch public/.nojekyll

- name: Deploy PR preview
if: github.event.action != 'closed'
id: deploy-preview
uses: rossjrw/pr-preview-action@v1.6.3
with:
persist-credentials: false
fetch-depth: 1

- name: Install 🔧
run: make setup

- name: Build 🏗️
# Always run the full production build explicitly.
# Do NOT use `make clean` here — that target is a developer convenience
# command whose recipe has changed multiple times, causing blog posts and
# other collections to be silently excluded from the deployed site when
# it ran a lite/dev build instead of the full production build.
# `npm run build` is the canonical, stable production build command:
# cross-env BUILD_FULL_SITE=true gatsby build
run: npm run build

- name: Broken Link Check 🔗
uses: technote-space/broken-link-checker-action@v2
source-dir: ./public
preview-branch: gh-pages
umbrella-dir: pr-preview
action: auto
comment: false

- name: Comment PR with Preview URL
if: github.event.action != 'closed'
uses: marocchino/sticky-pull-request-comment@v2
with:
target: ./public/**/*.html
header: pr-preview
message: |
🚀 **Preview deployment for PR #${{ github.event.pull_request.number }}**

🌐 **Preview URL**: ${{ steps.preview-vars.outputs.base_url }}/pr-preview/pr-${{ github.event.pull_request.number }}/

- name: Zip Site
run: bash ./script.sh
_This preview will be updated automatically when you push new commits to this PR._

- name: Upload files
uses: actions/upload-artifact@v6
- name: Cleanup PR preview on close
if: github.event.action == 'closed'
uses: rossjrw/pr-preview-action@v1.6.3
with:
name: public-dir
path: ./public-dir.zip
retention-days: 1
- name: Trigger Inner workflow
run: echo "triggering inner workflow"
preview-branch: gh-pages
umbrella-dir: pr-preview
action: remove
48 changes: 0 additions & 48 deletions .github/workflows/preview-site.yml

This file was deleted.

Loading