name: Test
on:
  push:
    branches:
      - '**'
  schedule:
    - cron: '0 0 * * MON'

concurrency:
  group: '${{ github.ref }}'
  cancel-in-progress: true

jobs:
  test:
    name: 'Test the npm package (Node.js ${{ matrix.nodejs }})'
    runs-on: ubuntu-24.04
    timeout-minutes: 5
    strategy:
      fail-fast: false
      matrix:
        nodejs: [25, 26]
    steps:
      - name: Prepare the environment
        uses: hausgold/actions/ci@v2
        with:
          clone_token: '${{ secrets.CLONE_TOKEN }}'
          settings_secret_key: '${{ secrets.SETTINGS_SECRET_KEY }}'
          settings: '${{ github.repository }}'
          target: ci/noop

      - name: Install system dependencies
        run: sudo apt-get update && sudo apt-get install -y
          poppler-utils imagemagick ghostscript

      - name: Install the correct Node.js version
        uses: actions/setup-node@v6
        with:
          node-version: ${{ matrix.nodejs }}
          cache: 'npm'

      - name: Install the npm package dependencies
        run: make install

      - name: Run the npm package tests
        run: make test

      - name: Upload the archive with debugging information
        uses: actions/upload-artifact@v7
        if: failure()
        with:
          name: 'pdfgen-${{ github.sha }}'
          path: test/tmp
          retention-days: 7

      - name: Generate statistics
        run: fe-stats

      - name: Upload the code coverage report
        run: coverage
