1 min read

CI/CD with GitHub Actions for Static Sites

A simple, fast GitHub Actions workflow that builds a statically exported site and deploys it to GitHub Pages on every push.

On this page

Static sites are the easiest thing to deploy well: build once, ship the files, done. GitHub Actions makes that automatic on every push.

The shape of the workflow

Install dependencies, build the export, then upload and deploy the output folder.

yaml
- uses: actions/checkout@v4
- run: corepack enable && pnpm install --frozen-lockfile
- run: pnpm build
- uses: actions/upload-pages-artifact@v3
  with:
    path: ./out

Keep it fast

  • Cache the package store so installs are near-instant.
  • Pin action versions for reproducible runs.
  • Fail the build on lint errors so problems never reach production.

Because the output is just static files, a deploy is atomic and a rollback is one revert away.

Fixing commit authorship

Migrated repos sometimes carry the wrong author on past commits. This script rewrites authorship across history:

#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="[email protected]"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="[email protected]"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags