---

on:
  push:
    tags:
      - "v*"

jobs:

  build_wheel:
    runs-on: docker
    steps:
      - uses: https://code.forgejo.org/actions/checkout@v4
      - name: Build Python wheel
        run: |
          apt update; apt install -y python3-pip
          pip3 install --break-system-packages -e .[test]
          python3 setup.py egg_info bdist_wheel
      - uses: https://git.kabelsalat.ch/s3lph/forgejo-action-wheel-package-upload@v3
        with:
          username: ${{ secrets.API_USERNAME }}
          password: ${{ secrets.API_PASSWORD }}

  build_debian:
    runs-on: docker
    steps:
      - uses: https://code.forgejo.org/actions/checkout@v4
      - name: Prepare package
        run: |
          # The Python package name provided by the python3-magic Debian package is "python-magic" rather than "file-magic".
          sed -re 's/file-magic/python-magic/' -i setup.py
          cp -r static/ package/debian/matemat/usr/lib/matemat/static/
          cp -r templates/ package/debian/matemat/usr/lib/matemat/templates/
          mkdir -p package/debian/matemat/var/lib/matemat/themes/
          cp -r themes/ package/debian/matemat/usr/lib/matemat/themes/
          
      - uses: https://git.kabelsalat.ch/s3lph/forgejo-action-python-debian-package@v5
        with:
          python_module: matemat
          package_name: matemat
          package_root: package/debian/matemat
          package_output_path: package/debian
          pre_package_hook: |
            mv matemat/usr/bin/matemat matemat/usr/lib/matemat/matemat
            rm -rf matemat/usr/bin
            chmod +x matemat/usr/lib/matemat/matemat

      - uses: https://git.kabelsalat.ch/s3lph/forgejo-action-debian-package-upload@v2
        with:
          username: ${{ secrets.API_USERNAME }}
          password: ${{ secrets.API_PASSWORD }}
          deb: "package/debian/*.deb"