Build and Publish Python Package #9
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 and Publish Python Package | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "Version to use for the Python package (e.g. 0.5.9)" | |
| required: true | |
| type: string | |
| release: | |
| types: [published] | |
| jobs: | |
| build-and-publish: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| platform: linux | |
| python-version: "3.10" | |
| arch: x86_64 | |
| plat_name: linux_x86_64 | |
| - os: ubuntu-latest | |
| platform: linux | |
| python-version: "3.10" | |
| arch: arm64 | |
| plat_name: linux_aarch64 | |
| - os: windows-latest | |
| platform: windows | |
| python-version: "3.10" | |
| arch: x86_64 | |
| plat_name: win_amd64 | |
| - os: macos-latest | |
| platform: macos | |
| python-version: "3.10" | |
| arch: x86_64 | |
| plat_name: macosx_10_9_x86_64 | |
| - os: macos-latest | |
| platform: macos | |
| python-version: "3.10" | |
| arch: arm64 | |
| plat_name: macosx_11_0_arm64 | |
| defaults: | |
| run: | |
| shell: bash | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| submodules: false | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install build dependencies | |
| run: | | |
| cd python-package | |
| python3 -m pip install --upgrade pip | |
| python3 -m pip install -r requirements-dev.txt | |
| - name: Get version | |
| id: get_version | |
| run: | | |
| if [[ "${{ github.event_name }}" == "release" ]]; then | |
| VERSION="${{ github.event.release.tag_name }}" | |
| else | |
| VERSION="${{ github.event.inputs.version }}" | |
| fi | |
| VERSION=${VERSION#v} | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Download artifacts for current platform | |
| run: | | |
| cd python-package | |
| python3 download_artifacts.py "${{ matrix.plat_name }}" "${{ steps.get_version.outputs.version }}" | |
| - name: Build wheel | |
| env: | |
| PACKAGE_VERSION: ${{ steps.get_version.outputs.version }} | |
| run: | | |
| cd python-package | |
| python setup.py bdist_wheel --plat-name "${{ matrix.plat_name }}" | |
| - name: Publish to PyPI | |
| if: github.event_name == 'release' | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| packages-dir: python-package/dist |