name: Node.js CI

on:
  push:
    tags:
      - '*'
  pull_request:
  workflow_dispatch:

jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        node-version: [18.x, 20.x, 21.x, 22.x, 23.x]

    steps:
      - name: Setup Git
        if: matrix.os == 'windows-latest'
        run: |
          git config --global core.autocrlf false
          git config --global core.eol lf

      - name: Checkout code
        uses: actions/checkout@v4

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}

      - name: Install dependencies
        run: npm ci

      - name: Run tests
        if: matrix.os == 'windows-latest'
        run: $env:NODE_OPTIONS = "--openssl-legacy-provider"; npm test

      - name: Run tests
        if: matrix.os != 'windows-latest'
        run: export NODE_OPTIONS=--openssl-legacy-provider && npm test
