Switch to cibuildwheel for CI builds.

This commit is contained in:
Russell Keith-Magee 2025-02-19 12:35:35 +08:00
parent 698c8c4bc4
commit 0859524e4f
No known key found for this signature in database
GPG key ID: 3D2DAB6A37BB5BC3
5 changed files with 135 additions and 28 deletions

View file

@ -4,6 +4,7 @@ on:
push: push:
branches: branches:
- main - main
workflow_call:
# Cancel active CI runs for a PR before starting another run # Cancel active CI runs for a PR before starting another run
concurrency: concurrency:
@ -25,26 +26,45 @@ jobs:
unit-tests: unit-tests:
name: Unit tests name: Unit tests
needs: [ pre-commit ] needs: [ pre-commit ]
runs-on: ${{ matrix.platform }} runs-on: ${{ matrix.runs-on }}
continue-on-error: ${{ matrix.experimental || false }}
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
platform: [ "macos-13", "macos-latest", "ubuntu-24.04" ] name: [ "macOS (x86_64)", "macOS (arm64)", "iOS", "Linux (x86_64)", "Linux (arm64)" ] # Android, Windows (x86_64), Windows (arm64)
# Test the min and max stable Python version on each OS.
python-version: [ "3.9", "3.13" ]
include: include:
# Ensure the Python versions between min and max are tested - name: macOS (x86_64)
- platform: "ubuntu-24.04" platform: macos
python-version: "3.10" runs-on: macos-13
- platform: "ubuntu-24.04" archs: auto
python-version: "3.11" - name: macOS (arm64)
- platform: "ubuntu-24.04" platform: macos
python-version: "3.12" runs-on: macos-latest
# Allow dev Python to fail without failing entire job archs: auto,universal2
- platform: "ubuntu-24.04" - name: iOS
python-version: "3.14" platform: ios
experimental: true runs-on: macos-latest
archs: auto
- name: Linux (x86_64)
platform: linux
runs-on: ubuntu-24.04
archs: auto
- name: Linux (arm64)
platform: linux
runs-on: ubuntu-24.04-arm
archs: auto
# - name: Android
# platform: android
# runs-on: macos-latest
# archs: auto
# - name: Windows (x86_64)
# platform: windows
# runs-on: windows-latest
# archs: auto
# - name: Windows (arm64)
# platform: windows
# runs-on: windows-latest-arm??
# archs: auto
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4.2.2 uses: actions/checkout@v4.2.2
@ -54,16 +74,23 @@ jobs:
- name: Set up Python - name: Set up Python
uses: actions/setup-python@v5.4.0 uses: actions/setup-python@v5.4.0
with: with:
python-version: ${{ matrix.python-version }} python-version: "3.x"
allow-prereleases: true
- name: Install Tox - name: Install cibuildwheel
uses: beeware/.github/.github/actions/install-requirement@main
with:
requirements: tox
extra: dev
- name: Test
id: test
run: | run: |
tox -e py python -m pip install -U pip
# Use a branch while iOS support is in development and test-sources is unpublished.
# python -m pip install cibuildwheel==3.0.0
python -m pip install git+https://github.com/freakboy3742/cibuildwheel.git@ios-support
- name: Build wheels
run: python -m cibuildwheel
env:
CIBW_PLATFORM: ${{ matrix.platform }}
CIBW_ARCHS: ${{ matrix.archs }}
CIBW_BUILD: "cp*"
- uses: actions/upload-artifact@v4.6.0
with:
name: wheels-${{ matrix.name }}
path: ./wheelhouse/*.whl

22
.github/workflows/publish.yml vendored Normal file
View file

@ -0,0 +1,22 @@
name: Upload Python Package
on:
release:
types: published
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
# This permission is required for trusted publishing.
id-token: write
steps:
- uses: dsaltares/fetch-gh-release-asset@1.1.2
with:
version: tags/${{ github.event.release.tag_name }}
file: ${{ github.event.repository.name }}.*
regex: true
target: dist/
- name: Publish release to production PyPI
uses: pypa/gh-action-pypi-publish@release/v1.12.3

54
.github/workflows/release.yml vendored Normal file
View file

@ -0,0 +1,54 @@
name: Create Release
on:
push:
tags:
- 'v*'
jobs:
ci:
name: CI
uses: ./.github/workflows/ci.yml
release:
name: Create Release
needs: ci
runs-on: ubuntu-latest
permissions:
contents: write
# This permission is required for trusted publishing.
id-token: write
attestations: write
steps:
- name: Set build variables
run: |
echo "VERSION=${GITHUB_REF_NAME#v}" | tee -a $GITHUB_ENV
- name: Set up Python
uses: actions/setup-python@v5.4.0
with:
python-version: "3.x"
- name: Get packages
uses: actions/download-artifact@v4.1.8
with:
pattern: wheels-*
path: dist
- name: Create release
uses: ncipollo/release-action@v1.15.0
with:
name: ${{ env.VERSION }}
draft: true
artifacts: dist/*
artifactErrorsFailBuild: true
- name: Generate attestations
uses: actions/attest-build-provenance@v2.1.0
with:
subject-path: "dist/*"
# - name: Publish release to Test PyPI
# uses: pypa/gh-action-pypi-publish@release/v1
# with:
# repository-url: https://test.pypi.org/legacy/

1
.gitignore vendored
View file

@ -11,3 +11,4 @@ distribute-*
.tox/ .tox/
.vscode/ .vscode/
venv/ venv/
wheelhouse/

View file

@ -31,7 +31,6 @@ classifiers=[
"Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Topic :: Text Processing", "Topic :: Text Processing",
"Topic :: Utilities", "Topic :: Utilities",
] ]
@ -52,6 +51,10 @@ Homepage = "https://github.com/freakboy3742/pyspamsum/"
Tracker = "https://github.com/freakboy3742/pyspamsum/issues" Tracker = "https://github.com/freakboy3742/pyspamsum/issues"
Source = "https://github.com/freakboy3742/pyspamsum/" Source = "https://github.com/freakboy3742/pyspamsum/"
[tool.cibuildwheel]
test-command = "pytest"
test-sources = ["tests"]
[tool.pytest.ini_options] [tool.pytest.ini_options]
testpaths = ["tests"] testpaths = ["tests"]
filterwarnings = [ filterwarnings = [