name: CI

on:
  - push
  - pull_request

permissions: {}

jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        arch:
          - x64
          - x86
        node:
          - 10
          - 12
          - 14
          - 16
          - 18
          - 19
        os:
          - macOS-latest
          - ubuntu-latest
          - windows-latest
        exclude:
          - arch: x86
            os: macOS-latest
          - arch: x86
            os: ubuntu-latest
          - arch: x86
            node: 18
            os: windows-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node }}
          architecture: ${{ matrix.arch }}
      - run: npm install
      - run: npm run lint
        if:
          matrix.os == 'ubuntu-latest' && matrix.node == 16 && matrix.arch ==
          'x64'
      - run: npm test
      - run: |
          id=$(node -e "console.log(crypto.randomBytes(16).toString('hex'))")

          echo "job_id=$id" >> $GITHUB_OUTPUT
        id: get_job_id
        shell: bash
      - uses: coverallsapp/github-action@1.1.3
        with:
          flag-name:
            ${{ steps.get_job_id.outputs.job_id }} (Node.js ${{ matrix.node }}
            ${{ matrix.arch }} on ${{ matrix.os }})
          github-token: ${{ secrets.GITHUB_TOKEN }}
          parallel: true
  coverage:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: coverallsapp/github-action@1.1.3
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          parallel-finished: true
