# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Main Workflow
on: [push, pull_request]

jobs:
  code_style:
    name: Code Style Analysis
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.13"
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -e .
          pip install "pylint==4.0.6"
      - name: Pylint
        run: |
          pylint --rcfile=.pylintrc wapitiCore

  docker:
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@v4
      - name: Set up Docker
        uses: docker/setup-buildx-action@v3
        id: buildx
        with:
          install: true
      - name: Build
        run: |
          docker build -f Dockerfile .

  build:
    runs-on: ubuntu-24.04
    strategy:
      matrix:
        python-version: ["3.12", "3.13", "3.14"]
    steps:
    - uses: actions/checkout@v4
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v5
      with:
        python-version: ${{ matrix.python-version }}
    - name: Display Python version
      run: python -c "import sys; print(sys.version)"
    - name: Install dependencies
      run: |
        sudo apt-get update
        sudo apt-get install -y software-properties-common
        sudo add-apt-repository ppa:ondrej/php -y
        sudo apt-get update
        sudo apt-get install php8.4-cli php8.4-xml sslscan -y --no-install-recommends
        python -m pip install --upgrade pip
        pip install -U setuptools
        pip3 install .[test] && playwright install firefox --with-deps
    - name: Test project
      run: |
        pytest
    - name: Upload coverage to Codecov
      uses: codecov/codecov-action@v4
      with:
        token: ${{ secrets.CODECOV_TOKEN }}

  integrate:
    runs-on: ubuntu-24.04
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Run Docker Compose
        run: bash ${GITHUB_WORKSPACE}/tests/integration/run.sh

      - name: Archive production artifact
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: diff-reports-file
          path: tests/integration/.dump_diff_file.txt

      - name: Archive production artifact
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: produced-reports
          path: tests/integration/.test/*
