name: "Hapi Bookshelf Serializer CI"

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

jobs:
  ci:
    name: Build & Test
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [20, 22, 24]

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Use Node ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}

      - name: Upgrade npm to v11
        run: npm install -g npm@11

      - name: Install dependencies
        run: npm install

      - name: Run linter
        run: npm run lint

      - name: Run tests
        run: npm run test

      # Run tests in a container. Gives us better test coverage by covering the in-container and non-container code paths
      - name: Run container tests
        run: |
          docker run -t -w /logger-node -v ${{ github.workspace }}:/logger-node node:${{ matrix.node-version }} /bin/sh -c 'npm install && npm run test'

      - name: Enforce coverage
        run: npm run enforce

      - name: Compress coverage directory
        run: test -d coverage && tar czvf coverage.tar.gz coverage

      - name: Archive code coverage results
        uses: actions/upload-artifact@v4
        with:
          name: code-coverage-report-node-v${{ matrix.node-version }}
          path: coverage.tar.gz
