GitHub Actions release pipeline with a production gate

Build and test a static site with GitHub Actions, then require a production approval before GitHub Pages deploys the build artifact.

published: reading time: 7 min read author: Geek Workbench updated: November 3, 2026
Quick Summary

This guide builds and deploys a static site through GitHub Actions and GitHub Pages. Pull requests run checks; updates to main build a Pages artifact and pause for an environment reviewer before deployment.

GitHub Actions release pipeline with a production gate

This guide uses one stack: GitHub Actions builds a static site, then GitHub Pages hosts it. Pull requests run checks and create a build artifact but do not deploy. A change merged to main builds a new artifact and waits for a reviewer before publishing it. Here, a release means publishing that reviewed site build; this guide does not cover package versioning or npm publication.

The test commands below are examples; map them to scripts your project actually defines. For test selection and CI quality gates, see Automated Testing in CI/CD. The Pages artifact represents the exact build output passed from the build job to deployment. For retention, provenance, and other artifact types, see Artifact Management.

Workflow at a glance

flowchart LR
    A[Pull request or main update] --> B[Lint, test, build]
    B --> C[Upload Pages artifact]
    C --> D{Event}
    D -->|Pull request| E[Checks finish; no deployment]
    D -->|Main update| F[Production approval]
    F --> G[Deploy to GitHub Pages]

A passing pull request run checks the proposed change and creates a Pages artifact; it does not publish the site. Merging to main repeats the checks on the merge commit. Only then does the deployment job reach the github-pages environment.

Reference stack and versions

These versions were checked against official releases on 2026-11-03. The workflow below uses the same exact tags. Recheck release notes before upgrading an action or Node.js.

Tool Version used Source
Node.js LTS 24.22.2 Node.js release notes
GitHub-hosted runner ubuntu-24.04 Available runner image releases
actions/checkout 7.0.1 Official release
actions/setup-node 7.1.0 Official release
actions/configure-pages 6.0.0 Official release
actions/upload-pages-artifact 5.0.0 Official release
actions/deploy-pages 5.0.1 Official release

The action tags point to versioned releases rather than floating @vN references. The workflow targets GitHub.com and the GitHub-hosted ubuntu-24.04 image. GitHub updates the image over time; the runner image releases list the changes.

Prepare the repository

Before adding the workflow:

  1. Commit package-lock.json so npm ci installs the locked dependency tree.
  2. Make sure package.json has the scripts used below: lint, test, and build. Replace those names if your project uses different commands.
  3. Make the static build write to dist/. If it writes somewhere else, change the artifact path in the workflow.
  4. Confirm that your generator emits asset URLs for the final Pages address. If it needs a base path for a project site, configure that before the build.
  5. In repository Settings → Pages, select GitHub Actions as the publishing source. The GitHub Pages custom workflow guide describes the required permissions and artifact handoff.
  6. In Settings → Environments, create github-pages, restrict deployments to main, and add required reviewers.

The environment field in YAML connects a job to an environment. It does not create an approval rule by itself. With required reviewers configured, GitHub pauses the deployment job before its steps run; approval lets the job continue and access environment secrets. Reviewer-rule availability depends on repository visibility and plan, so check GitHub’s current deployment review guidance before relying on the gate.

Add the workflow

Save this as .github/workflows/release.yml. It runs the checks on pull requests and main updates. A manual run can also deploy, but only when it is started from main.

name: Build and deploy static site

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
  workflow_dispatch:

permissions:
  contents: read

jobs:
  build:
    runs-on: ubuntu-24.04
    permissions:
      contents: read
      pages: read
    steps:
      - name: Check out source
        uses: actions/checkout@v7.0.1

      - name: Set up Node.js
        uses: actions/setup-node@v7.1.0
        with:
          node-version: 24.22.2
          cache: npm

      - name: Configure Pages
        uses: actions/configure-pages@v6.0.0

      - name: Install dependencies
        run: npm ci

      - name: Lint
        run: npm run lint

      - name: Test
        run: npm test

      - name: Build site
        run: npm run build

      - name: Upload build artifact
        uses: actions/upload-pages-artifact@v5.0.0
        with:
          path: ./dist

  deploy:
    if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
    needs: build
    runs-on: ubuntu-24.04
    permissions:
      contents: read
      pages: write
      id-token: write
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v5.0.1

The workflow assumes Node.js 24.22.2 and the action versions listed above, checked on 2026-11-03. The build job uploads dist/; the deploy job depends on it, so Pages receives the artifact from that run instead of rebuilding it. The GitHub Pages deployment docs describe this artifact-based workflow pattern.

Check the approval and deployment

Open a pull request to main. The build job should run lint, tests, and the production build. The deploy job should be skipped. If a script is missing or the build directory is wrong, the run fails before anything reaches the site.

After merging, the same checks run on main. The deploy job should wait for an environment reviewer. A reviewer opens Review deployments and chooses Approve and deploy or Reject. After approval, the deployment step publishes the artifact and exposes the Pages URL as steps.deployment.outputs.page_url.

This is a manual production gate: a passing build does not publish until someone approves it. If your team wants automatic production deployment, remove the required reviewer rule and update the title and release policy to match.

Roll back a bad deployment

For a single source commit that caused a bad site, make a new commit that reverses it. git revert records a new commit rather than rewriting the published branch history; see the Git revert documentation.

git switch -c revert-bad-release
git revert <bad-release-commit>
git push -u origin revert-bad-release

Open a pull request for the revert and let the workflow check it. The command above assumes a regular commit (including a squash merge). For a merge commit, choose its mainline parent with git revert -m <parent-number> <merge-commit>; verify that parent before reverting. After the revert is merged to main, the pipeline rebuilds the restored source state. Review and approve the github-pages deployment, then check the Pages URL and the route that failed.

This rollback rebuilds from source; it does not restore a byte-for-byte copy of an older artifact. Keep the lockfile and runtime version aligned so the rebuild uses the intended dependency set. For a release that must redeploy the exact previous bytes, retain and promote that immutable artifact through a separate release process. The artifact management guide covers retention and provenance choices.

Alternatives

If you use… Keep Replace
GitLab The PR checks, build, and approval sequence The GitHub Actions workflow and Pages deploy action with GitLab CI and GitLab Pages jobs
Netlify or Vercel The checks, locked dependencies, and build output The Pages artifact and deploy jobs with the host’s deployment integration and approval controls

The example stays on GitHub so the workflow and its production gate are concrete. For broader pipeline stage and job design, see CI/CD Pipeline Design.

Conclusion

Pull requests get the checks without publishing. Only a reviewed build from main reaches Pages, and a bad deployment can be corrected with a revert that goes through the same gate.

Category

Related Posts

Automated Releases and Tagging

Automate Git releases with tags, release notes, GitHub Releases, and CI/CD integration for consistent, repeatable software delivery.

#git #version-control #automation

Git in CI/CD Pipelines: Triggers, Webhooks, Shallow Clones, and Optimization

Understand how CI/CD systems interact with Git repositories. Learn about triggers, webhooks, shallow clones, pipeline optimization, and production patterns for Git-aware CI/CD.

#git #version-control #ci-cd

How to build and deploy a static site with Astro 7.4

Use Astro 7.4 to build a static site: pin Node, add a page and component, hydrate one React island, query a Markdown collection, and deploy the output.

#astro #static-sites #react