Skip to content

cibuildwheel

cibuildwheel #17

Workflow file for this run

name: 'cibuildwheel'
# Build a single wheel for a specific Python version and a specific platform
# Useful for building a wheel with debug flags
on:
workflow_dispatch:
inputs:
python-tag:
type: string
description: Python version to build the client for
required: true
platform-tag-and-runner-os:
description: Platform to build the client for. (ignore runner OS)
# We hardcode the runner OS version to make sure the wheels are always built in the same environment
# for each platform.
# It is not possible in Github Actions to create a "map" of values
# so we cannot map the platform tag to the runner OS.
# The workaround for this is to create a list of "2-tuples" that can be converted later into a real JSON list.
# Each 2-tuple is a list that maps the platform tag with the runner OS.
# Alternatively we could create a workflow job that maps the platform tag to the runner OS,
# but this would waste Github Actions resources if there were a calling workflow that runs this job many times
# to build multiple wheels.
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"]'
# Makes debugging via gh cli easier.
default: '["manylinux_x86_64", "ubuntu-22.04"]'
unoptimized:
description: 'macOS or Linux: Apply -O0 flag?'
# Windows supports a different flag to disable optimizations, but we haven't added support for it yet
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?'
# This is only supported for the above platforms because we cannot run Docker on Github runners for mac M1 and
# Windows x86.
type: boolean
required: false
default: false
workflow_call:
inputs:
# See workflow call hack in update-version.yml
is_workflow_call:
type: boolean
default: true
required: false
python-tag:
type: string
description: Python version to build the client for
required: true
# Unlike in a workflow dispatch event, we want to make sure any calling workflow is explicit about the platform
# it wants to build for
platform-tag-and-runner-os:
type: string
required: true
sha-to-build:
description: Python client repo commit sha to build
type: string
required: false
default: ${{ github.sha }}
# Debug build settings unused by calling workflows
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:
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=${{ inputs.python-tag }}-${{ env.PLATFORM_TAG }}" >> $GITHUB_ENV
shell: bash
- name: Get commit sha to show status check
# The workflow_dispatch event doesn't have the sha-to-build input
# So we also want to pass in the sha that triggered that event
run: echo COMMIT_SHA_FOR_STATUS_CHECK=${{ inputs.is_workflow_call == true && 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: ${{ env.COMMIT_SHA_FOR_STATUS_CHECK }}
# 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: ${{ inputs.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
- run: echo "RUN_INTEGRATION_TESTS_IN_THIS_JOB=${{ inputs.run_tests && (startsWith(env.PLATFORM_TAG, 'manylinux') || env.PLATFORM_TAG == 'macosx_x86_64') }}" >> $GITHUB_ENV
shell: bash
- name: 'macOS x86: Setup Docker using colima for testing'
if: ${{ env.RUN_INTEGRATION_TESTS_IN_THIS_JOB && env.PLATFORM_TAG == 'macosx_x86_64' }}
uses: ./.github/actions/setup-docker-on-macos
- name: 'Run Aerospike server in Docker container'
uses: ./.github/actions/run-ee-server
if: ${{ env.RUN_INTEGRATION_TESTS_IN_THIS_JOB && !startsWith(env.PLATFORM_TAG, 'manylinux') }}
- name: 'Linux: run Aerospike server in Docker container and configure config.conf to connect to another Docker container'
uses: ./.github/actions/run-ee-server-for-ext-container
if: ${{ env.RUN_INTEGRATION_TESTS_IN_THIS_JOB && startsWith(env.PLATFORM_TAG, 'manylinux') }}
- name: If not running tests against server, only run basic import test
if: ${{ env.RUN_INTEGRATION_TESTS_IN_THIS_JOB == 'false' }}
run: echo "TEST_COMMAND=python -c 'import aerospike'" >> $GITHUB_ENV
shell: bash
- name: Otherwise, enable integration tests
if: ${{ env.RUN_INTEGRATION_TESTS_IN_THIS_JOB == 'true' }}
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 && (startsWith(env.PLATFORM_TAG, 'manylinux') || startsWith(env.PLATFORM_TAG, 'macosx')) }}
run: echo "UNOPTIMIZED=1" >> $GITHUB_ENV
- name: Set include dsym flag
if: ${{ inputs.include-debug-info-for-macos && startsWith(env.PLATFORM_TAG, 'macosx') }}
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 }}