Skip to content

Update CI to build wheels for linux + osx with cibuildwheel #288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: CI

on:
push:
pull_request:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

permissions:
contents: read # to fetch code (actions/checkout)

jobs:
ci:
strategy:
# Allows for matrix sub-jobs to fail without canceling the rest
fail-fast: false

matrix:
os:
- "ubuntu-latest"
- "macos-latest"
# Test with the earliest and latest supported versions of Python, lxml, and libxmlsec1
# so that we get reasonable coverage of the supported versions.
python-version:
- "3.7"
- "3.12"
lxml-version:
- "5.0.0"
- "5.1.0"
libxmlsec1-version:
- "1.3.3"
- "1.2.39"

exclude:
# LXML did not upload a wheel for Python 3.7 so we can't test
# this configuration.
- os: "macos-latest"
python-version: "3.7"
lxml-version: "5.0.0"

env:
PYXMLSEC_STATIC_DEPS: "true"
PYXMLSEC_LIBXML2_VERSION: "2.12.3"
PYXMLSEC_LIBXSLT_VERSION: "1.1.39"

# This defaults to 360 minutes (6h) which is way too long and if a test gets stuck, it can block other pipelines.
# From testing, the runs tend to take 3-8 minutes, so a limit of 30 minutes should be enough.
timeout-minutes: 30
runs-on: ${{ matrix.os }}

steps:
- name: Checkout repo
uses: actions/[email protected]

- name: Setup Python
uses: actions/[email protected]
with:
python-version: ${{ matrix.python-version }}

- name: Cache libs
uses: actions/[email protected]
with:
path: libs/*.tar.gz
key: >
libs-
${{ matrix.os }}-
${{ env.PYXMLSEC_LIBXML2_VERSION }}-
${{ env.PYXMLSEC_LIBXSLT_VERSION }}-
${{ matrix.libxmlsec1-version }}

- name: Install build dependencies
run: pip install --upgrade pip setuptools wheel build

- name: Build wheel
run: |
python -m build
rm -rf build/
env:
PYXMLSEC_XMLSEC1_VERSION: ${{ matrix.libxmlsec1-version }}

- name: Install test dependencies
run: |
pip install --only-binary=lxml --upgrade -r requirements-test.txt lxml==${{ matrix.lxml-version }}
pip install xmlsec --only-binary=xmlsec --no-index --find-links=dist/

- name: Run tests
run: |
pytest -v --color=yes
34 changes: 0 additions & 34 deletions .github/workflows/linuxbrew.yml

This file was deleted.

44 changes: 0 additions & 44 deletions .github/workflows/macosx.yml

This file was deleted.

48 changes: 0 additions & 48 deletions .github/workflows/manylinux.yml

This file was deleted.

29 changes: 0 additions & 29 deletions .github/workflows/opensuse-tumbleweed.yml

This file was deleted.

26 changes: 0 additions & 26 deletions .github/workflows/sdist.yml

This file was deleted.

120 changes: 120 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: Wheel build

on:
release:
types: [created]
schedule:
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
# │ │ │ │ │
- cron: "42 3 * * 4"
push:
pull_request:
workflow_dispatch:

permissions: {}

jobs:
sdist:
runs-on: ubuntu-latest

permissions:
contents: write

steps:
- uses: actions/[email protected]
with:
fetch-depth: 0

- name: Set up Python
uses: actions/[email protected]
with:
python-version: "3.x"

- name: Install build dependencies
run: |
pip install --upgrade pip setuptools wheel

- name: Package source dist
run: python setup.py sdist

- name: Install test dependencies
run: |
sudo apt-get update -y -q
sudo apt-get install -y -q libxml2-dev libxslt1-dev libxmlsec1-dev libxmlsec1-openssl opensc softhsm2 libengine-pkcs11-openssl
pip install --upgrade -r requirements-test.txt --no-binary lxml
pip install dist/xmlsec-$(python setup.py --version).tar.gz

- name: Run tests
run: pytest -v --color=yes

- name: Upload sdist
uses: actions/[email protected]
with:
name: sdist
path: dist/*.tar.gz

generate-wheels-matrix:
# Create a matrix of all architectures & versions to build.
# This enables the next step to run cibuildwheel in parallel.
# From https://iscinumpy.dev/post/cibuildwheel-2-10-0/#only-210
name: Generate wheels matrix
runs-on: ubuntu-latest
outputs:
include: ${{ steps.set-matrix.outputs.include }}
steps:
- uses: actions/checkout@v4
- name: Install cibuildwheel
# Nb. keep cibuildwheel version pin consistent with job below
run: pipx install cibuildwheel==2.16.5
- id: set-matrix
# Once we have the windows build figured out, it can be added here
# by updating the matrix to include windows builds as well.
# See example here:
# https://github.com/lxml/lxml/blob/3ccc7d583e325ceb0ebdf8fc295bbb7fc8cd404d/.github/workflows/wheels.yml#L95C1-L106C51
run: |
MATRIX=$(
{
cibuildwheel --print-build-identifiers --platform linux \
| jq -nRc '{"only": inputs, "os": "ubuntu-latest"}' \
&& cibuildwheel --print-build-identifiers --platform macos \
| jq -nRc '{"only": inputs, "os": "macos-latest"}'
} | jq -sc
)
echo "include=$MATRIX"
echo "include=$MATRIX" >> $GITHUB_OUTPUT

build_wheels:
name: Build for ${{ matrix.only }}
needs: generate-wheels-matrix
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.generate-wheels-matrix.outputs.include) }}

steps:
- name: Check out the repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v3
with:
platforms: all

- name: Build wheels
uses: pypa/[email protected]
with:
only: ${{ matrix.only }}

- uses: actions/[email protected]
with:
path: ./wheelhouse/*.whl
name: xmlsec-wheel-${{ matrix.only }}
Loading