# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
  push:
    branches: [ master, release-0.8.x ]
  pull_request:
    branches: [ master, release-0.8.x ]

permissions:
  contents: read

jobs:
  test:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version:
        - 14
        - 16
        - 18
        - 20
        - 22

    steps:
    - name: Harden Runner
      uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
      with:
        egress-policy: audit

    - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
      with:
        node-version: ${{ matrix.node-version }}
    - run: npm ci --no-audit
    - run: npm run test
      if: matrix.node-version != 18
    - run: npm run test -- --coverage
      if: matrix.node-version == 18
    - run: npm run fuzz
      if: matrix.node-version == 18
    - if: matrix.node-version == 18
      uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
      env:
        CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

  lint:

    runs-on: ubuntu-latest

    steps:
    - name: Harden Runner
      uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
      with:
        egress-policy: audit

    - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
    - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
      with:
        node-version-file: .node-version
    - run: npm ci --no-audit
    - run: npm run lint
    - run: npm run format:check
