introduce cibuildwheel to build workflow #136
Workflow file for this run
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
name: Python Packages | |
on: | |
push: | |
branches: [ develop ] | |
tags: [ "v*" ] | |
# following two lines must be commented out before merging, we don't want to run this on PRs | |
# but for testing this we run this on PRs | |
pull_request: | |
branches: [ develop ] | |
jobs: | |
build-wheels: | |
name: build wheels using cibuildwheel | |
runs-on: ${{ format('{0}-latest', matrix.os) }} | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- os: "ubuntu" | |
platform: "linux" | |
arch: "x86_64" | |
- os: "macos" | |
arch: "universal2" | |
- os: "windows" | |
arch: "AMD64" | |
env: | |
build-sdist: ${{ matrix.os == 'ubuntu' && matrix.arch == 'x86_64' }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: setup python for sdist and cibuildwheel | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.11' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install --upgrade setuptools setuptools-rust build cibuildwheel | |
- name: download dictionary for PGO | |
if: ${{ matrix.os == 'ubuntu' }} | |
run: bash fetch_dictionary.sh "20220519" "core" | |
- name: Add aarch64/x86 target for macos | |
if: ${{ matrix.os == 'macos' }} | |
run: rustup target add aarch64-apple-darwin x86_64-apple-darwin | |
- uses: actions/cache@v4 | |
with: | |
path: | | |
~/.cargo/bin/ | |
~/.cargo/registry/index/ | |
~/.cargo/registry/cache/ | |
~/.cargo/git/db/ | |
target/ | |
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
- name: build sdist | |
if: ${{ env.build-sdist == 'true' }} | |
working-directory: ./python | |
run: bash build-sdist.sh | |
- name: cibuildwheel ${{ matrix.platform || matrix.os }} | |
env: | |
# most configuration are in python/pyproject.toml | |
CIBW_PLATFORM: ${{ matrix.platform || matrix.os }} | |
CIBW_ARCHS: ${{ matrix.arch }} | |
run: cibuildwheel python/ --output-dir python/dist/ | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: artifact-${{ matrix.os }} | |
path: | | |
./python/dist/*.whl | |
./python/dist/*.tar.gz | |
upload-to-pypi: # run only if all have succeeded | |
needs: [ build-wheels ] | |
# https://stackoverflow.com/questions/58475748/github-actions-how-to-check-if-current-push-has-new-tag-is-new-release | |
if: startsWith(github.ref, 'refs/tags/v') # only for tags | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/download-artifact@v4 | |
with: | |
pattern: artifact-* | |
path: dist/ | |
merge-multiple: true | |
- name: List files to upload | |
run: ls -R dist/ | |
- name: Publish distribution to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
user: ${{ secrets.PYPI_USERNAME }} | |
password: ${{ secrets.PYPI_PASSWORD }} | |
verbose: true |