diff --git a/.github/workflows/source-wheels.yml b/.github/workflows/source-wheels.yml new file mode 100644 index 0000000..b07d6bd --- /dev/null +++ b/.github/workflows/source-wheels.yml @@ -0,0 +1,248 @@ +name: Build and test source-built wheels + +# Builds the Python wheels of a repository that compiles an LLVM tool from +# source with scikit-build-core and cibuildwheel (clang-apply-replacements, +# clang-include-cleaner), plus its source distribution, and tests them. Each +# repository's own test.yml (one platform, on pull requests) and publish.yml +# (every platform, on release tags) call this workflow. The upload to PyPI +# stays in each repository's publish.yml, because PyPI trusted publishing does +# not work from inside a reusable workflow. +# +# What the calling repository provides: +# - pyproject.toml with the cibuildwheel settings (test-command and so on); +# - the version file that pyproject.toml reads the version from; +# - a pytest suite under test/ that tests the installed package, not the +# source tree (the workflow deletes `package-dir` before testing). +# +# The workflow uploads each platform's wheels as the artifact +# `artifacts-wheels--`, and the source distribution as +# `artifacts-sdist`, so the upload job can download them all with the pattern +# `artifacts-*`. + +on: + workflow_call: + inputs: + version-file: + description: The file that holds the version, e.g. clang-include-cleaner_version.txt + type: string + required: true + package-dir: + description: The Python package directory, e.g. clang_include_cleaner + type: string + required: true + llvm-version: + description: >- + Build this LLVM version instead of the one in version-file; the + version becomes .. Empty means the + version in version-file. + type: string + required: false + default: "" + wheel-version: + description: The packaging version appended to llvm-version + type: string + required: false + default: "0" + platforms: + description: >- + JSON list of {os, platform, arch} to build wheels for; platform is + the cibuildwheel platform (manylinux, musllinux, win, macos) and + arch the cibuildwheel architecture. Empty means every platform a + release builds (the list in the "platforms" job below). + type: string + required: false + default: "" + sdist: + description: Also build the source distribution and test a build from it + type: boolean + required: false + default: true + +permissions: {} + +jobs: + platforms: + name: Choose the platforms + runs-on: ubuntu-latest + outputs: + platforms: ${{ steps.platforms.outputs.platforms }} + steps: + - name: Choose the platforms + id: platforms + env: + PLATFORMS: ${{ inputs.platforms }} + run: | + if [ -z "$PLATFORMS" ]; then + # Every platform a release builds. The manylinux i686 wheel is + # built on Ubuntu 24.04: on Ubuntu 26.04, DNS lookups fail inside + # the manylinux_2_28_i686 container (pip cannot reach pypi.org). + PLATFORMS='[ + {"os": "ubuntu-latest", "platform": "manylinux", "arch": "x86_64"}, + {"os": "ubuntu-latest", "platform": "musllinux", "arch": "x86_64"}, + {"os": "ubuntu-24.04", "platform": "manylinux", "arch": "i686"}, + {"os": "ubuntu-latest", "platform": "musllinux", "arch": "i686"}, + {"os": "ubuntu-24.04-arm", "platform": "manylinux", "arch": "aarch64"}, + {"os": "ubuntu-24.04-arm", "platform": "manylinux", "arch": "armv7l"}, + {"os": "ubuntu-24.04-arm", "platform": "musllinux", "arch": "armv7l"}, + {"os": "windows-latest", "platform": "win", "arch": "AMD64"}, + {"os": "windows-latest", "platform": "win", "arch": "x86"}, + {"os": "macos-15-intel", "platform": "macos", "arch": "x86_64"}, + {"os": "macos-latest", "platform": "macos", "arch": "arm64"} + ]' + fi + # One line, as GITHUB_OUTPUT needs; jq also rejects invalid JSON. + echo "platforms=$(echo "$PLATFORMS" | jq -c .)" >> "$GITHUB_OUTPUT" + + build-wheels: + name: Build wheels on ${{ matrix.os }} (${{ matrix.platform }} ${{ matrix.arch }}) + needs: platforms + runs-on: ${{ matrix.os }} + permissions: + contents: read + strategy: + # Each job builds LLVM for about an hour. Let the other platforms finish + # when one job fails, so "Re-run failed jobs" only rebuilds that one. + fail-fast: false + matrix: + include: ${{ fromJSON(needs.platforms.outputs.platforms) }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Support long paths + if: runner.os == 'Windows' + run: git config --system core.longpaths true + + - name: Set up MSVC + if: runner.os == 'Windows' + uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0 + with: + arch: ${{ matrix.arch }} + + - name: Export macOS SDKROOT + if: runner.os == 'macOS' + run: echo "SDKROOT=$(xcrun --sdk macosx --show-sdk-path)" >> "$GITHUB_ENV" + + - name: Override the LLVM version + if: inputs.llvm-version + shell: bash + env: + VERSION_FILE: ${{ inputs.version-file }} + LLVM_VERSION: ${{ inputs.llvm-version }} + WHEEL_VERSION: ${{ inputs.wheel-version }} + run: | + echo "${LLVM_VERSION}.${WHEEL_VERSION}" > "$VERSION_FILE" + cat "$VERSION_FILE" + + - name: Build wheels + uses: pypa/cibuildwheel@b9e566a2b284570af229f6c2a33673410d0389a3 # v4.3.4 + env: + CIBW_ARCHS: ${{ matrix.arch }} + # One Python version is enough: the wheel does not depend on Python. + CIBW_BUILD: cp311-${{ matrix.platform }}* + # Test the installed wheel, not the source tree. + CIBW_BEFORE_TEST: rm -rf {package}/${{ inputs.package-dir }} + # No tests inside the Linux containers; the step below tests the + # Linux wheels that the runner can run itself. + CIBW_TEST_SKIP: "*linux*" + + - name: Check whether the runner can run the wheel + id: native + shell: bash + env: + PLATFORM: ${{ matrix.platform }} + ARCH: ${{ matrix.arch }} + run: | + # cibuildwheel's selectors for the runner's own architecture. + case "$ARCH/$RUNNER_ARCH" in + native/X64 | auto/X64 | auto64/X64) ARCH=x86_64 ;; + native/ARM64 | auto/ARM64 | auto64/ARM64) ARCH=aarch64 ;; + esac + case "$RUNNER_OS/$RUNNER_ARCH/$PLATFORM/$ARCH" in + Linux/X64/manylinux/x86_64 | Linux/ARM64/manylinux/aarch64) echo "test=true" >> "$GITHUB_OUTPUT" ;; + *) echo "test=false" >> "$GITHUB_OUTPUT" ;; + esac + + - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 + if: steps.native.outputs.test == 'true' + with: + python-version: "3.13" + + - name: Test the wheel + if: steps.native.outputs.test == 'true' + env: + PACKAGE_DIR: ${{ inputs.package-dir }} + run: | + # Remove the source package so the tests import the installed wheel. + rm -r "$PACKAGE_DIR" + python -m pip install wheelhouse/*.whl pytest + python -m pytest + + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: artifacts-wheels-${{ matrix.platform }}-${{ matrix.arch }} + path: ./wheelhouse/*.whl + if-no-files-found: error + + build-sdist: + name: Build source distribution + if: inputs.sdist + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Override the LLVM version + if: inputs.llvm-version + env: + VERSION_FILE: ${{ inputs.version-file }} + LLVM_VERSION: ${{ inputs.llvm-version }} + WHEEL_VERSION: ${{ inputs.wheel-version }} + run: | + echo "${LLVM_VERSION}.${WHEEL_VERSION}" > "$VERSION_FILE" + cat "$VERSION_FILE" + + - name: Build SDist + run: pipx run build --sdist + + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: artifacts-sdist + path: dist/*.tar.gz + if-no-files-found: error + + test-sdist: + name: Test build from source distribution + needs: build-sdist + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 + with: + python-version: "3.13" + + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: artifacts-sdist + path: sdist + + - name: Install from SDist + env: + PACKAGE_DIR: ${{ inputs.package-dir }} + run: | + rm -r "$PACKAGE_DIR" + python -m pip install sdist/*.tar.gz + + - name: Run test suite + run: | + python -m pip install pytest + python -m pytest diff --git a/README.md b/README.md index af4ace3..3631166 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,13 @@ builds and tests the Python wheels of the repositories that repackage prebuilt b on. The upload to PyPI stays in each repository's `publish.yml`, because PyPI trusted publishing does not work from inside a reusable workflow. +[`source-wheels.yml`](https://github.com/cpp-linter/.github/blob/main/.github/workflows/source-wheels.yml) +does the same for the repositories that compile an LLVM tool from source with cibuildwheel +([clang-apply-replacements](https://github.com/cpp-linter/clang-apply-replacements), +[clang-include-cleaner](https://github.com/cpp-linter/clang-include-cleaner)): their `test.yml` +calls it for one platform on pull requests, and their `publish.yml` for every platform before the +PyPI upload. + ## Brand assets [`branding/`](https://github.com/cpp-linter/.github/tree/main/branding) holds the logos, the social