# 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@05e31511f85b41b11d1cf0ef85d0992719546e2c # v2.21.0
      with:
        egress-policy: audit

    - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.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@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v6.0.2
      env:
        CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

  lint:

    runs-on: ubuntu-latest

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

    - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
    - uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0
      with:
        node-version-file: .node-version
    - run: npm ci --no-audit
    - run: npm run lint
    - run: npm run format:check
