Skip to content

Commit

Permalink
👷♻️ Improved Reusable Workflows (#594)
Browse files Browse the repository at this point in the history
## Description

This PR refactors parts of the reusable workflow and enhances them.
Notable changes:
- ⚡ Build and test parallelism is increased. Most public GitHub runners
offer 4 cores now.
- 🚸 Slightly reduces the number of individual macOS runs to avoid
hitting the concurrency limit of 5 runners too often.
- ✨ Adjusts the Python packaging workflow so that it also applies to
pure Python projects
- 🚸 Makes the default GitHub token available to Python test runs
- ♻️ Combines the Python test and minimal version runs. This means fewer
workflow runs and fewer coverage uploads. Minimal versions are now tests
on all Python versions and operating systems to ensure smooth operation
of the resulting packages.
- ♻️ Automates the Python version selection for building wheels. Just
one less place to touch when a new Python version comes around.

## Checklist:

<!---
This checklist serves as a reminder of a couple of things that ensure
your pull request will be merged swiftly.
-->

- [x] The pull request only contains commits that are related to it.
- [x] I have added appropriate tests and documentation.
- [x] I have made sure that all CI jobs on GitHub pass.
- [x] The pull request introduces no new warnings and follows the
project's style guidelines.

---------

Signed-off-by: burgholzer <burgholzer@me.com>
  • Loading branch information
burgholzer committed Apr 22, 2024
1 parent cb555c9 commit 5f88f68
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 117 deletions.
2 changes: 1 addition & 1 deletion .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ flag_management:
- name: python
paths:
- "src/mqt/**/*.py"
after_n_builds: 12
after_n_builds: 10
statuses:
- type: project
threshold: 0.5%
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/reusable-change-detection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
filter: |
include/**
!include/python/**
!include/**/python/**
src/**
!src/mqt/**
!src/python/**
Expand Down Expand Up @@ -65,6 +66,7 @@ jobs:
filter: |
include/**
!include/python/**
!include/**/python/**
src/**
!src/mqt/**
!src/python/**
Expand Down Expand Up @@ -97,7 +99,6 @@ jobs:
.github/codecov.yml
.github/workflows/reusable-python-linter.yml
.github/workflows/reusable-python-tests.yml
.github/workflows/reusable-python-minimums.yml
.github/workflows/reusable-python-ci.yml
.github/workflows/ci.yml
- name: Set a flag for running the Python tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable-code-ql-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
permissions:
security-events: write
env:
CMAKE_BUILD_PARALLEL_LEVEL: 3
CMAKE_BUILD_PARALLEL_LEVEL: 4
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/reusable-cpp-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,9 @@ jobs:
z3-version: ${{ inputs.z3-version }}

cpp-tests-macos:
name: 🍎 ${{ matrix.config }}
strategy:
matrix:
config: [Debug, Release]
fail-fast: false
name: 🍎
uses: ./.github/workflows/reusable-cpp-tests-macos.yml
with:
config: ${{ matrix.config }}
cmake-args: ${{ inputs.cmake-args }} ${{ inputs.cmake-args-macos }}
setup-z3: ${{ inputs.setup-z3 }}
z3-version: ${{ inputs.z3-version }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/reusable-cpp-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
name: 📈 Coverage
runs-on: ubuntu-latest
env:
CMAKE_BUILD_PARALLEL_LEVEL: 3
CTEST_PARALLEL_LEVEL: 3
CMAKE_BUILD_PARALLEL_LEVEL: 4
CTEST_PARALLEL_LEVEL: 4
FORCE_COLOR: 3
steps:
- uses: actions/checkout@v4
Expand Down
30 changes: 16 additions & 14 deletions .github/workflows/reusable-cpp-tests-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ name: 🇨 • Tests • macos-latest
on:
workflow_call:
inputs:
config:
description: "The configuration to use (Debug or Release)"
required: true
type: string
cmake-args:
description: "Additional arguments to pass to CMake"
default: "-G Ninja"
Expand All @@ -21,14 +17,14 @@ on:

jobs:
cpp-tests-macos:
name: 🍎 ${{ inputs.config }} ${{ matrix.runs-on }}
name: 🍎 ${{ matrix.runs-on }}
runs-on: ${{ matrix.runs-on }}
strategy:
matrix:
runs-on: [macos-13, macos-14] # Tests on the Intel and arm64 architectures
env:
CMAKE_BUILD_PARALLEL_LEVEL: 3
CTEST_PARALLEL_LEVEL: 3
CMAKE_BUILD_PARALLEL_LEVEL: 4
CTEST_PARALLEL_LEVEL: 4
FORCE_COLOR: 3
steps:
- uses: actions/checkout@v4
Expand All @@ -46,12 +42,18 @@ jobs:
uses: Chocobo1/setup-ccache-action@v1
with:
prepend_symlinks_to_path: false
override_cache_key: c++-tests-macos-latest-${{ inputs.config }}
override_cache_key: c++-tests-${{ matrix.runs-on }}
- name: Install Ninja
run: brew install ninja
- name: Configure CMake
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ inputs.config }} ${{ inputs.cmake-args }}
- name: Build
run: cmake --build build --config ${{ inputs.config }}
- name: Test
run: ctest -C ${{ inputs.config }} --output-on-failure --test-dir build --repeat until-pass:3 --timeout 600
- name: Configure CMake (Debug)
run: cmake -S . -B build_debug -DCMAKE_BUILD_TYPE=Debug ${{ inputs.cmake-args }}
- name: Build (Debug)
run: cmake --build build_debug --config Debug
- name: Test (Debug)
run: ctest -C Debug --output-on-failure --test-dir build_debug --repeat until-pass:3 --timeout 600
- name: Configure CMake (Release)
run: cmake -S . -B build_release -DCMAKE_BUILD_TYPE=Release ${{ inputs.cmake-args }}
- name: Build (Release)
run: cmake --build build_release --config Release
- name: Test (Release)
run: ctest -C Release --output-on-failure --test-dir build_release --repeat until-pass:3 --timeout 600
4 changes: 2 additions & 2 deletions .github/workflows/reusable-cpp-tests-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
name: 🐧 ${{ inputs.config }}
runs-on: ubuntu-latest
env:
CMAKE_BUILD_PARALLEL_LEVEL: 3
CTEST_PARALLEL_LEVEL: 3
CMAKE_BUILD_PARALLEL_LEVEL: 4
CTEST_PARALLEL_LEVEL: 4
FORCE_COLOR: 3
steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/reusable-cpp-tests-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ jobs:
name: 🏁 ${{ inputs.config }}
runs-on: windows-latest
env:
CMAKE_BUILD_PARALLEL_LEVEL: 3
CTEST_PARALLEL_LEVEL: 3
CMAKE_BUILD_PARALLEL_LEVEL: 4
CTEST_PARALLEL_LEVEL: 4
FORCE_COLOR: 3
steps:
- uses: actions/checkout@v4
Expand Down
18 changes: 0 additions & 18 deletions .github/workflows/reusable-python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,3 @@ jobs:
z3-version: ${{ inputs.z3-version }}
secrets:
token: ${{ secrets.token }}

minimums:
name: 🔧 Minimums
needs: [dist]
strategy:
fail-fast: false
matrix:
python-version:
- ${{ fromJson(needs.dist.outputs.python-versions)[0] }}
- ${{ needs.dist.outputs.max-python-version }}
uses: ./.github/workflows/reusable-python-minimums.yml
with:
runs-on: ubuntu-latest
python-version: ${{ matrix.python-version }}
setup-z3: ${{ inputs.setup-z3 }}
z3-version: ${{ inputs.z3-version }}
secrets:
token: ${{ secrets.token }}
64 changes: 0 additions & 64 deletions .github/workflows/reusable-python-minimums.yml

This file was deleted.

58 changes: 56 additions & 2 deletions .github/workflows/reusable-python-packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ name: 🐍 • Packaging
on:
workflow_call:
inputs:
pure-python:
description: "Whether this is a pure Python package (or contains compiled extensions)"
default: false
type: boolean
setup-z3:
description: "Whether to set up Z3"
default: false
Expand Down Expand Up @@ -30,14 +34,62 @@ jobs:
name: cibw-sdist
path: dist/*.tar.gz

build_wheel:
if: ${{ inputs.pure-python }}
name: 🛞 Wheel
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Build Wheel
run: pipx run build --wheel
- name: Check metadata
run: pipx run twine check dist/*
- uses: actions/upload-artifact@v4
with:
name: cibw-wheel
path: dist/*.whl

dist:
if: ${{ !inputs.pure-python }}
name: 📦 Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- if: ${{ inputs.setup-z3 }}
name: Setup Z3
uses: cda-tum/setup-z3@v1
with:
version: ${{ inputs.z3-version }}
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Set up mold as linker (Linux only)
uses: rui314/setup-mold@v1
- uses: hynek/build-and-inspect-python-package@v2
id: baipp
with:
skip-wheel: "true"
- name: 🐍 create identifiers for supported Python versions
id: python-versions
run: echo "python-versions=$(echo '${{ steps.baipp.outputs.supported_python_classifiers_json_array }}' | jq -c --raw-output 'map("cp" + . | gsub("\\."; ""))')" >> $GITHUB_OUTPUT
outputs:
python-versions: ${{ steps.python-versions.outputs.python-versions }}

build_wheels:
if: ${{ !inputs.pure-python }}
needs: dist
name: 🎡 ${{ matrix.runs-on }} ${{ matrix.python }}
runs-on: ${{ matrix.runs-on }}
strategy:
fail-fast: false
matrix:
runs-on: [ubuntu-latest, macos-13, macos-14, windows-latest]
python: ["cp38", "cp39", "cp310", "cp311", "cp312"]
python: ${{ fromJson(needs.dist.outputs.python-versions) }}
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -75,13 +127,15 @@ jobs:
path: wheelhouse/*.whl

build_wheels_emulation:
if: ${{ !inputs.pure-python }}
needs: dist
name: 🎡 ${{ matrix.arch }} ${{ matrix.python }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
arch: ["s390x", "ppc64le", "aarch64"]
python: ["cp38", "cp39", "cp310", "cp311", "cp312"]
python: ${{ fromJson(needs.dist.outputs.python-versions) }}
steps:
- uses: actions/checkout@v4
with:
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/reusable-python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
runs-on: ${{ inputs.runs-on }}
env:
FORCE_COLOR: 3
GITHUB_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -40,8 +41,6 @@ jobs:
uses: cda-tum/setup-z3@v1
with:
version: ${{ inputs.z3-version }}
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Setup ccache
uses: Chocobo1/setup-ccache-action@v1
with:
Expand All @@ -54,8 +53,10 @@ jobs:
- uses: wntrblm/nox@2024.04.15
with:
python-versions: ${{ inputs.python-version }}
- name: Test on 🐍 ${{ inputs.python-version }} with minimal versions
run: nox -s minimums-${{ inputs.python-version }} --verbose -- --cov --cov-report=xml
- name: Test on 🐍 ${{ inputs.python-version }}
run: nox -s tests-${{ inputs.python-version }} --verbose -- --cov --cov-report=xml
run: nox -s tests-${{ inputs.python-version }} --verbose -- --cov --cov-report=xml --cov-append
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
Expand Down
8 changes: 7 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@

PYTHON_ALL_VERSIONS = ["3.8", "3.9", "3.10", "3.11", "3.12"]

# The following lists all the build requirements for building the package.
# Note that this includes transitive build dependencies of package dependencies,
# since we use `--no-build-isolation` to install the package in editable mode
# and get better caching performance. This only concerns dependencies that are
# not available via wheels on PyPI (i.e., only as source distributions).
BUILD_REQUIREMENTS = [
"scikit-build-core[pyproject]>=0.8.1",
"setuptools_scm>=7",
"pybind11>=2.12",
"wheel>=0.40", # transitive dependency of pytest on Windows
]

if os.environ.get("CI", None):
Expand Down Expand Up @@ -72,7 +78,7 @@ def tests(session: nox.Session) -> None:
_run_tests(session)


@nox.session(reuse_venv=True, venv_backend="uv")
@nox.session(reuse_venv=True, venv_backend="uv", python=PYTHON_ALL_VERSIONS)
def minimums(session: nox.Session) -> None:
"""Test the minimum versions of dependencies."""
_run_tests(
Expand Down

0 comments on commit 5f88f68

Please sign in to comment.