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 as push, pull_request, schedule, workflow_dispatch or release.
  • Jobs run on runners (GitHub-hosted Linux, Windows or macOS, or self-hosted) and run in parallel unless linked with needs.
  • Steps either run shell commands or uses an action from the marketplace, such as actions/checkout and actions/setup-node.
  • A matrix fans a job out across versions or operating systems.
  • Caching (actions/cache or 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_target and 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