GitHub Actions and CI/CD
GitHub Actions runs YAML workflows from .github/workflows on events. Know how triggers and filters decide whether a run is created, how jobs, steps, outputs and matrices fit together, and how secrets, GITHUB_TOKEN permissions and runner choice shape security.
Key points
- 1
Triggers live under
on:. With bothbranchesandpathsset, both must match;pull_requestruns by default only foropened,synchronizeandreopened. - 2
Jobs run on separate fresh runners. Pass small values with step outputs (
$GITHUB_OUTPUT) mapped to joboutputs:, and files with artifacts. - 3
needs:jobs are skipped when a dependency fails unless you use a status function such asalways(),failure()or!cancelled(). - 4
Fork pull requests get no secrets and a read-only
GITHUB_TOKEN;pull_request_targethas secrets, so never run the PR's code in it. - 5
Set least-privilege
permissions:; listing any permission sets the rest tonone. Prefer OIDC (id-token: write) over long-lived cloud keys. - 6
Never interpolate untrusted context values like PR titles into
run:; pass them through environment variables. Pin third-party actions to a full commit SHA. - 7
actions/cachematcheskeyexactly thenrestore-keysby prefix, can't overwrite an existing cache, and only reads caches from the current, base and default branches.
Common traps
Events triggered with the repository
GITHUB_TOKEN(such as its pushes) don't start new workflow runs.With no
shell:key, bash runs withoutpipefail, so a failing command piped intoteecan let the step pass.A required check whose workflow is skipped by a paths filter stays Pending and blocks the merge.
Test yourself on GitHub Actions and CI/CD
Ten questions, with the answer and explanation after each one.