GitHub Actions Workflow for Build a Static Site and Deploy to Pages
Build a static site and ship it to GitHub Pages.
This workflow builds your site, uploads the output as a Pages artifact, and deploys it with the official actions.
The workflow
.github/workflows/pages.yml
name: Pages
on:
push:
branches: [main]
permissions:
contents: read
pages: write
id-token: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: 20, cache: npm }
- run: npm ci
- run: npm run build
- uses: actions/upload-pages-artifact@v3
with: { path: dist }
deploy:
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- id: deployment
uses: actions/deploy-pages@v4Notes
- Needs
pages: writeandid-token: write. - Enable Pages with the GitHub Actions source in repo settings.
- The deploy job consumes the artifact uploaded by the build job.
Run it cheaper
Point runs-on: at a Latchkey label to run this workflow at roughly 69% lower per-minute cost, with self-healing for transient failures.