Build and upload to PyPI #26
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 upload to PyPI | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
paths: | |
- "src/radius_clustering/**" | |
- "tests/**" | |
- "pyproject.toml" | |
release: | |
types: | |
- published | |
jobs: | |
run_pytest: | |
name: Run tests on min and max Python versions | |
runs-on: self-hosted | |
strategy: | |
fail-fast: true | |
matrix: | |
python-version: ["3.9", "3.13"] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install -e ".[dev]" | |
- name: Run tests with pytest | |
run: | | |
pytest -v | |
build_wheels: | |
name: Build wheels on ${{ matrix.os }} | |
runs-on: ${{ matrix.os }} | |
needs: run_pytest | |
strategy: | |
fail-fast: false | |
matrix: | |
# macos-13 is an intel runner, macos-14 is apple silicon | |
os: [ubuntu-latest, windows-latest, macos-13, macos-14] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Build wheels | |
uses: pypa/[email protected] | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }} | |
path: ./wheelhouse/*.whl | |
build_sdist: | |
name: Build source distribution | |
runs-on: self-hosted | |
needs: run_pytest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.12" | |
- name: Build sdist | |
run: | | |
pip install --upgrade pip | |
pip install --upgrade pipx | |
pipx run build --sdist | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: cibw-sdist | |
path: dist/*.tar.gz | |
upload_pypi: | |
needs: [build_wheels, build_sdist] | |
runs-on: self-hosted | |
environment: | |
name: pypi | |
url: https://pypi.org/p/radius-clustering | |
permissions: | |
id-token: write | |
attestations: write | |
#if: github.event_name == 'release' && github.event.action == 'published' | |
# or, alternatively, upload to PyPI on every tag starting with 'v' (remove on: release above to use this) | |
#if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') | |
steps: | |
- name: Download all dists | |
uses: actions/download-artifact@v4 | |
with: | |
# unpacks all CIBW artifacts into dist/ | |
pattern: cibw-* | |
path: dist/ | |
merge-multiple: true | |
- name: Test presence of artifacts | |
# This step is not necessary, but it can be useful for debugging | |
# and to check where the artifacts are downloaded | |
# and if they are downloaded correctly | |
# It will list all files in the current directory and its subdirectories | |
run : | | |
# Test if the artifacts are downloaded correctly and where they are | |
ls -R | |
- name: Generate artifact attestations | |
uses: actions/attest-build-provenance@v2 | |
with: | |
subject-path: dist/* | |
- name: Publish Distribution to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
package-dir: dist/ | |
# To test: repository-url: https://test.pypi.org/legacy/ |