name: Test Coverage

on:
  push:
    branches:
      - master
  pull_request:
  workflow_dispatch:

permissions:
  contents: read

jobs:
  test:
    name: Test (${{ matrix.os }})
    strategy:
      fail-fast: false
      matrix:
        os:
          - ubuntu-latest
          - windows-latest
          - macos-latest
    
    runs-on: ${{ matrix.os }}
    
    steps:
      - name: Checkout
        uses: actions/checkout@v7
        with:
          fetch-depth: 0
          fetch-tags: true
          ref: ${{ github.ref }}
      
      - name: Setup pnpm
        uses: pnpm/action-setup@v6
        with:
          version: 11
      
      - name: Setup Node.js
        uses: actions/setup-node@v7
        with:
          node-version: 24
          registry-url: https://registry.npmjs.org/
          package-manager-cache: false
      
      - name: Configure Git
        run: |
          git config --global user.name "github-actions[bot]"
          git config --global user.email "github-actions[bot]@users.noreply.github.com"
      
      - name: Install deps
        run: pnpm install --frozen-lockfile
      
      - name: Build
        run: pnpm build
      
      - name: Test
        run: pnpm test:cov
      
      - name: Coverage (Report - ${{ matrix.os }})
        uses: coverallsapp/github-action@v2
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          flag-name: ${{ matrix.os }}
          parallel: true
          fail-on-error: false
  
  finish:
    name: Finish
    if: always()
    needs: test
    runs-on: ubuntu-latest
    
    steps:
      - name: Finish Coveralls
        uses: coverallsapp/github-action@v2
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          parallel-finished: true
