name: Release
on:
  push:
    tags: ["v*"]

jobs:
  wheels:
    runs-on: codeberg-small
    container:
      image: ghcr.io/pyo3/maturin
    steps:
      - uses: https://code.forgejo.org/actions/checkout@v4
      - run: maturin sdist -o dist/
      - run: maturin build --release --strip --target x86_64-unknown-linux-gnu --manylinux 2_17 -o dist/
      - run: |
          pip install ziglang
          rustup target add aarch64-unknown-linux-gnu
          maturin build --release --strip --target aarch64-unknown-linux-gnu --zig --manylinux 2_17 -o dist/
      - uses: https://code.forgejo.org/actions/upload-artifact@v4
        with:
          name: dist
          path: dist/

  publish:
    needs: [wheels]
    runs-on: codeberg-small
    container:
      image: ghcr.io/pyo3/maturin
    steps:
      - uses: https://code.forgejo.org/actions/checkout@v4
      - uses: https://code.forgejo.org/actions/download-artifact@v4
        with:
          name: dist
          path: dist/
      - run: |
          pip install twine
          twine upload --non-interactive dist/*.whl dist/*.tar.gz
        env:
          TWINE_USERNAME: __token__
          TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
      - run: cargo publish --token "${{ secrets.CARGO_REGISTRY_TOKEN }}"
      - uses: https://code.forgejo.org/actions/forgejo-release@v2
        with:
          direction: upload
          url: ${{ github.server_url }}
          repo: ${{ github.repository }}
          token: ${{ secrets.RELEASE_TOKEN }}
          tag: ${{ github.ref_name }}
          title: ${{ github.ref_name }}
          release-dir: dist/
