on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
  merge_group:

jobs:
  test:
    if: github.ref != 'refs/heads/master'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
      - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
        with:
          node-version: '22.x'
      - run: yarn install --frozen-lockfile
      - run: yarn test --ci
  lint:
    if: github.ref != 'refs/heads/master'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
      - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
        with:
          node-version: '22.x'
      - run: yarn install --frozen-lockfile
      - run: yarn lint

  checks:
    if: ${{ always() && github.ref != 'refs/heads/master' }}
    needs: [ test, lint ]
    timeout-minutes: 5
    runs-on: ubuntu-latest
    steps:
      - name: Fail if any required job failed or was cancelled
        if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
        run: exit 1
