Skip to content

GitHub Actions

v2024

GitHub Actions is an event-driven automation platform. A repository event triggers a workflow, which orchestrates one or more jobs. Jobs run in parallel by default on fresh virtual machines, and each job executes a sequence of individual steps that can run shell commands or reusable actions.

KeyPurpose
nameThe workflow name shown in the UI
onThe event(s) that trigger the workflow
jobsThe container for all workflow jobs

A workflow is defined by a YAML file in the .github/workflows/ directory. It requires an event trigger and at least one job containing steps.

name: Build
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm install

Note: Paths are relative to the repository root unless you specify a different working directory.

EventTrigger condition
pushCode is pushed to a branch or tag
pull_requestA PR is opened or updated
workflow_dispatchManual trigger via UI or API

Workflows run when specific GitHub events occur. You can restrict triggers to specific branches, tags, or file paths to prevent unnecessary runs.

on:
push:
branches: [main]
paths: ["src/**"]
workflow_dispatch:

Gotcha: The pull_request event runs on the merge commit of the PR, not the exact branch head.

KeywordPurpose
needsRequire another job to finish first
ifRun conditionally on expressions

Jobs run in parallel across separate runners by default. You string them together sequentially using the needs keyword, ensuring dependent jobs only run if their prerequisites succeed.

jobs:
test:
runs-on: ubuntu-latest
deploy:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'

Tip: Use needs: [job1, job2] to wait for multiple jobs before proceeding.

KeyPurpose
matrixDefine multiple job configurations
includeAdd specific combinations
fail-fastCancel all jobs if one fails

A matrix strategy lets you run the same job multiple times with different variable combinations. It is ideal for testing across multiple operating systems or language versions concurrently.

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node: [18, 20]
steps:
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
ScopeUsage
Repository${{ secrets.MY_SECRET }}
Environment${{ vars.MY_VAR }}

Variables and secrets provide values to your workflows dynamically. Secrets are encrypted and masked in logs, while variables are plaintext. Both can be scoped to the repository, organization, or specific environments.

steps:
- run: npm run deploy
env:
API_KEY: ${{ secrets.PROD_API_KEY }}
NODE_ENV: ${{ vars.ENV_NAME }}

Warning: Never pass secrets directly into run scripts using expression syntax, as it exposes them to command injection.

ContextContains
githubWorkflow run and repo details
runnerCurrent runner environment
envEnvironment variables

Expressions allow you to programmatically evaluate conditions and access contexts. They are enclosed in ${{ }} syntax and can use built-in functions like contains() or always().

steps:
- run: echo "Branch is ${{ github.ref }}"
- if: failure()
run: echo "A previous step failed."

Gotcha: You can only use the env context in specific places, like the with or if keys of a step.

Verified 2026-07-30 against GitHub Actions Documentation