Skip to content

[PUB] Python Wheels

[PUB] Python Wheels #8

#############################################################################
# IMPORTANT: This file MUST stay in sync with emu-python-wheels.yml.
#
# Expected differences are the cisco-actions/* mirror references and workflow
# and file naming differences. A quick sanity self-check is included in the
# workflow. Do NOT accept PRs where these files diverge in any other way.
#############################################################################
name: "[PUB] Python Wheels"
on:
workflow_dispatch:
push:
branches:
- main
permissions:
contents: read
jobs:
sync-self-check:
name: Sync self-check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Check diff between emu and pub workflow files
run: |
MAX_DIFF_LINES=4
COUNT=$(diff -y --suppress-common-lines .github/workflows/emu-python-wheels.yml .github/workflows/pub-python-wheels.yml | wc -l)
echo "Differing lines: $COUNT (max allowed: $MAX_DIFF_LINES)"
if [ "$COUNT" -gt "$MAX_DIFF_LINES" ]; then
echo "::error::emu-python-wheels.yml and pub-python-wheels.yml have diverged ($COUNT differing lines, max $MAX_DIFF_LINES)"
diff .github/workflows/emu-python-wheels.yml .github/workflows/pub-python-wheels.yml || true
exit 1
fi
build-mercury-wheels:
needs: sync-self-check
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
environment:
name: pypi
url: https://pypi.org/p/mercury-python
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 1
submodules: recursive
- name: Install packages (Linux)
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y zlib1g-dev libssl-dev make libxsimd-dev
- name: Install packages (macOS)
if: runner.os == 'macOS'
run: brew install openssl zlib xsimd
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.x'
- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v4.0.0
with:
platforms: all
- name: Install pip packages
run: python -m pip install cython
- name: Build Mercury
run: ./configure && make && cp -r src/cython/* ./
- name: Build wheels
uses: pypa/cibuildwheel@v3.4.0
env:
CIBW_ARCHS_LINUX: aarch64 x86_64
CIBW_ARCHS_MACOS: arm64
CIBW_SKIP: "*-musllinux_* cp38*"
CIBW_BEFORE_ALL_LINUX: (yum install -y epel-release && yum install -y openssl-devel make zlib-devel xsimd-devel) || apt-get install -y zlib1g-dev libssl-dev make libxsimd-dev || apk add --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community zlib-dev openssl-dev make xsimd-dev
CIBW_BEFORE_ALL_MACOS: brew install openssl zlib xsimd
CIBW_TEST_COMMAND: cd {project} && python mercury_python_test.py
- name: Upload to S3
if: vars.UPLOAD_PYTHON_WHEELS_TO_S3 == 'true'
env:
AWS_ACCESS_KEY_ID: ${{secrets.ACCESS_KEY_ID}}
AWS_SECRET_ACCESS_KEY: ${{secrets.ACCESS_KEY_SECRET}}
AWS_DEFAULT_REGION: us-east-1
S3_BUCKET: ${{secrets.S3_BUCKET}}
run: VERSION=$(cat src/cython/_version.py | tr -d '\n' | cut -d \' -f2) && aws s3 cp wheelhouse/ "s3://$S3_BUCKET/version=$VERSION" --recursive