GitHub CI/CD
Continuous integration (CI) checks a change against the rest of the code before it is merged. Continuous delivery prepares a releasable build after those checks pass. Continuous deployment publishes that build automatically when its deployment rules allow it. A required reviewer can turn the last step into a manual release decision.
This walkthrough uses the Dev Handbooks frontend as a worked example. GitHub Actions runs its tests and builds its Docker image. GitHub Container Registry (GHCR) stores the image. A Linux deployment host pulls that exact image and runs Nginx in a container. The examples describe a setup you can add to your repository.
flowchart LR
PR["Pull request targeting main"] --> CI["GitHub runner: install, test, prerender"]
CI --> Review["GitHub: required check and review"]
Review --> Main["Push to main"]
Main --> Verify["GitHub runner: verify merged commit"]
Verify --> Publish["GitHub runner: build and push image"]
Publish --> Registry["GHCR: store image by digest"]
Publish --> Deploy["GitHub runner: SSH to deployment host"]
Registry --> Host["Linux host: pull exact image"]
Deploy --> Host
Host --> Browser["Nginx serves the frontend"]Where everything runs
GitHub reads workflow files from .github/workflows at the repository root. An event such as pull_request creates a run. Each job in this example gets its own GitHub-hosted Ubuntu VM. Steps in a job share the checked-out files, but each run step starts a new shell. The VM is discarded when the job ends. Your production server stays online independently of those VMs.
A cache saves reusable inputs such as downloaded dependencies. An artifact saves output you want to inspect or use elsewhere, such as a test report or static build. Jobs do not share a filesystem. This pipeline uses the registry to transfer the image and a job output to transfer its digest, the content identifier that fixes exactly which image to pull.
Self-hosted runners
A self-hosted runner is an agent on a machine you operate. GitHub schedules the job and receives the logs. Your VM, physical server, or Kubernetes pod executes the steps. Use one when a job needs access to a private network, specific hardware, or software you manage. You own the machine’s capacity, OS and tool updates, isolation, monitoring, and cost.
On a dedicated Linux VM, create an unprivileged runner account and allow outbound HTTPS to GitHub’s required endpoints. In the repository or organization settings, open Actions → Runners → New self-hosted runner. Select Linux and the machine architecture. Run GitHub’s generated download, checksum, and configuration commands on the VM. The registration token expires after one hour.
Start the runner with ./run.sh for a foreground test. Once it appears Idle in Actions → Runners, stop the foreground process and install the Linux service from the runner directory. Replace runner-user with the account you created.
sudo ./svc.sh install runner-user
sudo ./svc.sh start
sudo ./svc.sh statusRunner scope controls which repositories can reach the machine. A repository runner serves one repository. An organization or enterprise runner can serve repositories allowed by its runner group. Labels describe capabilities and route jobs. Every label in a runs-on list must match. Use the group policy to control access and the labels to select a machine within that group.
In a private repository, add a deployment runner to the organization group frontend-deploy and assign it the deploy-network label. Restrict the group to the repository and, where available, the deployment workflow. In the workflow below, keep verify and publish on GitHub-hosted machines. Replace only the deploy job’s runs-on field with this configuration. Keep its main-branch gate through publish, the production environment, and the deployment steps. Install an SSH client on the runner and confirm it can reach DEPLOY_HOST.
runs-on:
group: frontend-deploy
labels: deploy-networkUse GitHub-hosted runners for public pull requests. A job can execute repository code with the runner account’s privileges. On a persistent self-hosted machine, a job can leave files or processes that affect later jobs, and private repositories can also accept untrusted code. Keep deployment runners separate from build runners and give them only the network access they need.
Each runner agent takes one job at a time. If matching runners are busy or offline, the job waits for up to 24 hours. Check group access, labels, service status, and connectivity when a job stays queued. An ephemeral runner deregisters after one job. Your provisioning system still needs to destroy or wipe the machine and ship the logs elsewhere. Actions Runner Controller can automate ephemeral runner pools on Kubernetes.
Self-hosted runner requirements and job routing
Quotas and billing by repository visibility
Repository visibility and runner type determine how compute is billed on GitHub.com. The repository owner’s account pays for eligible usage. Its monthly included compute is shared across eligible repositories and products, including cloud sandbox usage. The allowance resets each billing cycle.
| Runner type | Public repository | Private or internal repository |
|---|---|---|
| Standard GitHub-hosted | Free compute | Draws from included compute, then billed at the runner rate |
| Larger GitHub-hosted | Billed at the runner rate | Eligible Team and Enterprise Cloud usage draws from included compute, then is billed |
| Self-hosted | No GitHub runner compute charge | No GitHub runner compute charge |
Self-hosting still costs you infrastructure and maintenance. Artifact uploads and dependency caches use GitHub storage independently of runner compute. Artifact storage shares its allowance with GitHub Packages. Storage accrues over time, so retention affects usage. The included cache allocation is 10 GB per repository.
| GitHub plan | Monthly compute allowance | Included artifact storage | Concurrent standard hosted jobs |
|---|---|---|---|
| Free (personal or organization) | $12 | 500 MB | 20 |
| Pro | $18 | 1 GB | 40 |
| Team | $18 | 2 GB | 60 |
| Enterprise Cloud | $300 | 50 GB | 500 |
Example: at a Linux runner rate of $0.006 per minute, 250 runs with two four-minute jobs consume 2,000 runner minutes, or $12 of included compute. Parallel jobs may finish in about four minutes of elapsed time per run, but both jobs count. Different runner types and other eligible workloads change how far the monthly allowance goes.
Concurrency is a separate limit. It caps how many jobs can run at once even when standard hosted compute is free. GitHub also caps hosted jobs at six hours and self-hosted jobs at five days. A workflow can set a shorter timeout-minutes. macOS and larger runners have additional concurrency limits.
In the owner’s Billing and licensing settings, use Usage to see which repositories and runner types consume the allowance. Review budgets and alerts before enabling overage. A budget configured to stop usage can block eligible jobs once its limit is reached. Check the linked billing and limits pages when planning capacity.
GitHub Actions billing and included usage
Workflow example
Save the example as .github/workflows/frontend.yml. Replace ghcr.io/example-owner/languages-frontend with your lowercase package path and replace the production URL in your GitHub settings. The pull request runs the verification job. A push to main, including a merge, verifies the resulting commit again before publishing. Manual dispatch can run the same workflow, with publishing restricted to main.
name: Frontend CI/CD
on:
pull_request:
branches: [main]
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
env:
IMAGE: ghcr.io/example-owner/languages-frontend
jobs:
verify:
name: Verify frontend
runs-on: ubuntu-latest
defaults:
run:
working-directory: frontend
steps:
- uses: actions/checkout@v6
- uses: pnpm/action-setup@v4
with:
version: 10.20.0
- uses: actions/setup-node@v6
with:
node-version: '22'
cache: pnpm
cache-dependency-path: frontend/pnpm-lock.yaml
- run: pnpm install --frozen-lockfile
- run: pnpm run check:i18n
- run: pnpm test
- run: pnpm run build
- run: pnpm run check:ssr-i18n
publish:
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
needs: verify
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
digest: ${{ steps.image.outputs.digest }}
steps:
- uses: actions/checkout@v6
- name: Build and push image
id: image
env:
GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VITE_SITE_URL: ${{ vars.FRONTEND_SITE_URL }}
SOURCE_URL: ${{ github.server_url }}/${{ github.repository }}
run: |
: "${VITE_SITE_URL:?Set FRONTEND_SITE_URL in repository variables}"
printf '%s' "$GHCR_TOKEN" | docker login ghcr.io -u "$GITHUB_ACTOR" --password-stdin
docker build --pull \
--build-arg "VITE_SITE_URL=$VITE_SITE_URL" \
--label "org.opencontainers.image.source=$SOURCE_URL" \
--tag "$IMAGE:$GITHUB_SHA" frontend
docker push "$IMAGE:$GITHUB_SHA"
reference=$(docker image inspect --format '{{index .RepoDigests 0}}' "$IMAGE:$GITHUB_SHA")
digest=${reference##*@}
[[ "$digest" =~ ^sha256:[0-9a-f]{64}$ ]]
printf 'digest=%s\n' "$digest" >> "$GITHUB_OUTPUT"
deploy:
needs: publish
runs-on: ubuntu-latest
environment:
name: production
url: ${{ vars.FRONTEND_SITE_URL }}
concurrency:
group: frontend-production
cancel-in-progress: false
steps:
- name: Deploy over SSH
env:
DIGEST: ${{ needs.publish.outputs.digest }}
DEPLOY_HOST: ${{ vars.DEPLOY_HOST }}
DEPLOY_USER: ${{ vars.DEPLOY_USER }}
SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
KNOWN_HOSTS: ${{ secrets.DEPLOY_KNOWN_HOSTS }}
run: |
[[ "$DIGEST" =~ ^sha256:[0-9a-f]{64}$ ]]
umask 077
mkdir -p ~/.ssh
printf '%s\n' "$SSH_KEY" > ~/.ssh/deploy_key
printf '%s\n' "$KNOWN_HOSTS" > ~/.ssh/known_hosts
ssh -o BatchMode=yes -o StrictHostKeyChecking=yes -i ~/.ssh/deploy_key \
-- "$DEPLOY_USER@$DEPLOY_HOST" "/srv/languages/deploy.sh $DIGEST"The frontend lockfile is frontend/pnpm-lock.yaml. The verification job uses Node.js 22 and pnpm 10.20.0 to match the Docker build. It checks French catalog coverage, runs unit tests, builds the client and server bundles, prerenders both locales, and checks the resulting HTML. The image job runs the Dockerfile from the same commit and passes the public site URL as a build argument.
Workflow YAML field reference
| Field | Role |
|---|---|
on | Selects events and filters. For pull_request, branches matches the target branch. For push, it matches the branch receiving the commit. |
jobs, runs-on, needs | Names the jobs, selects their runner, and declares which jobs must succeed first. |
steps, uses, run, with | Lists steps in order. uses invokes an action, run invokes a shell command, and with provides action inputs. |
permissions | Scopes the automatic GITHUB_TOKEN. Only the publishing job receives packages: write. |
env, vars, secrets | Supplies environment variables, reads GitHub configuration variables, and accesses credentials explicitly passed to a job or step. |
outputs, needs | Exposes a value from one job and reads it in a dependent job. The publish step writes its digest to GITHUB_OUTPUT. |
environment, concurrency | Associates a job with deployment rules and limits simultaneous deployments in the same group. Concurrency does not guarantee FIFO ordering. |
Set up GitHub and the deployment host
Enable GitHub Actions and allow the actions used by the workflow. Open a pull request and check that Verify frontend appears in its checks. Then make that check required for main using a ruleset or branch protection. If you use a merge queue, add a merge_group trigger so its required check runs there as well.
In Settings → Secrets and variables → Actions, create the repository variable FRONTEND_SITE_URL with your public HTTPS origin. Vite uses it at build time for canonical URLs and the sitemap. Keep credentials out of VITE_ variables because client-side values can be exposed in the bundle.
Create the production environment in Settings → Environments. Restrict deployment to main and add required reviewers if your plan supports them and you want approval before release. Add DEPLOY_HOST and DEPLOY_USER as environment variables. Add DEPLOY_SSH_KEY and DEPLOY_KNOWN_HOSTS as environment secrets. Populate known_hosts from a host key verified through your hosting provider or another trusted channel.
Generate a dedicated Ed25519 key pair with ssh-keygen -t ed25519 -f frontend-deploy. Add the public key to the deployment account’s authorized_keys and store the private key as DEPLOY_SSH_KEY. This unattended example needs a key that SSH can load without a passphrase prompt. Use a firewall and restrict the key to the deployment command where practical.
Give the workflow write access to the GHCR package. The example labels the image with its source repository. For an existing package, verify its Actions access in the package settings. For private images, log in to ghcr.io on the server as the deployment account with a credential that can read the package. Public images can be pulled anonymously.
Install Docker Engine, Docker Compose, curl, and an SSH server on a Linux host reachable from the deployment runner. Install the deployment script and Compose file below under /srv/languages. Give the deployment account access to those files and the Docker daemon. Docker access is privileged, so use a dedicated account and limit who can trigger its production job.
Save this as /srv/languages/compose.yml. Point your public HTTPS reverse proxy at 127.0.0.1:8080. This example serves the handbook frontend. To use its search API, also deploy the backend and attach both containers to the shared Docker network so Nginx can resolve backend:3001.
services:
web:
image: ${FRONTEND_IMAGE:?Set FRONTEND_IMAGE to the package digest reference}
ports:
- '127.0.0.1:8080:80'
restart: unless-stoppedSave the script as /srv/languages/deploy.sh and make it executable with chmod +x. Replace the package path with the same value used in the workflow. It accepts a digest, pulls that image before replacing the service, and records the digest only after the HTTP checks pass.
#!/usr/bin/env bash
set -euo pipefail
cd /srv/languages
digest=${1:-}
[[ "$digest" =~ ^sha256:[0-9a-f]{64}$ ]]
export FRONTEND_IMAGE="ghcr.io/example-owner/languages-frontend@$digest"
docker compose pull web
docker compose up -d --no-build --pull never web
curl --fail --silent --show-error --retry 5 --retry-connrefused \
http://127.0.0.1:8080/health
curl --fail --silent --show-error --output /dev/null \
http://127.0.0.1:8080/fr/git
printf '%s\n' "$digest" > deployed-digestsequenceDiagram
participant Build as Publish job
participant Registry as GHCR
participant Deploy as Deploy job
participant Host as Linux host
Build->>Registry: Push image
Registry-->>Build: Return image digest
Build-->>Deploy: Pass digest through job output
Deploy->>Host: Run deployment script over SSH
Host->>Registry: Pull image by digest
Host->>Host: Replace container and check HTTP
Host-->>Deploy: Return success or failureVerify, troubleshoot, and roll back
To reproduce CI, start from the repository root with Node.js 22 and pnpm 10.20.0 available. After building, open the Vite preview URL and navigate directly to a handbook in each language.
cd frontend
pnpm install --frozen-lockfile
pnpm run check:i18n
pnpm test
pnpm run build
pnpm run check:ssr-i18n
pnpm run previewAfter merging, open Actions, select the run for your commit, and expand the failed step if a job is red. A missing run usually calls for checking the workflow location, event, and branch filter. A package push denied by GHCR calls for checking token permissions and package access. A deployment waiting before its first step may require environment approval. An SSH failure calls for checking reachability, user, and host key.
After a successful run, open the public HTTPS URL and load a nested French route directly. Check that assets load and the canonical URL and sitemap point to the correct origin. The host script checks local HTTP. Public DNS, TLS, and proxy configuration need their own checks.
A failed smoke check can leave the new container running. Inspect docker compose logs using the attempted image reference, then rerun deploy.sh with the last known-good digest recorded in deployed-digest or in a previous successful release. Keep that image in GHCR. A source revert on main produces a new release and fixes the branch for subsequent deployments.
The command below restores the last successful release after a failed check. To undo a release that passed its checks, pass an earlier digest from the corresponding publish job instead. Before a manual rollback, check Actions for queued deployments that could replace the restored version.
cd /srv/languages
./deploy.sh "$(cat deployed-digest)"
curl --fail --silent --show-error https://handbooks.example.com/healthGitHub Pages for static projects
For a static-only project you can replace the registry and server with GitHub Pages. In Settings → Pages choose GitHub Actions as the source. Build the static output, upload it with actions/upload-pages-artifact, and publish it from a dependent job using actions/deploy-pages. The deploy job needs pages: write, id-token: write, and the github-pages environment.
A project site at owner.github.io/repository/ needs its assets and router to use the /repository/ base path. This frontend currently uses root-relative URLs and an Nginx proxy for /api. A GitHub Pages migration needs a base-path review and a separate backend for API features.
References
GitHub Actions workflow syntax