Skip to content

GitHub Actions essentials for production pipelines

Build a GitHub Actions workflow that runs the right jobs on the right events, caches dependencies, uses OIDC for cloud auth, and fails loudly when something drifts.

You’re picking up a repository whose .github/workflows/ directory has accumulated four YAML files written by three different people, none of them currently on the team. Tests run on every push to every branch, the deploy job uses a long-lived AWS access key stored as a secret from 2023, and nobody knows whether the green checkmark on main actually means the artifact was published. This article is the baseline a junior engineer needs to read the workflows, fix the obvious problems, and write a new one that will not embarrass anyone in six months.

How to verify

Look at the workflows that actually exist in the repo, what triggered the last few runs, and how long they ran:

ls -la .github/workflows/
gh workflow list
gh run list --limit 20 --json name,status,event,headBranch,createdAt,updatedAt
gh run view --log $(gh run list --limit 1 --json databaseId -q '.[0].databaseId')
gh secret list
gh variable list

If gh secret list shows entries with AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY, those are long-lived credentials and a candidate for OIDC migration.

What’s happening

A GitHub Actions workflow is a YAML file in .github/workflows/ that defines one or more jobs triggered by events — pushes, pull requests, schedules, manual dispatches, or webhook calls from other workflows. Each job runs on a runner (a fresh VM or container) and executes steps in order. The runner is ephemeral: nothing persists between jobs unless you upload an artifact, push a cache key, or write to an external system.

The three things that turn a “first day on the job” workflow into a production-grade one are: scoping triggers so you do not pay to run the full matrix on every doc-only commit, caching dependencies so jobs take seconds instead of minutes, and using OIDC to issue short-lived cloud credentials at job start instead of pasting a permanent key into the secret store.

The procedure

  1. Scope the trigger. Use paths-ignore for the documentation tree, branches to limit which branches trigger the full pipeline, and workflow_dispatch for manually-invoked variants. A common mistake is on: [push] which runs on every branch — explicit branch filters are cheaper and clearer.

    on:
      push:
        branches: [main]
        paths-ignore: ['docs/**', '**.md']
      pull_request:
        branches: [main]
      workflow_dispatch:
  2. Pin the runner and the actions. ubuntu-latest will quietly move to a new Ubuntu major version once a year and break something. Pin to ubuntu-24.04. For third-party actions, pin to a full SHA, not a tag — tags are mutable and have been hijacked. Dependabot will keep the SHAs current.

    jobs:
      test:
        runs-on: ubuntu-24.04
        steps:
          - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
  3. Cache the package manager. The official setup actions for Node, Python, Go, Java, and Ruby all accept a cache: input that handles this correctly. A bespoke actions/cache step is rarely necessary unless you are caching a build artifact directory.

    - uses: actions/setup-node@v4
      with:
        node-version: '20'
        cache: 'npm'
    - run: npm ci
  4. Wire OIDC for cloud auth. Add permissions: id-token: write at the workflow or job level, then use the cloud provider’s official action with role-to-assume. The runner exchanges a GitHub-signed JWT for short-lived credentials. The IAM role’s trust policy restricts which repo and which branch can assume it.

    permissions:
      id-token: write
      contents: read
    jobs:
      deploy:
        runs-on: ubuntu-24.04
        steps:
          - uses: aws-actions/configure-aws-credentials@v4
            with:
              role-to-assume: arn:aws:iam::123456789012:role/gha-deploy
              aws-region: us-east-1
  5. Set a concurrency group. Without one, two pushes in quick succession both run the deploy and race each other. cancel-in-progress: true is right for build/test; for deploys, leave it false so the second run queues instead of being killed mid-rollout.

    concurrency:
      group: deploy-${{ github.ref }}
      cancel-in-progress: false
  6. Fail loudly. Add a notify job that runs if: failure() and posts to Slack or PagerDuty when main breaks. A green dashboard with no alerts on failure means nobody notices when CI silently degrades.

Common pitfalls

  • pull_request_target runs with the base repo’s secrets and a malicious fork can read them — never use it without a strict permission audit.
  • secrets.GITHUB_TOKEN defaults to read-only for contents on new repos but read-write on older ones; set the workflow permissions: block explicitly.
  • Self-hosted runners on a flat network with pull_request triggered jobs are an arbitrary code execution surface for any contributor.
  • Matrix builds with fail-fast: false will continue running after one cell fails — useful for surfacing all failures, expensive on minutes.
  • The ${{ ... }} expression syntax is evaluated server-side and can interpolate untrusted PR titles or branch names directly into shell — always pass through env: first.

In the engagements we run, GitHub Actions is the default control plane for build, test, and deploy across client repos — pinned runners, OIDC for every cloud auth, concurrency on deploy jobs, and a single notification path that wakes the support desk when main breaks. See /en/services/managed-operations/ for how that fits into the broader operating model.