Python Wheels #255
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 Wheels | |
on: | |
workflow_dispatch: | |
release: | |
types: ['released', 'prereleased'] | |
env: | |
PACKAGE_VERSION: '1.0.0a20.dev0' | |
PACKAGE_NAME: alpaqa | |
jobs: | |
# First we build the wheels natively (build system == host system). | |
# This allows us to import the compiled modules, and automatically generate | |
# stub files for them. Those stub files are then included in the sdist | |
# (source distribution), to be later included in the cross-compiled packages | |
# as well (because we can't generate stubs while cross-compiling). | |
build-sdist: | |
name: Build sdist | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Conan and sccache | |
uses: ./.github/workflows/setup-conan | |
with: | |
python-version: '3.12' | |
cache-key: build-sdist | |
- name: Build Wheel (and install stubs) | |
run: bash scripts/ci/build-linux-native.sh . dist python | |
- name: Upload Wheel | |
uses: actions/upload-artifact@v4 | |
with: | |
name: native-wheels | |
path: dist/*.whl | |
retention-days: 1 | |
- name: Create sdist | |
run: python3 -m build -s | |
- name: Upload sdist | |
uses: actions/upload-artifact@v4 | |
with: | |
name: sdist | |
path: dist/*.tar.gz | |
retention-days: 1 | |
- run: conan cache clean | |
# Testing is done in the official Python Docker container: https://hub.docker.com/_/python/ | |
# This should match more closely to the environment that users might use. | |
# It also ensures that we don't accidentally depend on any libraries specific | |
# to the build container. | |
test-linux: | |
name: Run tests | |
needs: [build-sdist] | |
runs-on: ubuntu-latest | |
container: python:3.12-bookworm | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Download wheels | |
uses: actions/download-artifact@v4 | |
with: | |
name: native-wheels | |
path: dist | |
- name: Install libgfortran | |
run: apt-get update && apt-get install -y libgfortran5 | |
- name: Install | |
run: python3 -m pip install --find-links=dist "${PACKAGE_NAME}[test]==${PACKAGE_VERSION}" | |
- name: Test | |
run: pytest -rP | |
# After the native build, we have the stub files, and we can start cross- | |
# compiling for other architectures. | |
cross-build-linux: | |
name: Cross-build wheels ${{ matrix.host }} | |
needs: [build-sdist] | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
host: [x86_64-bionic-linux-gnu, aarch64-rpi3-linux-gnu] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Conan and sccache | |
uses: ./.github/workflows/setup-conan | |
with: | |
python-version: '3.12' | |
cache-key: cross-build-${{ matrix.host }} | |
- name: Download sdist | |
uses: actions/download-artifact@v4 | |
with: | |
name: sdist | |
path: dist | |
- name: Extract sdist | |
run: mkdir sdist && tar xf dist/*.tar.gz -C sdist --strip-components 1 | |
- name: Build Wheels | |
run: | | |
for v in 3.9 3.13; do | |
bash scripts/ci/build-linux.sh $v ${{ matrix.host }} sdist dist | |
done | |
- name: Upload Wheels | |
uses: actions/upload-artifact@v4 | |
with: | |
name: wheels-${{ matrix.host }} | |
path: ./dist/*.whl | |
- run: conan cache clean | |
# Build for Windows and macOS using cibuildwheel. | |
# Since we're not specifying any cross-compilation settings, py-build-cmake | |
# will use its default cross-compilation settings for Windows on ARM64. | |
# For macOS, we build universal wheels that work on both Intel and ARM macs. | |
build-macos-windows: | |
if: false | |
name: Build wheels for ${{ matrix.os }} - ${{ matrix.cibw-arch }} | |
needs: [build-sdist] | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
include: | |
- os: windows-latest | |
cibw-arch: AMD64 | |
arch: amd64 | |
- os: windows-latest | |
cibw-arch: x86 | |
arch: amd64_x86 | |
- os: windows-latest | |
cibw-arch: ARM64 | |
arch: amd64_arm64 | |
- os: macos-latest | |
cibw-arch: universal2 | |
fail-fast: false | |
env: | |
SCCACHE_CACHE_MULTIARCH: "1" | |
CIBW_ARCHS: ${{ matrix.cibw-arch }} | |
CIBW_ENABLE: 'pypy' | |
CIBW_TEST_SKIP: 'pp* *-win32' | |
CIBW_BUILD: 'cp311-* pp310-*' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Conan and sccache | |
uses: ./setup-conan/action.yml | |
with: | |
python-version: "3.12" | |
cache-key: cibuildwheel-${{ matrix.cibw-arch }} | |
- name: Install cibuildwheel | |
run: python -m pip install cibuildwheel~=2.22.0 | |
- name: Download sdist | |
uses: actions/download-artifact@v4 | |
with: | |
name: sdist | |
path: dist | |
- name: Extract sdist | |
shell: bash | |
run: mkdir sdist && tar xf dist/*.tar.gz -C sdist --strip-components 1 && cp -a scripts sdist | |
- name: Build wheels | |
if: runner.os == 'Windows' | |
shell: cmd | |
run: | | |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" ${{ matrix.arch }} | |
cibuildwheel sdist --output-dir dist | |
- name: Build wheels | |
if: runner.os != 'Windows' | |
run: cibuildwheel sdist --output-dir dist | |
- name: Upload package | |
uses: actions/upload-artifact@v4 | |
with: | |
name: wheels-${{ matrix.os }}-${{ matrix.cibw-arch }} | |
path: ./dist/*.whl | |
- run: conan cache clean | |
# This step checks the package version before release (to make sure that the | |
# package version actually matches the version of the GitHub release tag), | |
# and uses Twine to check the metadata of the packages. | |
check-release: | |
if: ${{ github.event.action == 'released' || github.event.action == 'prereleased' }} | |
needs: [build-sdist, test-linux, build-macos-windows] | |
runs-on: ubuntu-latest | |
container: python:3.12-bullseye | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/download-artifact@v4 | |
with: | |
pattern: wheels-* | |
path: dist | |
merge-multiple: true | |
- name: Install package | |
run: python -m pip install --no-deps --no-index --find-links=dist ${PACKAGE_NAME}==${PACKAGE_VERSION} | |
- name: Check package version | |
run: | | |
[ "${{ github.event.release.tag_name }}" == $(python -c 'from importlib.metadata import version as v; print(v("${{ env.PACKAGE_NAME }}"))') ] | |
shell: bash | |
- name: Twine check | |
run: | | |
python -m pip install twine | |
twine check dist/* | |
# Here we download the sdist and the built Wheel files, and upload them to | |
# TestPyPI. You should follow the trusted publishing instructions in the | |
# https://github.com/pypa/gh-action-pypi-publish README and on | |
# https://docs.pypi.org/trusted-publishers carefully! | |
release: | |
needs: [check-release] | |
if: ${{ github.event.action == 'released' || github.event.action == 'prereleased' }} | |
runs-on: ubuntu-latest | |
environment: | |
name: testpypi | |
url: https://pypi.org/p/alpaqa | |
permissions: | |
id-token: write # mandatory for trusted publishing | |
steps: | |
- uses: actions/download-artifact@v4 | |
with: | |
pattern: wheels-* | |
path: dist | |
merge-multiple: true | |
- uses: actions/download-artifact@v4 | |
with: | |
name: sdist | |
path: dist | |
- name: Publish package distributions to PyPI | |
uses: pypa/gh-action-pypi-publish@15c56dba361d8335944d31a2ecd17d700fc7bcbc |