GitHub Pages 06 ๐ GitHub Actions & OIDC Pipelines โ Automating deploys with configure-pages, upload-pages-artifact, and deploy-pages
GitHub Pages has transitioned from a simple branch-based hosting service to a fully integrated CI/CD platform. While the traditional method required pushing built files to a gh-pages branch, the modern approach utilizes GitHub Actions to build, package, and deploy directly from the source code. This shift eliminates the need for keeping “dist” or “build” folders in version control and provides a more secure, transparent pipeline using OpenID Connect (OIDC).
The core of this modern workflow is a trio of official actions: configure-pages, upload-pages-artifact, and deploy-pages. These actions work in sequence to prepare the environment, bundle the website content, and securely hand it off to the GitHub Pages infrastructure. By moving the deployment logic into a YAML workflow, developers gain granular control over build steps, environment variables, and deployment permissions.
This chapter covers the end-to-end configuration of an Actions-based deployment pipeline. We will explore the specific permissions required for OIDC authentication, the mechanics of artifact uploading, and the final deployment step that brings the site live. We will also examine how these actions handle common issues like base-path configuration for Single Page Applications (SPAs).
Key point: Modern GitHub Pages deployment uses GitHub Actions to build and deploy via artifacts; this requires setting the repository source to “GitHub Actions” and granting id-token: write permissions to allow secure OIDC-based deployment.
Why X exists
1. The branch pollution problem.
In the legacy model, developers had to push compiled build artifacts (HTML, CSS, JS) to a specific branch like gh-pages. This cluttered the repository history with machine-generated code, making it difficult to track actual source code changes and increasing the repository size unnecessarily.
2. Lack of build-time control.
Traditional branch-based hosting assumes the code is “ready to serve.” For modern frameworks like React, Vue, or Hugo, a build step is required. Using GitHub Actions allows these build steps to happen in a clean, isolated virtual environment, ensuring that the deployment is consistent regardless of the developer’s local machine state.
3. The security of OIDC.
Historically, automated deployments often required long-lived secrets or tokens. By using actions/deploy-pages with OIDC, GitHub provides a short-lived, identity-based token. This “keyless” approach reduces the risk of credential theft, as the deployment permissions are granted dynamically to the specific workflow run.
4. Artifact-based reliability.
Instead of syncing files from a branch, the new system uses “Artifacts.” The build step produces a single compressed bundle that is uploaded to GitHub’s internal storage. The deployment step then pulls this exact bundle. This ensures that what was built in the first stage is exactly what is deployed in the second, preventing partial sync issues.
5. Unified environment management.
GitHub Actions allows for different deployment environments (e.g., preview vs. production). The configure-pages action automatically detects the repository’s settings and provides the correct base URL to the build tools, simplifying the process of hosting sites under custom domains or sub-paths.
a. Initializing with actions/configure-pages
The configure-pages action is the first step in a deployment workflow. Its primary job is to gather metadata about the GitHub Pages site and inject it into the workflow environment. This is especially useful for setting the correct base URL for static site generators.
- name: Setup Pages
uses: actions/configure-pages@v5
When this action runs, it populates several outputs, such as base_url and origin. If your site is hosted at username.github.io/my-repo/, the build tool needs to know this to correctly link CSS and JS files. You can pass these outputs directly to your build command.
- name: Build with Hugo
run: hugo --baseURL ${{ steps.pages.outputs.base_url }}
id: build-step
This ensures that your application is “location-aware” during the compilation phase, preventing broken links that often occur when moving a project from a root domain to a sub-folder.
b. Packaging with actions/upload-pages-artifact
Once the build step is complete and you have a folder full of static files (typically dist, build, or public), you must package them. The upload-pages-artifact action takes a specified directory and uploads it as a special “github-pages” artifact.
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: './dist' # The directory containing the static files
This action handles the compression and naming conventions required by the GitHub Pages deployment engine. It is important to note that only one Pages artifact can be deployed per workflow run. If your build produces multiple outputs, they must all be contained within the single directory specified in the path parameter.
The artifact created here is temporary and typically expires after a few hours, serving only as a bridge between the “build” job and the “deploy” job in your workflow.
c. Deployment and Permissions with actions/deploy-pages
The final step is the actual deployment. This is handled by actions/deploy-pages. This action takes the artifact uploaded in the previous step and triggers the internal GitHub Pages deployment engine to update the live site.
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
For this to work, your workflow must have specific permissions. Because deploy-pages uses OIDC to verify the identity of the workflow, you must explicitly grant id-token: write and pages: write permissions at the top of your YAML file.
permissions:
contents: read
pages: write
id-token: write
Without these permissions, the action will fail with a 403 Forbidden error. This security model ensures that only authorized workflows from your specific repository can modify the hosted content, providing a significant security upgrade over manual token-based systems.
Complete Example Session
# ============================================
# PART 1: WORKFLOW NAME AND TRIGGERS
# ============================================
name: Deploy Static Site
on:
push:
branches: ["main"] # Trigger on push to main
workflow_dispatch: # Allow manual triggering
# ============================================
# PART 2: PERMISSIONS (CRITICAL FOR OIDC)
# ============================================
permissions:
contents: read
pages: write
id-token: write
# ============================================
# PART 3: CONCURRENCY CONTROL
# ============================================
concurrency:
group: "pages"
cancel-in-progress: true
# ============================================
# PART 4: THE BUILD JOB
# ============================================
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
# ============================================
# PART 5: CONFIGURE PAGES (Step a)
# ============================================
- name: Setup Pages
uses: actions/configure-pages@v5
id: pages
# ============================================
# PART 6: BUILD THE SITE
# ============================================
- name: Install dependencies
run: npm install
- name: Build project
run: npm run build # Creates a 'dist' folder
# ============================================
# PART 7: UPLOAD ARTIFACT (Step b)
# ============================================
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: './dist'
# ============================================
# PART 8: THE DEPLOY JOB
# ============================================
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build # Wait for build to finish
steps:
# ============================================
# PART 9: DEPLOY PAGES (Step c)
# ============================================
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
# ============================================
# PART 10: OUTPUT VERIFICATION
# ============================================
# The 'page_url' output provides the final live link
The parts covered the trigger logic, the necessary security permissions, the build-to-artifact pipeline, and the final OIDC-verified deployment job.
Quick Reference
Required Permissions
| Permission | Level | Reason |
|---|---|---|
contents | read | To checkout the source code |
pages | write | To modify the Pages site content |
id-token | write | To authenticate via OIDC |
Core Action Functions
| Action | Function | Key Input |
|---|---|---|
configure-pages | Detects URL/Paths | N/A |
upload-pages-artifact | Bundles files | path (e.g. ./dist) |
deploy-pages | Goes Live | N/A |
Workflow Settings
| Setting | Recommendation | Reason |
|---|---|---|
concurrency | cancel-in-progress: true | Prevents race conditions on rapid pushes |
runs-on | ubuntu-latest | Standard reliable environment |
environment | github-pages | Links deployment to the UI dashboard |
Best Practices
โ Do This:
# Set concurrency to prevent multiple deployments
concurrency: pages # โ
# Use specific environment for deployment tracking
environment: github-pages # โ
# Always use the latest major version of actions
uses: actions/deploy-pages@v4 # โ
# Include 'id-token: write' for secure OIDC
permissions: { id-token: write } # โ
โ Don’t Do This:
# Don't commit 'dist' or 'build' to the repo
# (Let Actions build it) # โ
# Don't use personal access tokens (PATs) for Pages
# (Use the built-in OIDC permissions) # โ
# Don't forget 'needs: build' in the deploy job
# (Deploy will run before build finishes) # โ
Common Pitfalls
| Pitfall | Why It Happens | Fix |
|---|---|---|
| 403 Forbidden | Missing id-token: write | Add OIDC permissions to YAML |
| Broken Assets | Base path mismatch | Use configure-pages outputs for build |
| Empty Deploy | Wrong path in upload-artifact | Verify build folder name (dist/build) |
| Concurrent Fail | Two deploys running at once | Add concurrency group to YAML |
| File Limit | Artifact > 10GB or 10k files | Clean up unnecessary files before upload |
Real-World Examples
1. Permissions Block
permissions:
pages: write
id-token: write
2. Concurrency Group
concurrency:
group: "pages"
cancel-in-progress: true
3. Setup Pages Output
- run: echo "URL: ${{ steps.pages.outputs.base_url }}"
4. Uploading sub-folder
with:
path: 'public'
5. Manual Dispatch Trigger
on: [push, workflow_dispatch]
6. Hugo Build with Base URL
run: hugo --baseURL ${{ steps.pages.outputs.base_url }}
7. Node Environment Setup
- uses: actions/setup-node@v4
with: { node-version: 20 }
8. Deployment Job URL Output
url: ${{ steps.deployment.outputs.page_url }}
9. Checking Out Code
uses: actions/checkout@v4
10. Conditional Deploy
if: github.ref == 'refs/heads/main'
Visual
The Artifact-Based Pipeline
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ BUILD JOB โ โ GITHUB ARTIFACT โ โ DEPLOY JOB โ
โ โ โ STORAGE โ โ โ
โ [npm run build] โโโโโ โ โ โโโโบโ [deploy-pages] โ
โ [upload-pages- โ โ โ โโโโโโโโโโโโโโ โ โ โ โ
โ artifact] โ โโโโบโ โ website.tarโ โโโโโ โ LIVE SITE LIVE โ
โโโโโโโโโโโโโโโโโโโ โ โโโโโโโโโโโโโโ โ โโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโ
OIDC Authentication Handshake
โโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ GITHUB ACTIONS RUN โ โ GITHUB OIDC ISSUER โ โ PAGES DEPLOYER โ
โโโโโโโโโโโฌโโโโโโโโโโโ โโโโโโโโโโโฌโโโโโโโโโโโ โโโโโโโโโโฌโโโโโโโโโ
โ โ โ
โ 1. Request JWT โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโบโ โ
โ โ โ
โ 2. Signed Identity Token โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ
โ โ โ
โ 3. Present Token + Artifact โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโบโ
โ โ โ
โ โ 4. Verify & Deployโ
โผ โผ โผ
Concurrency Logic
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ GITHUB PAGES DEPLOYMENT QUEUE โ
โ โ
โ RUN #1 [====PROGRESS====] <-- Cancelled (if new push) โ
โ โ
โ RUN #2 [====WAITING=====] <-- Starts next โ
โ โ
โ (Ensures only one version of the site is live at once) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Summary
| Item | Value |
|---|---|
| Setup Action | actions/configure-pages |
| Packaging Action | actions/upload-pages-artifact |
| Execution Action | actions/deploy-pages |
| Auth Method | OIDC (OpenID Connect) |
| Permission 1 | pages: write |
| Permission 2 | id-token: write |
| Source Setting | GitHub Actions (in Repo Settings) |
Key takeaways:
- Switch to Actions-based deployment. Move away from the legacy branch-based method to gain better build control and keep your repository clean.
- OIDC is the security backbone. By granting
id-token: writepermissions, you allow GitHub to verify the deployment without using permanent secrets. - The pipeline is artifact-centric. The build job packages your site into an artifact, and the deploy job fetches that artifact, ensuring consistency.
configure-pagessolves the base-path problem. Use the outputs from this action to dynamically set the base URL of your application during the build phase.- Manage concurrency. Always use a concurrency group in your YAML to prevent multiple deployment runs from clashing or causing race conditions.
- Environment visibility. Setting the
environmenttogithub-pagesallows you to track deployments directly from the GitHub repository’s main page.
Remember: To use this modern workflow, you must go to your Repository Settings > Pages and change the “Source” from “Deploy from a branch” to “GitHub Actions.” This unlocks the ability for your workflows to talk to the Pages infrastructure via artifacts and OIDC tokens.
Stop using slow, ad-bloated tool sites! ๐คฎ
๐ Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
โ
Finance (Mortgage, Interest, Inflation)
โ
Tech (Base64, JSON, Dev Suite, IP)
โ
Health (BMI, BMR, TDEE)
โ
Productivity (Timer, Workspace, QR)
โก๏ธ Fast & Private
๐ No data leaves your device
๐ 100% Free
๐ Use it now: https://tools.kandz.me
๐ Bookmark itโyouโll need it later!