Skip to content

cibuildwheel

cibuildwheel #14

Workflow file for this run

name: 'cibuildwheel'
on:
workflow_dispatch:
inputs:
python-tags:
type: string
description: Python versions to build the client for
required: false
default: '["cp38", "cp39", "cp310", "cp311", "cp312"]'
platform-tag-and-runner-os:
type: choice
required: true
options:
- '["manylinux_x86_64", "ubuntu-22.04"]'
- '["manylinux_aarch64", "ubuntu-22.04"]'
- '["macosx_x86_64", "macos-12-large"]'
- '["macosx_arm64", "macos-13-large"]'
- '["win_amd64", "windows-2022"]'
default: '["manylinux_x86_64", "ubuntu-22.04"]'
unoptimized:
description: 'macOS or Linux: Apply -O0 flag?'
type: boolean
required: false
default: false
include-debug-info-for-macos:
description: 'macOS: Build wheel for debugging?'
type: boolean
required: false
default: false
run_tests:
description: 'manylinux or macOS x86: Run Aerospike server and run tests?'
type: boolean
required: false
default: false
workflow_call:
inputs:
python-tags:
type: string
description: Python versions to build the client for
required: false
default: '["cp38", "cp39", "cp310", "cp311", "cp312"]'
platform-tag:
type: string
required: true
sha-to-build:
type: string
required: false
default: ${{ github.sha }}
unoptimized:
type: boolean
required: false
default: false
include-debug-info-for-macos:
type: boolean
required: false
default: false
run_tests:
type: boolean
required: false
default: false
jobs:
cibuildwheel:
strategy:
matrix:
python-tag: ${{ fromJSON(inputs.python-tags) }}
fail-fast: false
runs-on: ${{ fromJSON(inputs.platform-tag-and-runner-os)[1] }}
steps:
- name: Get platform tag from input
run: echo PLATFORM_TAG=${{ fromJSON(inputs.platform-tag-and-runner-os)[0] }} >> $GITHUB_ENV
shell: bash
- name: Get build identifier for cibuildwheel
run: echo "BUILD_IDENTIFIER=${{ matrix.python-tag }}-${{ env.PLATFORM_TAG }}" >> $GITHUB_ENV
shell: bash
- name: Get commit sha to show status check
# The workflow_dispatch event does not have a ref-to-build input
# And when dereferencing a non-existent input, it will return an empty string
# We have to pass in a valid sha, so just use github.ref by default
run: echo COMMIT_SHA_FOR_STATUS_CHECK=${{ inputs.sha-to-build != '' && inputs.sha-to-build || github.sha }} >> $GITHUB_ENV
- name: Create status check message
run: echo STATUS_CHECK_MESSAGE="cibuildwheel (${{ env.BUILD_IDENTIFIER }})" >> $GITHUB_ENV
- name: Show job status for commit
uses: myrotvorets/set-commit-status-action@v2.0.0
if: ${{ github.event_name != 'push' && github.event_name != 'pull_request' }}
with:
sha: ${{ env.COMMIT_SHA_FOR_STATUS_CHECK }}
context: ${{ env.STATUS_CHECK_MESSAGE }}
- uses: actions/checkout@v4
with:
submodules: recursive
ref: ${{ inputs.sha-to-build }}
# We need the last tag before the ref, so we can relabel the version if needed
fetch-depth: 0
- name: 'macOS arm64: Install experimental Python 3.8 macOS arm64 build'
# By default, cibuildwheel installs and uses Python 3.8 x86_64 to cross compile macOS arm64 wheels
# There is a bug that builds macOS x86_64 wheels instead, so we install this Python 3.8 native ARM build to ensure
# the wheel is compiled for macOS arm64
# https://cibuildwheel.pypa.io/en/stable/faq/#macos-building-cpython-38-wheels-on-arm64
if: ${{ matrix.python-tag == 'cp38' && env.PLATFORM_TAG == 'macosx_arm64' }}
run: |
curl -o /tmp/Python38.pkg https://www.python.org/ftp/python/3.8.10/python-3.8.10-macos11.pkg
sudo installer -pkg /tmp/Python38.pkg -target /
sh "/Applications/Python 3.8/Install Certificates.command"
- name: 'Windows: Add msbuild to PATH'
if: ${{ env.PLATFORM_TAG == 'win_amd64' }}
uses: microsoft/setup-msbuild@v1.1
- name: 'Windows: Install C client deps'
if: ${{ env.PLATFORM_TAG == 'win_amd64' }}
run: nuget restore
working-directory: aerospike-client-c/vs
- name: 'Linux aarch64: Set up QEMU for building and testing wheels'
if: ${{ endsWith(env.PLATFORM_TAG, 'aarch64') }}
uses: docker/setup-qemu-action@v2
with:
platforms: arm64
- name: 'macOS x86: Setup Docker using colima for testing'
if: ${{ inputs.run_tests && env.PLATFORM_TAG == 'macosx_x86_64' }}
uses: ./.github/actions/setup-docker-on-macos
- uses: ./.github/actions/run-ee-server
if: ${{ inputs.run_tests && !startsWith(env.PLATFORM_TAG, 'manylinux') }}
- uses: ./.github/actions/run-ee-server-for-ext-container
if: ${{ inputs.run_tests && startsWith(env.PLATFORM_TAG, 'manylinux') }}
- name: If not running tests against server, only run basic import test
if: ${{ !inputs.run_tests }}
run: echo "TEST_COMMAND=python -c 'import aerospike'" >> $GITHUB_ENV
shell: bash
- name: Otherwise, enable integration tests
if: ${{ inputs.run_tests }}
run: echo "TEST_COMMAND=cd {project}/test/ && pip install -r requirements.txt && python -m pytest new_tests/" >> $GITHUB_ENV
shell: bash
- name: Set unoptimize flag
if: ${{ inputs.unoptimized }}
run: echo "UNOPTIMIZED=1" >> $GITHUB_ENV
- name: Set include dsym flag
if: ${{ inputs.include-debug-info-for-macos }}
run: echo "INCLUDE_DSYM=1" >> $GITHUB_ENV
- name: Build wheel
uses: pypa/cibuildwheel@v2.18.1
env:
CIBW_ENVIRONMENT_PASS_LINUX: ${{ inputs.unoptimized && 'UNOPTIMIZED' || '' }}
CIBW_ENVIRONMENT_MACOS: SSL_LIB_PATH="$(brew --prefix openssl@1.1)/lib/" CPATH="$(brew --prefix openssl@1.1)/include/" STATIC_SSL=1
# We are cross compiling for Linux aarch64 on x86_64 hardware, so we need to specify the target arch
CIBW_ARCHS_LINUX: ${{ env.PLATFORM_TAG == 'manylinux_aarch64' && 'aarch64' || 'auto' }}
CIBW_BUILD: ${{ env.BUILD_IDENTIFIER }}
CIBW_BUILD_FRONTEND: build
CIBW_BEFORE_ALL_LINUX: >
yum install openssl-devel -y &&
yum install python-devel -y &&
yum install python-setuptools -y
CIBW_BEFORE_BUILD_WINDOWS: "pip install delvewheel"
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "delvewheel repair --add-path ./aerospike-client-c/vs/x64/Release -w {dest_dir} {wheel}"
CIBW_TEST_COMMAND: ${{ env.TEST_COMMAND }}
- name: Upload wheels to GitHub
uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
path: ./wheelhouse/*.whl
name: ${{ env.BUILD_IDENTIFIER }}.build
- name: Set final commit status
uses: myrotvorets/set-commit-status-action@v2.0.0
if: ${{ always() && github.event_name != 'push' && github.event_name != 'pull_request' }}
with:
sha: ${{ env.COMMIT_SHA_FOR_STATUS_CHECK }}
status: ${{ job.status }}
context: ${{ env.STATUS_CHECK_MESSAGE }}