|
| 1 | +# SPDX-FileCopyrightText: 2026 The RISE Project |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | +--- |
| 4 | +# Based on the `build-wheels` job of |
| 5 | +# https://github.com/simpleble/simpleble/blob/v1.1.0/.github/workflows/ci_simplepyble.yml |
| 6 | +name: Build simplepyble wheels (riscv64) |
| 7 | + |
| 8 | +on: |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + version: |
| 12 | + description: 'Version glob to (re)build; empty builds every version of docs/packages/simplepyble.yaml not released yet' |
| 13 | + required: false |
| 14 | + default: '' |
| 15 | + pull_request: |
| 16 | + branches: [main] |
| 17 | + paths: |
| 18 | + - '.github/workflows/build-simplepyble.yml' |
| 19 | + - 'docs/packages/simplepyble.yaml' |
| 20 | + push: |
| 21 | + branches: [main] |
| 22 | + paths: |
| 23 | + - '.github/workflows/build-simplepyble.yml' |
| 24 | + - 'docs/packages/simplepyble.yaml' |
| 25 | + |
| 26 | +concurrency: |
| 27 | + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} |
| 28 | + cancel-in-progress: true |
| 29 | + |
| 30 | +permissions: |
| 31 | + contents: read # to fetch code (actions/checkout) |
| 32 | + |
| 33 | +env: |
| 34 | + MANYLINUX_RISCV64_IMAGE: quay.io/pypa/manylinux_2_39_riscv64 |
| 35 | + |
| 36 | +jobs: |
| 37 | + setup: |
| 38 | + uses: $/.github/workflows/_setup.yml |
| 39 | + with: |
| 40 | + package: simplepyble |
| 41 | + version: ${{ inputs.version }} |
| 42 | + |
| 43 | + build_wheels: |
| 44 | + needs: [setup] |
| 45 | + if: needs.setup.outputs.versions != '[]' |
| 46 | + name: Build simplepyble ${{ matrix.version }} ${{ matrix.python }}-manylinux_riscv64 |
| 47 | + runs-on: ubuntu-24.04-riscv |
| 48 | + strategy: |
| 49 | + fail-fast: false |
| 50 | + matrix: |
| 51 | + version: ${{ fromJSON(needs.setup.outputs.versions) }} |
| 52 | + # upstream skips cp314t and musllinux |
| 53 | + python: ["cp312", "cp313", "cp314"] |
| 54 | + |
| 55 | + env: |
| 56 | + SIMPLEPYBLE_VERSION: ${{ matrix.version }} |
| 57 | + |
| 58 | + steps: |
| 59 | + - name: Checkout simpleble v${{ env.SIMPLEPYBLE_VERSION }} |
| 60 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 61 | + with: |
| 62 | + repository: simpleble/simpleble |
| 63 | + ref: v${{ env.SIMPLEPYBLE_VERSION }} |
| 64 | + persist-credentials: false |
| 65 | + |
| 66 | + - name: Stage the licence-collection script |
| 67 | + run: | |
| 68 | + cat > collect-licenses.sh <<'COLLECT_EOF' |
| 69 | + #!/bin/bash |
| 70 | + # SPDX-FileCopyrightText: 2026 The RISE Project |
| 71 | + # SPDX-License-Identifier: MIT |
| 72 | + # |
| 73 | + # Stage, at the project root, the licence of every shared library |
| 74 | + # auditwheel vendors out of the build image alongside libdbus-1. |
| 75 | + # setuptools' default LICENSE* glob copies them into the wheel. |
| 76 | + set -euo pipefail |
| 77 | +
|
| 78 | + project="${1:?usage: collect-licenses.sh <project-dir>}" |
| 79 | +
|
| 80 | + # ldd is transitive, so libdbus-1 alone covers its whole closure; |
| 81 | + # ldd does not list the root itself, so resolve that too. |
| 82 | + mapfile -t libs < <( |
| 83 | + { |
| 84 | + ldd /usr/lib64/libdbus-1.so | tr ' ' '\n' | grep '^/' |
| 85 | + readlink -f /usr/lib64/libdbus-1.so |
| 86 | + } | sort -u |
| 87 | + ) |
| 88 | +
|
| 89 | + # `rpm -qf` reports unowned files on stdout, so keep only bare package names. |
| 90 | + # glibc and the gcc runtime are on auditwheel's manylinux allowlist and |
| 91 | + # are never vendored into the wheel. |
| 92 | + mapfile -t pkgs < <( |
| 93 | + rpm -qf --qf '%{NAME}\n' "${libs[@]}" 2>/dev/null | |
| 94 | + grep -E '^[A-Za-z0-9._+-]+$' | sort -u | |
| 95 | + grep -vE '^(glibc|libgcc|libstdc\+\+|gcc)$' |
| 96 | + ) |
| 97 | +
|
| 98 | + for pkg in "${pkgs[@]}"; do |
| 99 | + mapfile -t files < <(rpm -q --licensefiles "$pkg" 2>/dev/null || true) |
| 100 | +
|
| 101 | + # Some subpackages leave the licence to a sibling of the same source RPM. |
| 102 | + if [ -z "${files[0]:-}" ]; then |
| 103 | + srpm=$(rpm -q --qf '%{SOURCERPM}\n' "$pkg") |
| 104 | + mapfile -t files < <( |
| 105 | + rpm -qa --qf '%{SOURCERPM} %{NAME}\n' | |
| 106 | + awk -v s="$srpm" '$1 == s { print $2 }' | |
| 107 | + xargs -r rpm -q --licensefiles 2>/dev/null | sort -u |
| 108 | + ) |
| 109 | + fi |
| 110 | +
|
| 111 | + # Others mark it %doc rather than %license, and the image installs no docs. |
| 112 | + if [ -z "${files[0]:-}" ]; then |
| 113 | + dnf -y --disablerepo=extras reinstall --setopt=tsflags= "$pkg" >/dev/null |
| 114 | + mapfile -t files < <(rpm -qd "$pkg" | grep -iE '/(LICEN[CS]E|COPYING|NOTICE)') |
| 115 | + fi |
| 116 | +
|
| 117 | + for f in "${files[@]}"; do |
| 118 | + [ -f "$f" ] || continue |
| 119 | + cp "$f" "$project/LICENSE.${pkg}.$(basename "$f")" |
| 120 | + done |
| 121 | + compgen -G "$project/LICENSE.$pkg.*" >/dev/null || |
| 122 | + { echo "no licence file found for $pkg" >&2; exit 1; } |
| 123 | + done |
| 124 | +
|
| 125 | + ls -1 "$project"/LICENSE.* | sed "s|$project/||" |
| 126 | + COLLECT_EOF |
| 127 | +
|
| 128 | + - name: Build wheels |
| 129 | + uses: pypa/cibuildwheel@1828c10ab37f080699c7b81cea34097c684a7074 # v4.2.0 |
| 130 | + with: |
| 131 | + output-dir: wheelhouse/ |
| 132 | + only: ${{ matrix.python }}-manylinux_riscv64 |
| 133 | + env: |
| 134 | + CIBW_MANYLINUX_RISCV64_IMAGE: ${{ env.MANYLINUX_RISCV64_IMAGE }} |
| 135 | + CIBW_BEFORE_ALL_LINUX: >- |
| 136 | + dnf install -y dbus-devel && |
| 137 | + bash {project}/collect-licenses.sh {project} |
| 138 | + CIBW_TEST_REQUIRES: pytest |
| 139 | + # upstream's suite targets the Plain (mock) backend; only these two are backend-independent |
| 140 | + CIBW_TEST_COMMAND: >- |
| 141 | + pytest -v {project}/simplepyble/test/test_simpleble.py |
| 142 | + -k "test_configuration_parity or test_platform_enums" && |
| 143 | + python -c "import simplepyble; assert simplepyble.get_operating_system() == simplepyble.OperatingSystem.LINUX" |
| 144 | +
|
| 145 | + - name: Verify the wheel ships the extension and every vendored library's licence |
| 146 | + run: | |
| 147 | + python3 - wheelhouse/*.whl <<'EOF' |
| 148 | + import json, sys, zipfile |
| 149 | + z = zipfile.ZipFile(sys.argv[1]) |
| 150 | + names = z.namelist() |
| 151 | + sos = sorted(n for n in names if n.endswith(".so") or ".so." in n) |
| 152 | + print("\n".join(sos)) |
| 153 | + assert any(n.startswith("simplepyble/_simplepyble.") for n in sos), sos |
| 154 | +
|
| 155 | + lic = sorted(n.split("/")[-1] for n in names if ".dist-info/licenses/" in n and not n.endswith("/")) |
| 156 | + print("\n".join(lic)) |
| 157 | + assert "LICENSE.md" in lic, lic |
| 158 | + have_pkgs = {f.split(".", 2)[1] for f in lic if f.startswith("LICENSE.") and f != "LICENSE.md"} |
| 159 | +
|
| 160 | + sbom = next(n for n in names if n.endswith("sboms/auditwheel.cdx.json")) |
| 161 | + vendored = { |
| 162 | + c["purl"].split("/")[2].split("@")[0] |
| 163 | + for c in json.loads(z.read(sbom))["components"] |
| 164 | + if c.get("purl", "").startswith("pkg:rpm/") |
| 165 | + } |
| 166 | + print("vendored:", sorted(vendored)) |
| 167 | + assert "dbus-libs" in vendored, vendored |
| 168 | + assert vendored <= have_pkgs, vendored - have_pkgs |
| 169 | + EOF |
| 170 | +
|
| 171 | + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 172 | + with: |
| 173 | + name: simplepyble-${{ env.SIMPLEPYBLE_VERSION }}-${{ matrix.python }}-manylinux_riscv64 |
| 174 | + path: ./wheelhouse/*.whl |
| 175 | + if-no-files-found: error |
| 176 | + |
| 177 | + gpl_sources: |
| 178 | + needs: [setup] |
| 179 | + if: needs.setup.outputs.versions != '[]' |
| 180 | + strategy: |
| 181 | + fail-fast: false |
| 182 | + matrix: |
| 183 | + version: ${{ fromJSON(needs.setup.outputs.versions) }} |
| 184 | + name: Collect GPL sources for simplepyble ${{ matrix.version }} |
| 185 | + runs-on: ubuntu-24.04-riscv |
| 186 | + |
| 187 | + env: |
| 188 | + SIMPLEPYBLE_VERSION: ${{ matrix.version }} |
| 189 | + |
| 190 | + steps: |
| 191 | + - name: Checkout python-wheels |
| 192 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 193 | + with: |
| 194 | + persist-credentials: false |
| 195 | + |
| 196 | + # dbus-libs/libcap/systemd-libs are the copyleft (GPL/LGPL) libraries auditwheel |
| 197 | + # vendors out of the build image alongside libdbus-1. |
| 198 | + - uses: ./actions/collect-gpl-sources |
| 199 | + with: |
| 200 | + image: ${{ env.MANYLINUX_RISCV64_IMAGE }} |
| 201 | + packages: gcc dbus-libs libcap systemd-libs |
| 202 | + output: gpl-sources.tar |
| 203 | + |
| 204 | + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 205 | + with: |
| 206 | + name: simplepyble-${{ env.SIMPLEPYBLE_VERSION }}-gpl-sources |
| 207 | + path: gpl-sources.tar |
| 208 | + if-no-files-found: error |
| 209 | + |
| 210 | + publish: |
| 211 | + name: Publish simplepyble ${{ matrix.version }} |
| 212 | + needs: [setup, build_wheels, gpl_sources] |
| 213 | + if: needs.setup.outputs.versions != '[]' |
| 214 | + strategy: |
| 215 | + fail-fast: false |
| 216 | + matrix: |
| 217 | + version: ${{ fromJSON(needs.setup.outputs.versions) }} |
| 218 | + permissions: |
| 219 | + contents: write |
| 220 | + pull-requests: write |
| 221 | + uses: $/.github/workflows/_publish-wheel.yml |
| 222 | + secrets: |
| 223 | + app-private-key: ${{ secrets.RISEPROJECT_APP_PRIVATE_KEY }} |
| 224 | + with: |
| 225 | + artifact-pattern: simplepyble-${{ matrix.version }}-*-manylinux_riscv64 |
| 226 | + gpl-sources-artifact: simplepyble-${{ matrix.version }}-gpl-sources |
| 227 | + gpl-sources-description: gcc and the copyleft libraries bundled in the wheel |
0 commit comments