Skip to main content
GitHub Actions Recipes: The Practical Guide

GitHub Actions Recipes: The Practical Guide

KU
· Founder & Chief Editor
• 6 min read•Updated •31 views

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.

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.

YAML
# .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

Doing it securely

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:

YAML
# .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

The starter checklist

Run through this once for any new workflow. Each row is one recipe above, in the order it usually pays off:

RecipeFixesEffort
Restrictive top-level permissions:Over-privileged GITHUB_TOKENOne line
Cache dependenciesSlow, repeated installsA few lines
OIDC instead of static keysLong-lived cloud secrets sitting in the repoModerate, one-time role setup
Path filtersRunning the whole suite for a docs-only changeA few lines
Matrix buildsCopy-pasted jobs per version/OSModerate
Reusable workflowsThe same YAML duplicated across reposLarger, 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

React
Share this post
Cite this article
Plain text

Kiril Urbonas (2026). GitHub Actions Recipes: The Practical Guide. DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/github-actions-recipes

Markdown

[GitHub Actions Recipes: The Practical Guide](https://www.devopsness.com/blog/github-actions-recipes) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)

KU

Kiril Urbonas

Founder & Chief Editor

586 articles
View all articles by Kiril Urbonas

You might have missed

Evergreen posts worth revisiting.