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.
- Check formatting and links.
- Build the production artefact.
- Upload the artefact to object storage.
- 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.
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:
| Stage | Input | Output |
|---|---|---|
| Validate | Repository | Pass/fail checks |
| Build | Source + content | public/ artefact |
| Publish | Verified artefact | S3 objects |
| Activate | Successful publish | CloudFront invalidation |
Figure 1: Keep validation, building and publication separate enough to reason about.
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.