name: "CI Unit Tests & Efficacy"

on:
  push:
    branches:
      - main
  pull_request:
    paths:
      - 'naxsi_src/**'
      - 'unit-tests/**'
      - 'distros/**'

# Automatically cancel any previous workflow on new push.
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
  cancel-in-progress: true

jobs:
  build-sys:
    strategy:
      fail-fast: false
      matrix:
        container:
          - fedora:37
          - fedora:38
          - fedora:39
    name: libinjection-system ${{ matrix.container }}
    runs-on: ubuntu-latest
    container: ${{ matrix.container }}
    steps:
      - name: Checkout repository without submodule
        uses: actions/checkout@v4
      - name: Install system libinjection
        run: |
          sudo dnf -y install libinjection \
                              libinjection-devel \
                              pcre2-devel pcre2 \
                              zlib-devel zlib \
                              make automake gcc \
                              wget openssl
      - name: Build
        run: /bin/bash .scripts/ci-build.sh "1.25.1"


  build-test:
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest]
        nginx:
          - 1.27.0
          - 1.26.1
          - 1.25.1
          - 1.24.0
          - 1.23.4
          - 1.22.0
          - 1.21.5
          - 1.20.2
          - 1.18.0
          - 1.16.1
          - 1.14.2
    runs-on: ${{ matrix.os }}
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          submodules: recursive
          persist-credentials: false
      - name: Build
        run: /bin/bash .scripts/ci-build.sh "${{ matrix.nginx }}"
      - name: Unit Tests
        run: /bin/bash .scripts/ci-test.sh

  build-efficacy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          submodules: recursive
          persist-credentials: false
      - name: Build
        run: /bin/bash .scripts/ci-build.sh "1.25.1"
      - name: Run WAF efficacy tests (core only)
        run: /bin/bash .scripts/ci-wafefficacy.sh core
      - name: Run WAF efficacy tests (complete)
        run: /bin/bash .scripts/ci-wafefficacy.sh complete