name: Publish Django package to Gitea registry

on:
  push:
    tags:
      - 'django/v*'

jobs:
  publish:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: backends/mizan-django
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-python@v5
        with:
          python-version: '3.12'

      - name: Install build tools
        run: pip install build twine

      - name: Build package
        run: python -m build

      - name: Publish to Gitea PyPI
        env:
          TWINE_REPOSITORY_URL: ${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/pypi
          TWINE_USERNAME: __token__
          TWINE_PASSWORD: ${{ secrets.PUBLISH_TOKEN }}
        run: twine upload dist/*
