Build + Deploy to GitHub Pages #268
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build + Deploy to GitHub Pages | |
on: | |
push: | |
branches: | |
- www | |
workflow_call: | |
inputs: | |
ref: | |
type: string | |
default: main | |
description: "The branch, tag, or SHA to run the workflow from" | |
workflow_dispatch: | |
inputs: | |
ref: | |
type: string | |
default: main | |
description: "The branch, tag, or SHA to run the workflow from" | |
jobs: | |
run: | |
name: Build + Deploy to GitHub Pages (iff www/ has changed since last gh-pages push) | |
runs-on: ubuntu-latest | |
steps: | |
# See https://github.com/actions/checkout/issues/265#issuecomment-1936792528 | |
- name: Resolve inputs.ref to full SHA | |
id: resolve-ref | |
env: | |
GH_TOKEN: ${{ secrets.GH_TOKEN }} | |
run: | | |
ref=${{ inputs.ref }} | |
sha=$(gh api /repos/$GITHUB_REPOSITORY/commits/$ref | jq -r .sha) | |
if [ -z "$sha" ]; then | |
echo "Failed to resolve ref $ref (possibly missing GH_TOKEN env var?)" >&2 | |
exit 1 | |
fi | |
echo "Expanded ref $ref to SHA $sha" | |
echo "sha=$sha" >> $GITHUB_OUTPUT | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ steps.resolve-ref.outputs.sha }} | |
- uses: pnpm/action-setup@v2 | |
with: | |
version: 8 | |
- run: git fetch origin gh-pages | |
- id: base-sha | |
run: echo "BASE_SHA=$(./parse-ghp-base-sha.py -d root origin/gh-pages)" >> $GITHUB_OUTPUT | |
- name: Check whether www was changed | |
id: www-changed | |
env: | |
BASE_SHA: ${{ steps.base-sha.outputs.BASE_SHA }} | |
run: | | |
echo "BASE_SHA: $BASE_SHA" | |
git fetch --depth 1 origin $BASE_SHA | |
echo "WWW_CHANGED=$([ $BASE_SHA != 'root' ] && git diff --quiet $BASE_SHA && echo '' || echo 'true')" >> $GITHUB_OUTPUT | |
- run: | | |
echo "WWW_CHANGED: ${{ steps.www-changed.outputs.WWW_CHANGED }}" | |
- if: steps.www-changed.outputs.WWW_CHANGED | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 19 | |
cache: 'pnpm' | |
cache-dependency-path: www/pnpm-lock.yaml | |
- name: pnpm install, build, export | |
if: steps.www-changed.outputs.WWW_CHANGED | |
env: | |
S3_DBs: 1 | |
run: | | |
cd www | |
pnpm install | |
pnpm run gha-export | |
du -sh out | |
- if: steps.www-changed.outputs.WWW_CHANGED | |
name: Deploy to GH Pages | |
uses: JamesIves/github-pages-deploy-action@v4 | |
with: | |
branch: gh-pages | |
folder: www/out |