How to Deploy to GitHub Pages With GitHub Actions
Upload the built site as a Pages artifact, then call actions/deploy-pages, which publishes to the github-pages environment.
Set the Pages source to "GitHub Actions", grant pages: write and id-token: write, upload the build with actions/upload-pages-artifact, then deploy with actions/deploy-pages.
Steps
- In repo settings, set Pages source to GitHub Actions.
- Build the site into a directory.
- Upload it with
actions/upload-pages-artifact. - Deploy with
actions/deploy-pagesin a job targeting thegithub-pagesenvironment.
Workflow
.github/workflows/pages.yml
permissions:
pages: write
id-token: write
contents: read
jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deploy.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm run build
- uses: actions/upload-pages-artifact@v3
with: { path: dist }
- id: deploy
uses: actions/deploy-pages@v4Common pitfalls
- If Pages source is set to "Deploy from a branch",
deploy-pagesfails; switch it to "GitHub Actions". - The artifact must be named the Pages default (
github-pages); useupload-pages-artifact, not the generic upload action. - Missing
id-token: writecauses the deploy step to fail because Pages verifies the run via OIDC.
Related guides
How to Deploy a Static Site to S3 and CloudFront With GitHub ActionsPublish a static site to S3 and invalidate the CloudFront cache from GitHub Actions, syncing the build output…
How to Deploy to Cloudflare Pages With GitHub ActionsDeploy a build to Cloudflare Pages from GitHub Actions with the Wrangler CLI and the cloudflare/wrangler-acti…