name: CI

on:
  push:
    branches:
      - main
      - master
  pull_request: {}

concurrency:
  group: ci-${{ github.head_ref || github.ref }}
  cancel-in-progress: true

jobs:
  lint:
    name: "Lint"
    runs-on: ubuntu-latest
    timeout-minutes: 10

    steps:
      - uses: actions/checkout@v6
      - uses: pnpm/action-setup@v4
      - uses: actions/setup-node@v6
        with:
          node-version: 24
          cache: pnpm
      - run: pnpm install
      - run: pnpm run lint

  test:
    name: "Test"
    runs-on: ubuntu-latest
    timeout-minutes: 5
    strategy:
      fail-fast: false
      matrix:
        node-version:
          - 18
          - 20
          - 22
          - 24

    steps:
      - uses: actions/checkout@v6
      - uses: pnpm/action-setup@v4
      - uses: actions/setup-node@v6
        with:
          node-version: ${{ matrix.node-version }}
          cache: pnpm
      - run: pnpm install
      - run: pnpm test

  legacy-node-test:
    name: "Legacy Node Test"
    runs-on: ubuntu-latest
    timeout-minutes: 5
    strategy:
      fail-fast: false
      matrix:
        node-version:
          - 6
          - 8
          - 10
          - 12
          - 14
          - 16

    steps:
      - uses: actions/checkout@v6
      # prevent yarn from complaining about the packageManager key in the package.json
      - run: cat package.json | jq ".packageManager = \"yarn@1.22.22\"" | tee package.json
      - uses: actions/setup-node@v6
        with:
          node-version: ${{ matrix.node-version }}
          cache: yarn
      - run: yarn install --frozen-lockfile --ignore-engines
      - run: yarn test

  windows-test:
    name: "Windows smoke test"
    runs-on: windows-latest
    timeout-minutes: 5

    steps:
      - uses: actions/checkout@v6
      - uses: pnpm/action-setup@v4
      - uses: actions/setup-node@v6
        with:
          node-version: 24
          cache: pnpm
      - run: pnpm install
      - run: pnpm test