GitHub Actions
GitHub’s event-driven automation platform for running build, test, release, and repository workflows from YAML files.
Why it exists.
It solves the gap between a code change and its verification or delivery by running automation directly from repository events.
Where it shines.
Teams already working in GitHub that want fast, composable CI/CD with pull-request checks and reusable workflow actions.
Where not to use it.
Do not use it as the only orchestration layer for workloads that need long-running infrastructure control, or when your source code lives elsewhere.
What it is made of.
- Workflow YAML
- Events and triggers
- Jobs and steps
- Hosted or self-hosted runners
- Actions and secrets
How it works.
- A repository event triggers a workflow
- GitHub creates jobs from the YAML graph
- Runners execute actions and steps
- Checks, artifacts, and deployments are reported back
What makes up GitHub Actions.
- Workflow
- YAML automation stored in .github/workflows. A repository can contain several workflows.
- Event
- A trigger such as push, pull_request, workflow_dispatch, or schedule.
- Job
- An execution unit containing steps, or a call to a reusable workflow.
- Step
- A task inside a job: run executes shell commands; uses invokes an action.
- Action
- Reusable functionality implemented as JavaScript, a Docker container, or a composite of steps.
- Runner
- A machine executing a job: GitHub-hosted or self-hosted.
- Environment
- A deployment target with optional protection rules and scoped configuration.
- Artifact
- A stored build output or report that can be downloaded or passed between jobs.
Read workflow YAML with confidence.
- Workflow run / attempt
- One execution of a workflow; rerunning creates another attempt.
- Job ID / step ID
- Identifiers used to reference dependencies and outputs; name is a display label.
- Context
- Structured runtime data: github, runner, needs, steps, matrix, inputs, secrets, vars, and env.
- Expression
- An evaluated value or condition, commonly written as ${{ ... }}.
- needs
- Declares prerequisite jobs and exposes their results and outputs.
- Matrix
- Expands a job into combinations such as operating systems and language versions.
- Output
- A named value; steps write to GITHUB_OUTPUT and jobs can expose it to downstream jobs.
- Secret / variable
- secrets holds sensitive values; vars holds non-sensitive configuration. env supplies environment variables.
- GITHUB_TOKEN
- A GitHub-issued token for a job, constrained by configured permissions.
- OIDC
- Federated identity for obtaining short-lived cloud credentials without storing a cloud access key.
- Concurrency
- Groups runs or jobs to limit overlapping execution; optionally cancels older work.
- Cache / artifact
- A cache accelerates dependency reuse; an artifact preserves outputs and reports.
- Reusable workflow / composite action
- A reusable workflow shares jobs via workflow_call; a composite action shares steps within a job.
From event to result.
- EventA push, pull request, manual request, or schedule matches the workflow trigger.
- Workflow graphGitHub evaluates conditions and dependencies, and expands matrix jobs.
- Runner assignmentEligible jobs are queued for matching runners.
- StepsThe runner executes commands and actions, collecting logs and results.
- ResultsJob status, outputs, artifacts, and deployment records become available.
Runner boundaries.
Standard GitHub-hosted VM jobs get fresh machines. Self-hosted runners may retain state. Never assume files from one job exist in another; explicitly transfer artifacts or outputs.
Dependency graph.
Independent jobs can run together. needs waits for prerequisites; steps normally run in order. A build job can wait for every test matrix execution.
A matrix followed by a build.
Save as .github/workflows/ci.yml in a Node project with package-lock.json and test/build scripts. Two test jobs run before build. Each job checks out code and installs dependencies separately.
name: Node CI
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
node: [22, 24]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: npm
- run: npm ci
- run: npm test
build:
needs: test
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
cache: npm
- run: npm ci
- run: npm run buildMajor action tags keep this learning example readable. For production, replace each tag with a reviewed full commit SHA and keep it updated. Adapt Node versions and scripts to your project.
Types of jobs and when to use them.
These patterns can overlap: a matrix job can also use a container. Build, test, scan, and deploy describe a job’s purpose.
| Pattern | Behavior | Example |
|---|---|---|
| Independent / parallel | Jobs without needs may run concurrently when runners are available. | Separate lint and unit-test jobs. |
| Dependent / sequential | needs creates an execution graph; failed or skipped prerequisites normally skip dependents. | Build → test → deploy. |
| Matrix | strategy.matrix creates multiple job executions with varied inputs. | Test Node 22 and 24. |
| Conditional | if controls whether a job runs. | Deploy only on a push to main. |
| Container | container runs job steps in a selected image on a Linux runner. | Run CI inside node:24-bookworm. |
| Service-backed | services starts companion containers on a Linux runner; this is a job configuration pattern. | Integration tests with PostgreSQL. |
| Reusable workflow call | Job-level uses calls another workflow instead of declaring local steps. | uses: ./.github/workflows/reusable-ci.yml |
| Deployment | environment associates a job with a deployment target and applicable protection rules. | Deploy to production after approval. |
| Cleanup / reporting | A condition allows reporting after dependencies finish, including failures. | needs: [test] with if: always() for a bounded report. |
Limit access and trust.
- Start with contents: read; grant additional token permissions only to jobs that need them.
- Pin actions and external reusable workflows to reviewed full commit SHAs. Use automated update PRs.
- Use OIDC for short-lived cloud credentials and restrict its trust policy.
- Keep secrets out of logs and artifacts; masking is not a security boundary.
- Never execute untrusted PR code in privileged pull_request_target workflows.
- Pass untrusted event text through quoted environment variables instead of interpolating it into shell scripts.
- Isolate self-hosted runners from untrusted workloads.
Make failures useful.
- Use lockfiles and reproducible installation commands.
- Set explicit job timeouts; keep lint, tests, and deployment separately visible.
- Require CI checks before merging; keep required check names stable.
- Publish test reports and build artifacts with deliberate retention.
- Use protected environments for production deployment.
Run the work that matters.
- Cache dependencies using OS and lockfile-aware keys.
- Cancel superseded CI runs with concurrency; avoid interrupting production deployments blindly.
- Keep matrices focused and cap parallelism when resources are limited.
- Use event and path filters carefully: skipped required workflows can leave checks pending.
Keep workflows reviewable.
- Give workflows, jobs, and steps meaningful names.
- Share repeated jobs with reusable workflows and repeated steps with composite actions.
- Pass explicit inputs, outputs, and secrets across reuse boundaries.
- Review .github/workflows changes as executable code.