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_call: | ||
| inputs: | ||
| upload: | ||
| description: 'Upload to PyPI' | ||
| type: boolean | ||
| required: false | ||
| default: false | ||
| python-version: | ||
| description: 'Python version to run on' | ||
| type: string | ||
| required: true | ||
| default: "3.13" | ||
| target: | ||
| description: "target os to build for: linux,macos,windows" | ||
| type: string | ||
| required: false | ||
| default: "linux,macos,windows" | ||
| jobs: | ||
| prepare-matrix: | ||
| name: "Prepare matrix to run for ${{ inputs.python-version }} on `${{ inputs.target }}`" | ||
| runs-on: ubuntu-24.04 | ||
| outputs: | ||
| matrix: ${{ steps.prepare.outputs.matrix }} | ||
| steps: | ||
| - name: Prepare matrix json from input matrix list | ||
| id: prepare | ||
| run: | | ||
| echo -n "[" > /tmp/matrix.json | ||
| was_added="" | ||
| for os in $(echo "${{ inputs.target }}" | tr -d " " | tr "," "\n") | ||
| do | ||
| if [[ "${os}" == "linux" ]]; then | ||
| [ -n "$was_added" ] && echo -n "," >> /tmp/matrix.json | ||
| echo -n '{"os":"ubuntu-20.04","platform":"x86_64"},{"os":"ubuntu-20.04","platform":"PyPy"}' >> /tmp/matrix.json | ||
| was_added=1 | ||
| elif [[ "${os}" == "windows" ]]; then | ||
| [ -n "$was_added" ] && echo -n "," >> /tmp/matrix.json | ||
| echo -n '{"os":"windows-2022","platform":"win64"},{"os":"windows-2022","platform":"PyPy"}' >> /tmp/matrix.json | ||
| was_added=1 | ||
| elif [[ "${os}" == "macos" ]]; then | ||
| [ -n "$was_added" ] && echo -n "," >> /tmp/matrix.json | ||
| echo -n '{"os":"macos-14","platform":"all"},{"os":"macos-13","platform":"all"},{"os":"macos-14","platform":"PyPy"}' >> /tmp/matrix.json | ||
| was_added=1 | ||
| fi | ||
| done | ||
| echo -n "]" >> /tmp/matrix.json | ||
| echo -e "Resulted matrix json:\n$(cat /tmp/matrix.json)" | ||
| echo "matrix=$(cat /tmp/matrix.json)" >> $GITHUB_OUTPUT | ||
| build-wheels: | ||
| name: Build wheels ${{ matrix.os }} (${{ matrix.platform }}) | ||
| runs-on: ${{ matrix.os }} | ||
| needs: prepare-matrix | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: ${{ fromJson(needs.prepare-matrix.outputs.matrix) }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-python@v5 | ||
| name: Install Python | ||
| with: | ||
| python-version: ${{ inputs.python-version }} | ||
| allow-prereleases: 'true' | ||
| - name: Enable pip installing globally | ||
| if: runner.os == 'MacOs' || runner.os == 'Windows' | ||
| run: | | ||
| echo "PIP_BREAK_SYSTEM_PACKAGES=1" >> $GITHUB_ENV | ||
| - name: Install cibuildwheel | ||
| run: | | ||
| python3 -m pip install cibuildwheel[uv]==2.22.0 | ||
| - name: Install OpenSSL for Windows | ||
| if: runner.os == 'Windows' | ||
| run: | | ||
| choco install openssl --version=3.4.1 -f -y | ||
| choco install llvm -y | ||
| - name: Install Conan | ||
| if: runner.os == 'Windows' | ||
| uses: turtlebrowser/get-conan@main | ||
| - name: configure libev for Windows | ||
| if: runner.os == 'Windows' | ||
| run: | | ||
| conan profile detect | ||
| conan install conanfile.py | ||
| - name: Install OpenSSL for MacOS | ||
| if: runner.os == 'MacOs' | ||
| run: | | ||
| brew install libev | ||
| - name: Overwrite for Linux and MacOS | ||
| if: runner.os == 'Linux' || runner.os == 'MacOS' | ||
| run: | | ||
| ##### Set MACOSX_DEPLOYMENT_TARGET | ||
| if [ "${{ matrix.os }}" == "macos-13" ]; then | ||
| echo "MACOSX_DEPLOYMENT_TARGET=13.0" >> $GITHUB_ENV; | ||
| echo "Enforcing target deployment for 13.0" | ||
| elif [ "${{ matrix.os }}" == "macos-14" ]; then | ||
| echo "MACOSX_DEPLOYMENT_TARGET=14.0" >> $GITHUB_ENV; | ||
| echo "Enforcing target deployment for 14.0" | ||
| fi | ||
| - name: Build wheels | ||
| if: runner.os != 'Windows' | ||
| run: | | ||
| python3 -m cibuildwheel --output-dir wheelhouse | ||
| - name: Build wheels | ||
| if: runner.os == 'Windows' | ||
| run: | | ||
| python3 -m cibuildwheel --output-dir wheelhouse | ||
| env: | ||
| CC: "C:\Program Files\LLVM\bin\clang.exe" | ||
| CXX: "C:\Program Files\LLVM\bin\clang++.exe" | ||
| CIBW_ENVIRONMENT_WINDOWS: "CC=\"C:\Program Files\LLVM\bin\clang.exe\" CXX=\"C:\Program Files\LLVM\bin\clang++.exe\"" | ||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: wheels-${{ matrix.os }}-${{ matrix.platform }} | ||
| path: ./wheelhouse/*.whl | ||
| build-sdist: | ||
| name: Build source distribution | ||
| runs-on: ubuntu-24.04 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-python@v5 | ||
| name: Install Python | ||
| - name: Build sdist | ||
| run: | | ||
| pip install build | ||
| python -m build --sdist | ||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: source-dist | ||
| path: dist/*.tar.gz | ||
| build-wheels-extra-arch: | ||
| # The host should always be linux | ||
| runs-on: ubuntu-24.04 | ||
| name: Build extra arch ${{ matrix.archs }} wheels | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| archs: [ aarch64,] # ppc64le ] | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Set up QEMU | ||
| id: qemu | ||
| uses: docker/setup-qemu-action@v3 | ||
| with: | ||
| platforms: all | ||
| image: 'docker.io/tonistiigi/binfmt:desktop-v8.1.5' | ||
| if: runner.os == 'Linux' | ||
| - uses: actions/setup-python@v5 | ||
| name: Install Python | ||
| with: | ||
| python-version: ${{ inputs.python-version }} | ||
| allow-prereleases: 'true' | ||
| - name: Install cibuildwheel | ||
| run: | | ||
| python -m pip install cibuildwheel[uv]==2.22.0 | ||
| - name: Build wheels | ||
| env: | ||
| CIBW_BUILD: "cp39* cp310* cp311* cp312* cp313*" # limit to specific version since it take much more time than jobs limit | ||
| run: | | ||
| python -m cibuildwheel --archs ${{ matrix.archs }} --output-dir wheelhouse | ||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: wheels-${{ matrix.archs }} | ||
| path: ./wheelhouse/*.whl | ||
| upload_pypi: | ||
| if: inputs.upload | ||
| needs: [build-wheels, build-wheels-extra-arch, build-sdist] | ||
| runs-on: ubuntu-24.04 | ||
| permissions: | ||
| id-token: write | ||
| steps: | ||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| path: dist | ||
| merge-multiple: true | ||
| - uses: pypa/gh-action-pypi-publish@release/v1 | ||
| with: | ||
| skip-existing: true | ||