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.

JavascriptCli Tooling

Code

javascriptsnippet
37 lines
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

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.