name: Automated Testing

on:
  push:
    branches: [main]
  pull_request:
  workflow_dispatch:

jobs:
  code-hygiene:
    name: Code Hygiene
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with: { persist-credentials: false }
      - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
        with:
          node-version-file: '.nvmrc'
      - run: npm ci
      - run: npm run lint
        if: success() || failure()
      - run: npm run build
        if: success() || failure()
      - run: npm run typecheck
        if: success() || failure()
  unit-and-integration-tests:
    name: Unit and Integration Tests
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with: { persist-credentials: false }
      - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
        with:
          node-version-file: '.nvmrc'
      - run: npm ci
      - run: npm run test-unit-ci
      - run: npm run test-integration-ci
      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
        with:
          files: ${{ github.workspace }}/coverage/vitest/unit/coverage-final.json, ${{ github.workspace }}/coverage/vitest/integration/coverage-final.json
          verbose: true
          token: ${{ secrets.CODECOV_TOKEN }}

  packaging-tests:
    name: Packaging and Build tests
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with: { persist-credentials: false }
      - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
        with:
          node-version-file: '.nvmrc'
      - run: npm ci
      - run: npm run build
      - run: npm run test-build-ci
      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
        with:
          files: ${{ github.workspace }}/coverage/vitest/build/coverage-final.json
          verbose: true
          token: ${{ secrets.CODECOV_TOKEN }}
