Linux / Security

Building a sensible GitHub Actions deployment pipeline

A deployment pipeline with useful checks, short-lived credentials and a deliberate release boundary.

A useful deployment pipeline should be boring in the best possible way. It should catch mistakes early, explain what it is doing, and make the release step easy to inspect.

A pipeline is not safer merely because it contains more jobs. Each job should establish a fact that someone actually needs before deployment.

Start with a clear boundary

The workflow has three stages: validate the source, build the release artifact, and publish only after the build succeeds. Keep the deployment credentials out of the ordinary test job.

  1. Check formatting and links.
  2. Build the production artefact.
  3. Upload the artefact to object storage.
  4. Invalidate the CDN only after publication succeeds.

A small Bash helper

#!/usr/bin/env bash
set -euo pipefail

artifact_dir="${1:-public}"
test -f "$artifact_dir/index.html"
find "$artifact_dir" -type f -print0 \
  | xargs -0 -n1 --no-run-if-empty echo "validated:"

Inline commands such as hugo --minify should be easy to distinguish from prose, even on a phone.

Note Prefer the immutable commit SHA as the release identifier. Branch names move; commits do not.

Inspect the generated plan

The same checks can be represented in Python when a shell-only test becomes difficult to maintain.

from pathlib import Path

site = Path("public")
required = {"index.html", "index.xml", "sitemap.xml"}
missing = [name for name in required if not (site / name).is_file()]

if missing:
    raise SystemExit(f"Missing generated files: {missing}")

The release plan is small enough to review:

StageInputOutput
ValidateRepositoryPass/fail checks
BuildSource + contentpublic/ artefact
PublishVerified artefactS3 objects
ActivateSuccessful publishCloudFront invalidation

A simple path from source to a published site Figure 1: Keep validation, building and publication separate enough to reason about.

Warning Never place a long-lived cloud access key in a pull request workflow. Use workload identity and constrain the trust relationship to the deployment environment.

What comes next

The next improvement is not another deployment step. It is a small, reliable rollback test and a link checker that can be run locally before a push. See the Hugo documentation for the available build controls.