name: "Linters"

on:
  push:
    branches:
      - main
  pull_request:

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

jobs:
  no-debug:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@v4
    - name: Check debug logs are disabled
      run: /bin/bash .scripts/ci-debug-check.sh

  distro-ci-check:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@v4
      with:
        submodules: recursive
        persist-credentials: false
    - name: Check if the distro info are updated
      run: /bin/bash .scripts/ci-distro-check.sh

  licenses:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@v4
    - name: Reuse Compliance Check
      uses: fsfe/reuse-action@v5
      with:
        args: --suppress-deprecation lint


  formatting:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@v4
    - name: Install wget, software-properties-common, lsb-release (dependencies of LLVM install script)
      run: sudo apt --assume-yes install wget software-properties-common lsb-release
    - name: Install automatic LLVM 16
      run: wget https://apt.llvm.org/llvm.sh -O /tmp/llvm-install.sh; chmod +x /tmp/llvm-install.sh; sudo /tmp/llvm-install.sh 16
    - name: Install clang-format-16
      run: sudo apt --assume-yes install clang-format-16
    - name: Format check
      run: find naxsi_src/ -type f -name "*.c" -o -name "*.h" | grep -v "libinjection" | xargs -I % clang-format --verbose --Werror --dry-run %

  rules:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@v4
    - name: Install python3
      run: sudo apt --assume-yes install python3
    - name: Format check rules
      run: |
        bash .scripts/ci-rules-linter.sh naxsi_rules/blocking
        bash .scripts/ci-rules-linter.sh naxsi_rules/whitelists
