| | |

GitHub Pages 06 ๐Ÿ“„ GitHub Actions & OIDC Pipelines โ€” Automating deploys with configure-pages, upload-pages-artifact, and deploy-pages

โฑ๏ธ Estimated read: 9 min | |

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

PermissionLevelReason
contentsreadTo checkout the source code
pageswriteTo modify the Pages site content
id-tokenwriteTo authenticate via OIDC

Core Action Functions

ActionFunctionKey Input
configure-pagesDetects URL/PathsN/A
upload-pages-artifactBundles filespath (e.g. ./dist)
deploy-pagesGoes LiveN/A

Workflow Settings

SettingRecommendationReason
concurrencycancel-in-progress: truePrevents race conditions on rapid pushes
runs-onubuntu-latestStandard reliable environment
environmentgithub-pagesLinks 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

PitfallWhy It HappensFix
403 ForbiddenMissing id-token: writeAdd OIDC permissions to YAML
Broken AssetsBase path mismatchUse configure-pages outputs for build
Empty DeployWrong path in upload-artifactVerify build folder name (dist/build)
Concurrent FailTwo deploys running at onceAdd concurrency group to YAML
File LimitArtifact > 10GB or 10k filesClean 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

ItemValue
Setup Actionactions/configure-pages
Packaging Actionactions/upload-pages-artifact
Execution Actionactions/deploy-pages
Auth MethodOIDC (OpenID Connect)
Permission 1pages: write
Permission 2id-token: write
Source SettingGitHub 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: write permissions, 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-pages solves 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 environment to github-pages allows 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.

Was this helpful?


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!