name: Coverage Windows

on:
  pull_request:
    types: [opened, synchronize, reopened, ready_for_review]
    paths:
      - lib/**/*.js
      - Makefile
      - src/**/*.cc
      - src/**/*.h
      - test/**
      - tools/gyp/**
      - tools/test.py
      - .github/workflows/coverage-windows.yml
  push:
    branches:
      - main
    paths:
      - lib/**/*.js
      - Makefile
      - src/**/*.cc
      - src/**/*.h
      - test/**
      - tools/gyp/**
      - tools/test.py
      - .github/workflows/coverage-windows.yml

concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  cancel-in-progress: true

env:
  PYTHON_VERSION: '3.12'
  FLAKY_TESTS: keep_retrying

permissions:
  contents: read

jobs:
  coverage-windows:
    if: github.event.pull_request.draft == false
    runs-on: windows-2022
    steps:
      - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b  # v4.1.4
        with:
          persist-credentials: false
      - name: Set up Python ${{ env.PYTHON_VERSION }}
        uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d  # v5.1.0
        with:
          python-version: ${{ env.PYTHON_VERSION }}
      - name: Install deps
        run: choco install nasm
      - name: Environment Information
        run: npx envinfo
      - name: Build
        run: ./vcbuild.bat
      # TODO(bcoe): investigate tests that fail with coverage enabled
      # on Windows.
      - name: Test
        run: ./vcbuild.bat test-ci-js; node -e 'process.exit(0)'
        env:
          NODE_V8_COVERAGE: ./coverage/tmp
      - name: Report
        run: npx c8 report
        env:
          NODE_OPTIONS: --max-old-space-size=8192
      - name: Clean tmp
        run: npx rimraf ./coverage/tmp
      - name: Upload
        uses: codecov/codecov-action@5ecb98a3c6b747ed38dc09f787459979aebb39be  # v4.3.1
        with:
          directory: ./coverage
          token: ${{ secrets.CODECOV_TOKEN }}