name: Node.js CI

on:
  pull_request:
    branches: [main]
  workflow_dispatch:

env:
  HUSKY: 0

permissions:
  contents: read

concurrency:
  group: nodejs-ci-${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        node-version: [22.x, 24.x, 26.x]

    steps:
    - uses: actions/checkout@v6
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v6
      with:
        node-version: ${{ matrix.node-version }}

    - run: npm ci
    - run: npm test
    - run: node_modules/nyc/bin/nyc.js report --reporter=lcovonly

    - name: Coveralls Parallel
      uses: coverallsapp/github-action@v2
      with:
        github-token: ${{ secrets.GITHUB_TOKEN }}
        flag-name: run-${{ matrix.node-version }}
        parallel: true

  finish:
    name: Node.js CI
    needs: build
    runs-on: ubuntu-latest
    steps:
    - name: Coveralls Finished
      uses: coverallsapp/github-action@v2
      with:
        github-token: ${{ secrets.GITHUB_TOKEN }}
        parallel-finished: true
