GitHub Actions 1 cheatsheet
GitHub Actions 1: Jobs, matrices and conditions
7 common GitHub Actions 1 tasks.
Test across versions
Run the same job once per Node.js version and operating system.
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node: [22, 24]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
Run a step conditionally
Run a step only on the main branch.
- run: ./deploy.sh
if: github.ref == 'refs/heads/main'
Run a step after a failure
Run cleanup or notifications when an earlier step failed.
- run: ./notify.sh
if: failure()
Cancel outdated runs
Cancel an in-progress run when a newer one starts for the same branch.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
Start a database for tests
Run a PostgreSQL container next to the job.
services:
postgres:
image: postgres:18
env:
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-retries 5
Pass data between jobs
Expose a step's output as a job output that later jobs can read.
jobs:
build:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.ver.outputs.version }}
steps:
- id: ver
run: echo "version=1.2.3" >> "$GITHUB_OUTPUT"
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- run: echo "Deploying ${{ needs.build.outputs.version }}"