# This file is autogenerated by maturin v1.12.4
# To update, run
#
#    maturin generate-ci github
#
name: PyPi Python publisher

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

on:
  push:
    tags:
      - '[0-9]*'
      - 'py[0-9]*'
  workflow_dispatch:
    inputs:
      skip_build:
        description: 'Skip native+wasm build and use artifacts from run ID'
        required: false
        default: ''

permissions:
  contents: read

jobs:
  linux:
    runs-on: ${{ matrix.platform.runner }}
    if: inputs.skip_build == ''
    strategy:
      fail-fast: false
      matrix:
        platform:
          - runner: ubuntu-22.04
            target: x86_64
            toolchain: stable
            features: avx,sse
          - runner: ubuntu-22.04
            target: x86
            toolchain: stable
            features: sse
          - runner: ubuntu-22.04
            target: aarch64
            toolchain: nightly
            features: rdm,sve,nightly_i8mm
          - runner: ubuntu-22.04
            target: armv7
            toolchain: stable
            features: ""
          - runner: ubuntu-22.04
            target: s390x
            toolchain: stable
            features: ""
          - runner: ubuntu-22.04
            target: ppc64le
            toolchain: stable
            features: ""
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-python@v6
        with:
          python-version: 3.x
      - name: Build wheels
        uses: PyO3/maturin-action@v1
        with:
          rust-toolchain: ${{ matrix.platform.toolchain }}
          target: ${{ matrix.platform.target }}
          args: --release --out dist --find-interpreter ${{ matrix.platform.features != '' && format('--features {0}', matrix.platform.features) || '' }}
          sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
          manylinux: auto
          working-directory: ./pic-scale-py
      - name: Upload wheels
        uses: actions/upload-artifact@v6
        with:
          name: wheels-linux-${{ matrix.platform.target }}
          path: ./pic-scale-py/dist

  musllinux:
    runs-on: ${{ matrix.platform.runner }}
    if: inputs.skip_build == ''
    strategy:
      fail-fast: false
      matrix:
        platform:
          - runner: ubuntu-22.04
            target: x86_64
            toolchain: stable
            features: avx,sse
          - runner: ubuntu-22.04
            target: x86
            toolchain: stable
            features: avx,sse
          - runner: ubuntu-22.04
            target: aarch64
            toolchain: nightly
            features: rdm,sve,nightly_i8mm
          - runner: ubuntu-22.04
            target: armv7
            toolchain: stable
            features: ""
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-python@v6
        with:
          python-version: 3.x
      - name: Build wheels
        uses: PyO3/maturin-action@v1
        with:
          target: ${{ matrix.platform.target }}
          rust-toolchain: ${{ matrix.platform.toolchain }}
          args: --release --out dist --find-interpreter ${{ matrix.platform.features != '' && format('--features {0}', matrix.platform.features) || '' }}
          sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
          manylinux: musllinux_1_2
          working-directory: ./pic-scale-py
      - name: Upload wheels
        uses: actions/upload-artifact@v6
        with:
          name: wheels-musllinux-${{ matrix.platform.target }}
          path: ./pic-scale-py/dist

  windows:
    runs-on: ${{ matrix.platform.runner }}
    if: inputs.skip_build == ''
    strategy:
      fail-fast: false
      matrix:
        platform:
          - runner: windows-latest
            target: x64
            python_arch: x64
            toolchain: stable
            features: avx,sse
          - runner: windows-latest
            target: x86
            python_arch: x86
            toolchain: stable
            features: ""
          - runner: windows-11-arm
            target: aarch64
            python_arch: arm64
            toolchain: nightly
            features: rdm,sve,nightly_i8mm
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-python@v6
        with:
          python-version: 3.13
          architecture: ${{ matrix.platform.python_arch }}
      - name: Build wheels
        uses: PyO3/maturin-action@v1
        with:
          rust-toolchain: ${{ matrix.platform.toolchain }}
          target: ${{ matrix.platform.target }}
          args: --release --out dist --find-interpreter ${{ matrix.platform.features != '' && format('--features {0}', matrix.platform.features) || '' }}
          sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
          working-directory: ./pic-scale-py
      - name: Upload wheels
        uses: actions/upload-artifact@v6
        with:
          name: wheels-windows-${{ matrix.platform.target }}
          path: ./pic-scale-py/dist

  macos:
    runs-on: ${{ matrix.platform.runner }}
    if: inputs.skip_build == ''
    strategy:
      fail-fast: false
      matrix:
        platform:
          - runner: macos-15-intel
            target: x86_64
            features: avx,sse
            toolchain: stable
          - runner: macos-latest
            target: aarch64
            toolchain: nightly
            features: rdm,sve,nightly_i8mm
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-python@v6
        with:
          python-version: 3.x
      - name: Build wheels
        uses: PyO3/maturin-action@v1
        with:
          rust-toolchain: ${{ matrix.platform.toolchain }}
          target: ${{ matrix.platform.target }}
          args: --release --out dist --find-interpreter --features ${{ matrix.platform.features }}
          sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
          working-directory: ./pic-scale-py
      - name: Upload wheels
        uses: actions/upload-artifact@v6
        with:
          name: wheels-macos-${{ matrix.platform.target }}
          path: ./pic-scale-py/dist

  sdist:
    runs-on: ubuntu-latest
    if: inputs.skip_build == ''
    steps:
      - uses: actions/checkout@v6
      - name: Build sdist
        uses: PyO3/maturin-action@v1
        with:
          command: sdist
          args: --out dist
          working-directory: ./pic-scale-py
      - name: Upload sdist
        uses: actions/upload-artifact@v6
        with:
          name: wheels-sdist
          path: ./pic-scale-py/dist

  release:
    name: Release
    runs-on: ubuntu-latest
    if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }}
    needs: [ linux, musllinux, windows, macos, sdist ]
    environment: Cargo
    permissions:
      # Use to sign the release artifacts
      id-token: write
      # Used to upload release artifacts
      contents: write
      # Used to generate artifact attestation
      attestations: write
    steps:
      - uses: actions/download-artifact@v6
      - name: Generate artifact attestation
        uses: actions/attest-build-provenance@v3
        with:
          subject-path: 'wheels-*/*'
      - name: Install uv
        if: ${{ startsWith(github.ref, 'refs/tags/') }}
        uses: astral-sh/setup-uv@v7
      - name: Publish to PyPI
        if: ${{ startsWith(github.ref, 'refs/tags/') }}
        run: uv publish 'wheels-*/*'
        env:
          UV_PUBLISH_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
