on:
  workflow_dispatch:
  push:
    branches:
      - develop
    tags:
      - "[0-9]+.[0-9]+.[0-9]+"
      - "[0-9]+.[0-9]+.[0-9]+rc[0-9]+"
  pull_request:
    branches:
      - develop

jobs:
  build:
    name: "Build mod_wsgi packages"
    runs-on: "ubuntu-20.04"
    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13-dev"]
    steps:
      - uses: "actions/checkout@v4"
      - uses: "actions/setup-python@v5"
        with:
          python-version: "${{ matrix.python-version }}"
      - name: "Update package details"
        run: sudo apt --fix-missing update
      - name: "Install Apache package"
        run: sudo apt install -y apache2-dev
      - name: "Build mod_wsgi packages"
        run: ./package.sh && ls -las dist
      - name: "Store built packages"
        uses: "actions/upload-artifact@v4"
        with:
          name: dist ${{ matrix.python-version }}
          path: dist/*

  tests:
    name: "Test mod_wsgi package (Python ${{ matrix.python-version }})"
    runs-on: "ubuntu-20.04"
    needs:
    - build
    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13-dev"]
    steps:
      - uses: "actions/checkout@v4"
      - uses: "actions/setup-python@v5"
        with:
          python-version: "${{ matrix.python-version }}"
      - name: "Download built packages"
        uses: "actions/download-artifact@v4"
        with:
            name: dist ${{ matrix.python-version }}
            path: dist
      - name: "Update package details"
        run: sudo apt --fix-missing update
      - name: "Install Apache package"
        run: sudo apt install -y apache2-dev
      - name: "Update pip installation"
        run: python -m pip install --upgrade pip setuptools wheel
      - name: "Install mod_wsgi"
        run: python -m pip install --verbose dist/mod_wsgi-[0-9].*.tar.gz
      - name: "Run mod_wsgi-express test #1"
        run: scripts/run-single-test.sh
      - name: "Uninstall mod_wsgi"
        run: pip uninstall --yes mod_wsgi
      - name: "Install mod_wsgi-standalone"
        run: python -m pip install --verbose dist/mod_wsgi[-_]standalone-[0-9].*.tar.gz
      - name: "Run mod_wsgi-express test #2"
        run: scripts/run-single-test.sh
      - name: "Uninstall mod_wsgi-standalone"
        run: pip uninstall --yes mod_wsgi-standalone
      - name: "Verify configure/make/make install"
        run: ./configure && make && sudo make install
