- uses: actions/checkout@v4Most build, test, and release workflows start with a checkout step.
Jobs, steps, matrix builds, conditional execution, reusable workflows, composite actions, and service containers in GitHub Actions.
Compose job logic cleanly and gate execution with expressions.
- uses: actions/checkout@v4Most build, test, and release workflows start with a checkout step.
- uses: actions/setup-node@v4
with:
node-version: 20Use official setup actions for language runtimes whenever possible.
- name: Publish
if: github.ref == 'refs/heads/main'
run: npm run publishConditionals help keep a single workflow flexible across branches and events.
jobs:
release:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latestUse job-level conditions when the whole job should be skipped.
- name: Optional audit
continue-on-error: true
run: npm auditUseful for advisory checks that should not fail the pipeline yet.
Scale workflows across versions, platforms, and reusable components.
Use a strategy matrix for version coverage.
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node: [18, 20, 22]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: npm ci
- run: npm testMatrix builds are the standard way to validate against multiple versions or OSes.
Validate portability across Linux, macOS, and Windows.
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}Great for CLI tools and cross-platform libraries.
Run integration tests against a database service.
services:
postgres:
image: postgres:16
env:
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 10s
--health-timeout 5s
--health-retries 5Service containers make it easy to run databases and dependent services inside CI.
Centralize shared CI logic in one workflow file.
jobs:
ci:
uses: my-org/my-repo/.github/workflows/reusable-ci.yml@main
with:
node-version: 20
secrets: inheritReusable workflows reduce duplication across repos and teams.
Bundle repeated shell steps into a reusable local action.
name: setup-project
runs:
using: "composite"
steps:
- run: npm ci
shell: bash
- run: npm run build
shell: bashComposite actions are useful for local step reuse without creating a full JavaScript or Docker action.