Build and Publish #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Publish | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| workflow_dispatch: | |
| inputs: | |
| target: | |
| description: 'Publish target' | |
| required: true | |
| default: 'pypi' | |
| type: choice | |
| options: | |
| - pypi | |
| - testpypi | |
| permissions: | |
| contents: read | |
| id-token: write | |
| jobs: | |
| build-sdist: | |
| name: Build source distribution | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| - name: Install maturin | |
| run: pip install maturin | |
| - name: Build sdist | |
| run: maturin sdist | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: sdist | |
| path: target/wheels/*.tar.gz | |
| build-wheels: | |
| name: Build wheels on ${{ matrix.os }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| arch: x86_64 | |
| - os: ubuntu-latest | |
| arch: aarch64 | |
| - os: macos-latest | |
| arch: x86_64 | |
| - os: macos-latest | |
| arch: aarch64 | |
| - os: windows-latest | |
| arch: x86_64 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| - uses: dtolnay/rust-toolchain@stable | |
| - name: Build wheels | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| target: ${{ matrix.arch }} | |
| args: --release --out dist --find-interpreter | |
| manylinux: auto | |
| docker-options: -e CI=true | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheels-${{ matrix.os }}-${{ matrix.arch }} | |
| path: dist/*.whl | |
| publish: | |
| name: Publish to PyPI | |
| needs: [build-sdist, build-wheels] | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' || github.event.inputs.target == 'pypi' | |
| steps: | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| path: dist | |
| merge-multiple: true | |
| - uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| skip-existing: true | |
| publish-testpypi: | |
| name: Publish to TestPyPI | |
| needs: [build-sdist, build-wheels] | |
| runs-on: ubuntu-latest | |
| if: github.event.inputs.target == 'testpypi' | |
| steps: | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| path: dist | |
| merge-multiple: true | |
| - uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| repository-url: https://test.pypi.org/legacy/ | |
| skip-existing: true |