Build Python Module #11
Workflow file for this run
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 Python Module | |
| on: | |
| push: | |
| branches: | |
| - master | |
| - develop | |
| - "release/*" | |
| tags: | |
| - "*.*.*" | |
| pull_request: | |
| branches: | |
| - master | |
| - develop | |
| - "release/*" | |
| workflow_dispatch: | |
| env: | |
| DRY_RUN: ${{ !(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) }} | |
| jobs: | |
| build-wheels: | |
| name: Build Wheels | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [macos-latest] | |
| python-version: ["3.11", "3.12", "3.13", "3.14"] | |
| outputs: | |
| dist-paths: ${{ steps.upload-artifacts.outputs.dist-paths }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install system dependencies | |
| if: runner.os != 'Windows' | |
| run: | | |
| sudo apt-get update || brew update | |
| sudo apt-get install -y libsamplerate0-dev || brew install libsamplerate | |
| - name: Install vcpkg dependencies | |
| if: runner.os == 'Windows' | |
| run: | | |
| git clone https://github.com/microsoft/vcpkg.git vcpkg | |
| .\vcpkg\bootstrap-vcpkg.bat | |
| .\vcpkg\vcpkg install libsamplerate:x64-windows | |
| - name: Setup Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Upgrade build tools | |
| run: | | |
| python -m pip install --upgrade pip setuptools wheel twine build scikit-build-core pybind11 numpy | |
| # --------------------------- | |
| # Dry-run version bump | |
| # --------------------------- | |
| - name: Bump version for Test PyPI | |
| if: env.DRY_RUN == 'true' | |
| working-directory: plugins/python-module | |
| shell: bash | |
| run: | | |
| python - <<EOF | |
| from pathlib import Path | |
| import re, tomllib | |
| path = Path("pyproject.toml") | |
| data = tomllib.loads(path.read_text()) | |
| base = data["project"]["version"] | |
| new = f"{base}.post0.dev{${{ github.run_number }}}" | |
| text = re.sub(r'version\\s*=\\s*".*"', f'version = "{new}"', path.read_text()) | |
| path.write_text(text) | |
| EOF | |
| - name: Build distributions (Windows) | |
| if: runner.os == 'Windows' | |
| working-directory: plugins/python-module | |
| run: | | |
| python -m build --wheel --sdist | |
| env: | |
| CMAKE_TOOLCHAIN_FILE: ${{ github.workspace }}\vcpkg\scripts\buildsystems\vcpkg.cmake | |
| - name: Build distributions | |
| if: runner.os != 'Windows' | |
| working-directory: plugins/python-module | |
| run: | | |
| python -m build --wheel --sdist | |
| - name: Install built wheel | |
| working-directory: plugins/python-module | |
| run: | | |
| python -m pip install dist/*.whl | |
| - name: Run Python sanity tests | |
| working-directory: plugins/python-module | |
| run: | | |
| python -m pip install pytest | |
| pytest -q | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: btrack-wheels-${{ matrix.os }}-py${{ matrix.python-version }} | |
| path: plugins/python-module/dist/* | |
| publish: | |
| name: Publish to PyPI | |
| runs-on: ubuntu-latest | |
| needs: build-wheels | |
| if: > | |
| startsWith(github.ref, 'refs/heads/release/') || | |
| (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) | |
| steps: | |
| - name: Download all built wheels | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: dist/ | |
| - name: Flatten wheel artifacts | |
| run: | | |
| mkdir -p files-to-upload | |
| find dist -type f \( -name "*.whl" -o -name "*.tar.gz" \) -exec mv {} files-to-upload/ \; | |
| - name: Install twine | |
| run: | | |
| python -m pip install --upgrade pip twine | |
| - name: Publish to Test PyPI | |
| if: env.DRY_RUN == 'true' | |
| run: python -m twine upload --repository testpypi files-to-upload/* --verbose | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }} | |
| - name: Publish to Production PyPI | |
| if: env.DRY_RUN == 'false' | |
| run: python -m twine upload files-to-upload/* | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} |