CI Pipeline GitHub Actions Matrix Build
Define a GitHub Actions CI pipeline with a Node version matrix, dependency caching, conditional deployment job, and pinned action versions.
Code
name: ci
on:
push: { branches: [main] }
pull_request: { branches: [main] }
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node: [20, 22]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: pnpm
- run: corepack enable
- run: pnpm install --frozen-lockfile
- run: pnpm lint
- run: pnpm test:unit
- run: pnpm test:e2e
continue-on-error: false
deploy:
needs: test
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
- run: pnpm build
- run: pnpm run deploy
env:
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}How the snippet works
The file declares a pipeline, not a program — 2 jobs break the work into isolated stages with 3 steps between them.
It runs on push, pull_request events, so every branch push and pull request gets the same checks.
A version matrix fans the job out across several toolchain versions, catching compatibility breaks a single-version run would miss.
Third-party actions in use: actions/checkout, actions/setup-node — each is pinned to a tag in the source.
7 steps drop to raw shell commands; the rest delegate to packaged actions.
Statements that matter
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
pull_request: { branches: [main] }
node-version: ${{ matrix.node }}
Interactive Tools for This Topic
Cron Expression ExplainerParse a five-field cron expression and get a field-by-field plain-English explanation plus a one-line human-readable schedule summary.Crontab Schedule GeneratorBuild standard 5-field cron expressions visually with field presets or custom ranges and preview the next 10 UTC and local execution timestamps.Git Conventional Commit BuilderBuild and validate Conventional Commits v1.0.0 messages with type, scope, breaking markers, 72-char subject counter, body, footers, and git CLI command.Glob Pattern TesterCompile glob patterns with *, **, ?, character classes, and braces into regex and test them against a list of candidate file paths.
FAQ
- What triggers this workflow?
- `push`, `pull_request` events, fanned out across the version matrix. Every matching push or pull request runs the same checks.
- Does this workflow depend on third-party actions?
- Yes — `actions/checkout`, `actions/setup-node`, each referenced at a pinned tag in the source. Review them before adopting the workflow in a repo with stricter supply-chain rules.
Report a problem with this exampleOpens a pre-filled issue on GitHub.