-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mrc-4786: Build and publish Python wheels in CI. (#49)
This will allow users to install and import the Python bindings without needing to install a Rust toolchain. The wheels should work on most mainstream platforms and architecture. We can add more if it turns out there's a gap somewhere. Additionally it uses abi3 wheels, which will work on any Python version >= 3.8, see https://pyo3.rs/v0.20.0/building_and_distribution#py_limited_apiabi3 The wheels are built unconditionally on every commit to master and PR commit. Additionally, whenever a tag is created the source package and wheels are pushed to PyPI.
- Loading branch information
Showing
4 changed files
with
131 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
name: Build, Test and Publish Python Bindings | ||
jobs: | ||
test: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: | ||
- "3.8" | ||
- "3.9" | ||
- "3.10" | ||
- "3.11" | ||
name: Test (Python ${{ matrix.python-version }}) | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install Python tooling | ||
run: | | ||
python -m pip install hatch | ||
- name: Run Python tests | ||
run: | | ||
hatch run test | ||
build-sdist: | ||
name: Build source distribution | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.x" | ||
- name: Install pypa/build | ||
run: | | ||
python -m pip install build | ||
- name: Build source distribution | ||
run: | | ||
python -m build --sdist | ||
- name: Upload artifacts | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
if-no-files-found: error | ||
name: python-artifacts | ||
path: dist | ||
|
||
build-wheels: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
config: | ||
- {os: ubuntu-latest, target: 'x86_64'} | ||
- {os: ubuntu-latest, target: 'x86'} | ||
- {os: ubuntu-latest, target: 'aarch64'} | ||
- {os: windows-latest, target: 'x64'} | ||
- {os: windows-latest, target: 'x86'} | ||
- {os: macos-latest, target: 'x86_64'} | ||
- {os: macos-latest, target: 'aarch64'} | ||
|
||
runs-on: ${{ matrix.config.os }} | ||
name: Build wheels for ${{ matrix.config.os }} (${{ matrix.config.target }}) | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
if: matrix.config.os == 'windows-latest' | ||
with: | ||
python-version: "3.x" | ||
architecture: ${{ matrix.config.target }} | ||
- name: Build wheels | ||
uses: PyO3/maturin-action@v1 | ||
with: | ||
target: ${{ matrix.config.target }} | ||
args: --release --out dist | ||
manylinux: manylinux2014 | ||
- name: Upload artifacts | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
if-no-files-found: error | ||
name: python-artifacts | ||
path: dist | ||
|
||
# This assumes a PyPI Trusted Publisher has been configure for the `outpack_query_parser` package. | ||
# See https://docs.pypi.org/trusted-publishers/ for more details. | ||
publish-to-pypi: | ||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') | ||
name: Publish Python distribution to PyPI | ||
needs: | ||
- build-sdist | ||
- build-wheels | ||
runs-on: ubuntu-latest | ||
environment: | ||
name: pypi | ||
url: https://pypi.org/p/outpack_query_parser | ||
permissions: | ||
# This permission is needed for the workflow to authenticate against PyPI | ||
id-token: write | ||
steps: | ||
- name: Download all the dists | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: python-artifacts | ||
path: dist/ | ||
- name: Publish distribution to PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 |
This file contains 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
This file contains 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