GitHub Actions Recipes: The Practical Guide
Most GitHub Actions pain comes from the same handful of jobs done wrong. This is the map: the recipes that make pipelines fast, secure, and cheap.
Key takeaways
- Most GitHub Actions problems are fixed by a handful of recipes applied in order.
- Set a read-only top-level permissions block, cache dependencies, and use OIDC instead of stored cloud keys.
- Then add path filters, matrix builds, and reusable workflows as the repo grows, and pin third-party actions to a full commit SHA.
On this page
Fix most GitHub Actions problems with six recipes, in this order: a read-only top-level permissions: block, a dependency cache, OIDC instead of stored cloud keys, path filters, matrix builds, and reusable workflows. Pin every third-party action to a full commit SHA. This page is the map, and each recipe links to its full walkthrough.
Verified against
actions/checkout v7 (v7.0.1), actions/cache v6 (v6.1.0), against the docs.github.com workflow syntax, secure use, dependency caching and OpenID Connect pages. Checked October 2026.
GitHub Actions is easy to start with and easy to get subtly wrong. The result is pipelines that are slow, leak secrets, rebuild everything on every push, or quietly burn through your minutes budget. If you have never written a workflow, start with your first CI/CD pipeline with GitHub Actions and come back.
A workflow is just YAML describing jobs, steps, and triggers. The payoff is in the details: what you cache, how you scope permissions, and how much you run in parallel.
# .github/workflows/ci.yml
name: ci
on: [push, pull_request]
permissions:
contents: read # least privilege by default; widen per-job only when needed
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- run: npm ci && npm test
Making it fast
- Cache dependencies: the single biggest speedup, so CI stops re-downloading the same packages every run. Set up in caching dependencies in GitHub Actions, which pairs with the strategy in CI pipeline caching that pays off.
- Matrix builds: test across versions and OSes in parallel without copy-pasting jobs, covered in matrix builds that don't waste minutes.
- Speed up a slow pipeline: the full toolkit (parallelism, caching, path filters, bigger runners) is in how to speed up a slow CI pipeline. When minutes get expensive, self-hosted runners change the cost model.
Doing it securely
- Secrets: how to use repository and environment secrets without leaking them in logs or to forks, in using secrets in GitHub Actions safely.
- Keyless deploys: stop storing long-lived cloud keys in secrets and use OIDC to assume a role at runtime, walked through in keyless deploys to AWS via OIDC. The broader pattern is keyless cloud authentication.
- Pinning and hardening: a tag like
@v7is a pointer the action's owner can move. The fixes that matter after a supply-chain compromise are in GitHub Actions security hardening, and the newer lockfile approach is in GitHub Actions workflow lockfiles.
GitHub's secure-use guide says to pin actions to a commit SHA and to confirm the SHA comes from the action's own repository, not a fork. In practice that looks like this:
# .github/workflows/ci.yml (excerpt)
permissions:
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # only this job may request an OIDC token
steps:
- uses: actions/checkout@<full-40-char-sha> # v7.0.1
Keep the version in a trailing comment so humans and Dependabot can still tell what the SHA is.
Common jobs
- Build and push Docker images: buildx, layer caching, and multi-arch, in build and push Docker images in CI.
- Conditional jobs and path filters: only run the jobs that a change actually affects, in conditional jobs and path filters.
- Reusable workflows: stop copy-pasting the same YAML across dozens of repos, covered in reusable workflows at org scale.
The starter checklist
Run through this once for any new workflow. Each row is one recipe above, in the order it usually pays off:
| Recipe | Fixes | Effort |
|---|---|---|
Restrictive top-level permissions: | Over-privileged GITHUB_TOKEN | One line |
| Cache dependencies | Slow, repeated installs | A few lines |
| OIDC instead of static keys | Long-lived cloud secrets sitting in the repo | Moderate, one-time role setup |
| Path filters | Running the whole suite for a docs-only change | A few lines |
| Matrix builds | Copy-pasted jobs per version/OS | Moderate |
| Reusable workflows | The same YAML duplicated across repos | Larger, pays off at scale |
Where these recipes break
Caching is not free correctness: a cache key that ignores the lockfile hash restores stale dependencies, and the build passes on code that would fail from a clean install. Hash the lockfile into the key, every time. Path filters can skip a job that a required status check expects, which leaves pull requests waiting on a check that never runs; mark those checks carefully or use a job that always reports. OIDC trust policies that match too loosely on the sub claim let any branch, or any repo in the org, assume your deploy role. Scope the trust to the repository and the environment, not just the organization.
The mental model
Every workflow improvement falls into one of three buckets: faster (cache, parallelize, skip unaffected jobs), safer (least-privilege permissions, scoped secrets, OIDC instead of static keys), or cheaper (fewer wasted minutes, right-sized runners). Set a restrictive permissions: block at the top, cache aggressively, and pin third-party actions to a commit SHA, and most problems never appear. Picking the platform itself is a separate decision, compared in best CI/CD platforms.
Questions people ask
What permissions should a GitHub Actions workflow have by default?
Start with contents: read at the top of the workflow and nothing else. GitHub's secure-use guide recommends granting the GITHUB_TOKEN the minimum required permissions, read-only on repository contents by default, then raising them per job only where needed. A deploy job might add id-token: write for OIDC; a release job might add contents: write. Never grant write at the workflow level.
Should I pin GitHub Actions to a tag or a commit SHA?
Pin to the full commit SHA. A tag such as @v7 can be moved by whoever controls the action's repository, so a compromised maintainer account changes what your pipeline runs without any change in your repo. A SHA is immutable. Keep the version in a comment next to it and let Dependabot propose updates. GitHub's docs also describe lockfiles, which record exact commits for every dependency.
What is the fastest way to speed up a slow GitHub Actions workflow?
Cache dependencies first. Re-downloading packages on every run is usually the largest avoidable cost, and the cache takes a few lines with actions/cache or the built-in cache option of a setup action. After that, skip unaffected jobs with path filters, split slow test suites with a matrix, and only then consider bigger or self-hosted runners.
The call we'd make
Start every workflow from least-privilege permissions and a dependency cache, because those two lines fix the most common security and speed problems at once. Add OIDC before you ever paste a cloud key into a secret, and pin third-party actions by SHA from day one. Then reach for matrix builds, path filters, and reusable workflows as the repo grows. Each linked recipe is a focused fix; adopt them in that order and a GitHub Actions setup stays fast, secure, and cheap as it scales.
Sources
Cite this article
Kiril Urbonas (2026). GitHub Actions Recipes: The Practical Guide. DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/github-actions-recipes
[GitHub Actions Recipes: The Practical Guide](https://www.devopsness.com/blog/github-actions-recipes) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)
More from DevOps
Explore more articles in this category
kaniko CVE-2026-105769: Lookalike ACR Hosts Get Your Azure Token. Rebuild on v1.25.20
A FROM line pointing at a host like x.azurecr.io.attacker.com is enough to make kaniko hand the build's Entra ID token to that host. Which kaniko forks and images are affected, how to find Azure identities in your build pods, and what to rotate.
Sign Container Images With Cosign: Keyless GitHub Actions Workflow, SBOM and In-Cluster Checks
One workflow that builds, signs keylessly with GitHub OIDC, attaches an SBOM and SLSA provenance, plus the Kyverno policy that refuses anything unsigned. Copy it, change three names, ship it.
GitLab CVE-2026-110264: A Second CVSS 10 RCE in Nine Days. Patch to 19.5.1
An unauthenticated regex-compiler RCE reaching back to GitLab 7.0, no workaround, and backports on older branches that fix only the critical bug. The exact version per branch and the commands to get there.
You might have missed
Evergreen posts worth revisiting.