GitHub Actions
Build pipelines as YAML workflows triggered by repository events, using jobs, reusable actions, secrets and OIDC to the cloud.
Intermediate · about 8 hours · difficulty 2/5
Learn first: Continuous Integration and Delivery
GitHub Actions is built into GitHub, free for public repositories and generous for private ones, which makes it the easiest first CI system to learn.
Building blocks
- Workflows are YAML files in
.github/workflows/, triggered by events such aspush,pull_request,schedule,workflow_dispatchorrelease. - Jobs run on runners (GitHub-hosted Linux, Windows or macOS, or self-hosted) and run in parallel unless linked with
needs. - Steps either
runshell commands orusesan action from the marketplace, such asactions/checkoutandactions/setup-node. - A matrix fans a job out across versions or operating systems.
- Caching (
actions/cacheor built-in setup caches) and artifacts pass files between jobs.
Secrets and cloud access
Store credentials as secrets and read them with ${{ secrets.NAME }}. Better still, use OIDC: the workflow requests a short-lived token and assumes a cloud role, so no long-lived keys exist at all. Scope the default GITHUB_TOKEN with permissions:.
Deployments
Environments add required reviewers, wait timers and environment-specific secrets. Concurrency groups stop two deploys of the same environment running together.
Reuse and hardening
- Reusable workflows (
workflow_call) and composite actions remove copy-paste across repos. - Pin third-party actions to a full commit SHA.
- Be careful with
pull_request_targetand untrusted input in scripts.
Good enough to move on: you can write a workflow that lints, tests across a matrix, builds and pushes an image, and deploys to a protected environment using OIDC with no stored cloud keys.
Key concepts
- Workflows, events and triggers
- Jobs, steps and runners
- Marketplace actions
- Matrix builds
- Caching and artifacts
- Secrets and OIDC to cloud
- Environments and approvals
- Reusable workflows and composite actions
- Self-hosted runners
Other options for this step
- GitLab CI/CD: Pipelines defined in .gitlab-ci.yml with stages, jobs, runners and environments, tightly integrated with GitLab's registry and security tools.
- Jenkins: The long-standing self-hosted automation server, with pipelines as code in Jenkinsfiles and a huge plugin ecosystem.
Mini project
Create a workflow for a containerised app: test on pull requests, build and push to a registry on main tagged with the commit SHA, then deploy to a staging environment and, after manual approval, to production using OIDC.
Check yourself
What does OIDC federation remove from your repository settings, and why is that a security win?
Free resources
- GitHub Actions documentation (GitHub)
- Security hardening for GitHub Actions (GitHub)