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
-
Scope the trigger. Use
paths-ignorefor the documentation tree,branchesto limit which branches trigger the full pipeline, andworkflow_dispatchfor manually-invoked variants. A common mistake ison: [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: -
Pin the runner and the actions.
ubuntu-latestwill quietly move to a new Ubuntu major version once a year and break something. Pin toubuntu-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 -
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 bespokeactions/cachestep 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 -
Wire OIDC for cloud auth. Add
permissions: id-token: writeat the workflow or job level, then use the cloud provider’s official action withrole-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 -
Set a concurrency group. Without one, two pushes in quick succession both run the deploy and race each other.
cancel-in-progress: trueis right for build/test; for deploys, leave itfalseso the second run queues instead of being killed mid-rollout.concurrency: group: deploy-${{ github.ref }} cancel-in-progress: false -
Fail loudly. Add a
notifyjob that runsif: failure()and posts to Slack or PagerDuty whenmainbreaks. A green dashboard with no alerts on failure means nobody notices when CI silently degrades.
Common pitfalls
pull_request_targetruns with the base repo’s secrets and a malicious fork can read them — never use it without a strict permission audit.secrets.GITHUB_TOKENdefaults to read-only forcontentson new repos but read-write on older ones; set the workflowpermissions:block explicitly.- Self-hosted runners on a flat network with
pull_requesttriggered jobs are an arbitrary code execution surface for any contributor. - Matrix builds with
fail-fast: falsewill 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 throughenv: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.