Skip to content

Build + Deploy to GitHub Pages #294

Build + Deploy to GitHub Pages

Build + Deploy to GitHub Pages #294

Workflow file for this run

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@v4
with:
version: 9
- 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: 20
cache: 'pnpm'
cache-dependency-path: www/pnpm-lock.yaml
- uses: actions/setup-python@v5
if: steps.www-changed.outputs.WWW_CHANGED
with:
python-version: 3.11
cache: pip
- name: Install sql-query
if: steps.www-changed.outputs.WWW_CHANGED
run: pip install -e sql-query
- name: pnpm install, build, export
if: steps.www-changed.outputs.WWW_CHANGED
env:
S3_DBS: 1
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-east-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