Deploying to Github Pages
Constructing the workflow
Designing the workflow
# .github/workflows/cd.yml
name: Deploying to Github Pages
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Fetch repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'yarn'
- name: Install dependencies
run: |
yarn
- name: Building
run: |
NODE_ENV=production yarn build
- name: Uploading production artifacts
uses: actions/upload-pages-artifact@v3
with:
name: github-pages
path: dist
deploy:
needs: build
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Publishing production artifact
id: deployment
uses: actions/deploy-pages@v4
with:
artifact_name: github-pagesBreaking it down
Conditional workflow trigger
build job
Publishing artifacts
deploy job
Permissions & secrets
Environments
Deploying the artifact
Visualizing the workflow


Verifying the workflow






Last updated