From 2b721b5b354bedad20717b5d1fe03df80112bb21 Mon Sep 17 00:00:00 2001 From: Ryan <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 30 Nov 2026 13:16:06 +1100 Subject: [PATCH 1/8] ci: apple-build-kunit: run only the touched KUnit suites until approval The Apple KUnit matrix runs 16 suites for every push to every PR that touches any of its paths, so one push costs 16 runner jobs and the trusted queue on the shared runners is hours deep. A new plan job reads the PR's changed files through the API (no checkout) and picks the suites whose directories the PR changes. Shared code (include/, rust/, mm/, arm64 configs, Kconfig or Makefile, iommu, pci, power, drivers/soc/apple outside clpc, this workflow) and any unknown path select all suites; nvme, thunderbolt and Apple Wi-Fi are build-only (apple-build compiles them, no suite lives there); files outside this workflow's paths are ignored. The full matrix runs on pushes and dispatches, once the PR is approved (GitHub review decision or an approval at the head), and when the kunit-full label is added. API errors or a truncated file list select the full matrix. apple-build always runs. Labelled events start the workflow only for kunit-full; any other label gets its own concurrency group, so it never cancels a running check. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- .github/workflows/apple-build-kunit.yml | 168 ++++++++++++++++++++---- 1 file changed, 142 insertions(+), 26 deletions(-) diff --git a/.github/workflows/apple-build-kunit.yml b/.github/workflows/apple-build-kunit.yml index 1666013c1f087..bf46ef0e10fcb 100644 --- a/.github/workflows/apple-build-kunit.yml +++ b/.github/workflows/apple-build-kunit.yml @@ -8,9 +8,17 @@ name: Apple build and KUnit # mt7932.kunitconfig (mt7932-kunit.yml), display.kunitconfig # (apple-drm-kunit.yml) and .kunitconfig.pmgr-pwrstate # (pmgr-pwrstate-kunit.yml). +# +# KUnit tiering: on a pull request the plan job picks only the suites whose +# directories the PR changes (shared code such as include/, rust/, mm/, +# configs, Kconfig/Makefile, iommu or this workflow selects all of them). +# The full matrix runs on pushes and dispatches, once the PR is approved, and +# when a maintainer adds the kunit-full label (the merge train does this +# before merging). apple-build always runs. on: pull_request: + types: [opened, synchronize, reopened, labeled] branches: [main, integration/aurora, aurora-wip] paths: - 'arch/arm64/configs/**' @@ -39,6 +47,7 @@ on: - '**/Makefile' - '.github/workflows/apple-build-kunit.yml' pull_request_target: + types: [opened, synchronize, reopened, labeled] branches: [main, integration/aurora, aurora-wip] paths: - 'arch/arm64/configs/**' @@ -101,7 +110,7 @@ permissions: contents: read concurrency: - group: apple-build-kunit-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }} + group: apple-build-kunit-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }}${{ (github.event.action == 'labeled' && github.event.label.name != 'kunit-full') && format('-label-{0}', github.run_id) || '' }} cancel-in-progress: true env: @@ -110,7 +119,7 @@ env: jobs: apple-build: - if: ${{ (github.event_name == 'pull_request_target' && vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]')) || (github.event_name == 'pull_request' && !(vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]'))) || (github.event_name != 'pull_request' && github.event_name != 'pull_request_target') }} + if: ${{ (github.event.action != 'labeled' || github.event.label.name == 'kunit-full') && ((github.event_name == 'pull_request_target' && vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]')) || (github.event_name == 'pull_request' && !(vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]'))) || (github.event_name != 'pull_request' && github.event_name != 'pull_request_target')) }} runs-on: ${{ (vars.AURORA_SELF_HOSTED == 'on' && (github.event_name == 'pull_request_target' || (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')))) && fromJSON('["self-hosted","aurora-buildbox","x64"]') || 'ubuntu-24.04' }} timeout-minutes: 120 steps: @@ -177,37 +186,144 @@ jobs: drivers/thunderbolt/ \ fs/splice.o kernel/sys.o mm/ksm.o mm/madvise.o mm/vma_exec.o + plan: + name: KUnit plan + if: ${{ (github.event.action != 'labeled' || github.event.label.name == 'kunit-full') && ((github.event_name == 'pull_request_target' && vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]')) || (github.event_name == 'pull_request' && !(vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]'))) || (github.event_name != 'pull_request' && github.event_name != 'pull_request_target')) }} + runs-on: ${{ (vars.AURORA_SELF_HOSTED == 'on' && (github.event_name == 'pull_request_target' || (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')))) && fromJSON('["self-hosted","aurora-buildbox","x64"]') || 'ubuntu-24.04' }} + timeout-minutes: 10 + permissions: + contents: read + pull-requests: read + outputs: + matrix: ${{ steps.plan.outputs.matrix }} + count: ${{ steps.plan.outputs.count }} + steps: + # Reads the PR through the API only; no checkout, no PR code runs here. + - name: Pick the KUnit suites for this change + id: plan + env: + GITHUB_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + EVENT: ${{ github.event_name }} + PR: ${{ github.event.pull_request.number }} + HEAD: ${{ github.event.pull_request.head.sha }} + run: | + cat > "$RUNNER_TEMP/plan.py" <<'PLAN' + # KUnit tier planner for apple-build-kunit.yml (embedded in the workflow's plan job). + # Input (env): FILES = changed paths, one per line; FULL = "1" to force the full matrix. + # Output: the matrix JSON on stdout. Unknown or shared paths select the full matrix. + import fnmatch, json, os + SUITES = [ + ("ane-boot", "drivers/accel/ane/boot.kunitconfig", False, ["drivers/accel/ane/"]), + ("ane-pm", "tools/testing/selftests/drivers/ane/pm.kunitconfig", False, ["drivers/accel/ane/", "tools/testing/selftests/drivers/ane/"]), + ("dcp-fabric", "drivers/gpu/drm/apple/tests/.kunitconfig", False, ["drivers/gpu/drm/apple/"]), + ("dcp-topology", "drivers/gpu/drm/apple/tests/topology.kunitconfig", False, ["drivers/gpu/drm/apple/"]), + ("asahi", "drivers/gpu/drm/asahi/.kunitconfig", True, ["drivers/gpu/drm/asahi/"]), + ("spi-hid-apple", "drivers/hid/spi-hid/.kunitconfig", False, ["drivers/hid/spi-hid/"]), + ("avd", "drivers/media/platform/apple/avd/tests/.kunitconfig", False, ["drivers/media/platform/apple/avd/"]), + ("ave", "drivers/media/platform/apple/ave/.kunitconfig", False, ["drivers/media/platform/apple/ave/"]), + ("isp", "drivers/media/platform/apple/isp/.kunitconfig", False, ["drivers/media/platform/apple/isp/"]), + ("jpeg", "drivers/media/platform/apple/jpeg/.kunitconfig", False, ["drivers/media/platform/apple/jpeg/"]), + ("prores", "drivers/media/platform/apple/prores/.kunitconfig", False, ["drivers/media/platform/apple/prores/"]), + ("scaler", "drivers/media/platform/apple/scaler/.kunitconfig", False, ["drivers/media/platform/apple/scaler/"]), + ("macsmc", "drivers/mfd/macsmc.kunitconfig", False, ["drivers/mfd/"]), + ("clpc", "drivers/soc/apple/clpc.kunitconfig", False, ["drivers/soc/apple/clpc"]), + ("apple-spmi-nvmem", "drivers/nvmem/apple-spmi-nvmem.kunitconfig", False, ["drivers/nvmem/"]), + ("trusted-keys", "security/keys/trusted-keys/tests/.kunitconfig", False, ["security/keys/"]), + ] + MEDIA = "drivers/media/platform/apple/" + # The workflow's own trigger paths (on.pull_request.paths). Other files cannot change these suites + # (dt-checks, host-tests and the other workflows cover them), so they are ignored here. + TRIGGERS = ["arch/arm64/configs/", "drivers/accel/ane/", "drivers/gpu/drm/apple/", "drivers/gpu/drm/asahi/", + "drivers/hid/spi-hid/", "drivers/iommu/", "drivers/media/platform/apple/", "drivers/mfd/", + "drivers/net/wireless/apple/", "drivers/nvme/host/", "drivers/nvmem/", "drivers/pci/controller/", + "drivers/power/", "drivers/soc/apple/", "drivers/thunderbolt/", "fs/splice.c", "include/", + "kernel/sys.c", "mm/", "rust/", "security/keys/", "tools/testing/selftests/drivers/ane/", + ".github/workflows/apple-build-kunit.yml"] + # Compiled by the apple-build job; no KUnit suite lives there. + BUILD_ONLY = ["drivers/nvme/host/", "drivers/thunderbolt/", "drivers/net/wireless/apple/"] + + def plan(files, full): + names = set() + for f in files: + base = f.rsplit("/", 1)[-1] + if fnmatch.fnmatch(base, "Kconfig*") or base == "Makefile": + full = True # build configuration: every suite + break + if not any(f.startswith(t) for t in TRIGGERS): + continue # outside this workflow's paths + hit = [s for s, _, _, pre in SUITES if any(f.startswith(p) for p in pre)] + if hit: + names.update(hit) + elif f.startswith(MEDIA): + names.update(s for s, k, _, _ in SUITES if k.startswith(MEDIA)) # shared media code + elif any(f.startswith(p) for p in BUILD_ONLY): + continue + else: + full = True # shared: include/, rust/, mm/, configs, iommu, pci, power, soc/apple (not clpc), this workflow + break + pick = [s for s in SUITES if full or s[0] in names] + return {"include": [dict(suite=s, kunitconfig=k, **({"rust": True} if r else {})) for s, k, r, _ in pick]} + + if __name__ == "__main__": + files = [l.strip() for l in os.environ.get("FILES", "").splitlines() if l.strip()] + full = os.environ.get("FULL") == "1" or not files + print(json.dumps(plan(files, full), separators=(",", ":"))) + PLAN + cat > "$RUNNER_TEMP/files.py" <<'FILES' + # Changed files and the approval state, through the API. Any doubt selects the full matrix. + import json, os, urllib.request + api = os.environ.get("GITHUB_API_URL", "https://api.github.com") + def get(url, body=None): + req = urllib.request.Request(url, data=json.dumps(body).encode() if body else None, headers={ + "Authorization": "Bearer " + os.environ["GITHUB_TOKEN"], "Accept": "application/vnd.github+json"}) + with urllib.request.urlopen(req, timeout=60) as r: + return json.load(r) + full, files = False, [] + if os.environ["EVENT"] not in ("pull_request", "pull_request_target"): + full = True + else: + try: + owner, name = os.environ["REPO"].split("/") + q = ("query($o:String!,$n:String!,$p:Int!){repository(owner:$o,name:$n){pullRequest(number:$p){" + "reviewDecision labels(first:100){nodes{name}} reviews(last:50){nodes{state commit{oid}}}}}}") + pr = get(api + "/graphql", {"query": q, "variables": {"o": owner, "n": name, "p": int(os.environ["PR"])}})["data"]["repository"]["pullRequest"] + if pr["reviewDecision"] == "APPROVED" or "kunit-full" in [l["name"] for l in pr["labels"]["nodes"]] \ + or any(r["state"] == "APPROVED" and (r["commit"] or {}).get("oid") == os.environ["HEAD"] for r in pr["reviews"]["nodes"]): + full = True + else: + for page in range(1, 31): + got = get(f"{api}/repos/{owner}/{name}/pulls/{os.environ['PR']}/files?per_page=100&page={page}") + files += [f["filename"] for f in got] + [f["previous_filename"] for f in got if f.get("previous_filename")] + if len(got) < 100: + break + else: + full = True # 3000+ files: the API list is truncated + except Exception as e: + print(f"::warning::KUnit plan: {e}; running the full matrix") + full = True + t = os.environ["RUNNER_TEMP"] + open(t + "/full", "w").write("1" if full else "0") + open(t + "/files.txt", "w").write("\n".join(files)) + FILES + python3 -I "$RUNNER_TEMP/files.py" + m=$(FULL=$(cat "$RUNNER_TEMP/full") FILES=$(cat "$RUNNER_TEMP/files.txt") python3 -I "$RUNNER_TEMP/plan.py") + n=$(printf '%s' "$m" | python3 -I -c 'import json,sys;print(len(json.load(sys.stdin)["include"]))') + echo "matrix=$m" >> "$GITHUB_OUTPUT" + echo "count=$n" >> "$GITHUB_OUTPUT" + echo "### KUnit plan: $n suite(s)" >> "$GITHUB_STEP_SUMMARY" + printf '%s\n' "$m" | python3 -I -c 'import json,sys;[print("- "+x["suite"]) for x in json.load(sys.stdin)["include"]]' >> "$GITHUB_STEP_SUMMARY" + kunit: name: KUnit ${{ matrix.suite }} - if: ${{ (github.event_name == 'pull_request_target' && vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]')) || (github.event_name == 'pull_request' && !(vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]'))) || (github.event_name != 'pull_request' && github.event_name != 'pull_request_target') }} + needs: plan + if: ${{ needs.plan.outputs.count != '0' && (github.event.action != 'labeled' || github.event.label.name == 'kunit-full') && ((github.event_name == 'pull_request_target' && vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]')) || (github.event_name == 'pull_request' && !(vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]'))) || (github.event_name != 'pull_request' && github.event_name != 'pull_request_target')) }} runs-on: ${{ (vars.AURORA_SELF_HOSTED == 'on' && (github.event_name == 'pull_request_target' || (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')))) && fromJSON('["self-hosted","aurora-buildbox","x64"]') || 'ubuntu-24.04' }} timeout-minutes: 60 strategy: fail-fast: false max-parallel: 4 - matrix: - include: - # boot.kunitconfig runs the same ANE suites as transport.kunitconfig. - # It also sets UBSAN_SHIFT, and KASAN_INLINE is the default, so it - # covers both. - - { suite: ane-boot, kunitconfig: drivers/accel/ane/boot.kunitconfig } - - { suite: ane-pm, kunitconfig: tools/testing/selftests/drivers/ane/pm.kunitconfig } - - { suite: dcp-fabric, kunitconfig: drivers/gpu/drm/apple/tests/.kunitconfig } - - { suite: dcp-topology, kunitconfig: drivers/gpu/drm/apple/tests/topology.kunitconfig } - - { suite: asahi, kunitconfig: drivers/gpu/drm/asahi/.kunitconfig, rust: true } - - { suite: spi-hid-apple, kunitconfig: drivers/hid/spi-hid/.kunitconfig } - # avd-pm.kunitconfig runs the same AVD suites. PM_SLEEP, which it - # adds, is already on by default on arm64. - - { suite: avd, kunitconfig: drivers/media/platform/apple/avd/tests/.kunitconfig } - - { suite: ave, kunitconfig: drivers/media/platform/apple/ave/.kunitconfig } - - { suite: isp, kunitconfig: drivers/media/platform/apple/isp/.kunitconfig } - - { suite: jpeg, kunitconfig: drivers/media/platform/apple/jpeg/.kunitconfig } - - { suite: prores, kunitconfig: drivers/media/platform/apple/prores/.kunitconfig } - - { suite: scaler, kunitconfig: drivers/media/platform/apple/scaler/.kunitconfig } - - { suite: macsmc, kunitconfig: drivers/mfd/macsmc.kunitconfig } - - { suite: clpc, kunitconfig: drivers/soc/apple/clpc.kunitconfig } - - { suite: apple-spmi-nvmem, kunitconfig: drivers/nvmem/apple-spmi-nvmem.kunitconfig } - - { suite: trusted-keys, kunitconfig: security/keys/trusted-keys/tests/.kunitconfig } + matrix: ${{ fromJSON(needs.plan.outputs.matrix) }} steps: - uses: actions/checkout@v4 with: From 3e15f1017b5fa8bfa3aef9c721de28d31420d3de Mon Sep 17 00:00:00 2001 From: Ryan <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 30 Nov 2026 13:20:48 +1100 Subject: [PATCH 2/8] ci: apple-build-kunit: gate merges on a full KUnit run at the head Review: approving a PR started nothing, so a narrow pass stayed the last KUnit result, and nothing required the full matrix before merge. - The plan job sets the commit status "KUnit full matrix" to pending on the PR head for every same-repo run. A final job sets it to success only when a full-matrix run passed for that exact head; a narrow, cancelled or unfinished run leaves it pending, a failing suite sets failure. The readiness bot treats pending as not ready. - An approval of a same-repo PR (pull_request_review) dispatches this workflow from main with the PR number. GITHUB_TOKEN dispatches do start workflows. The dispatch run reads the PR's current head through the API, refuses forks and closed PRs, checks out refs/pull/N/merge, verifies its second parent against that head, runs all suites and records the status. - Fork PRs (the pull_request twin) always run the full matrix and get no gate. Dispatch concurrency groups are per PR, so two approvals do not cancel each other. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- .github/workflows/apple-build-kunit.yml | 145 ++++++++++++++++++------ 1 file changed, 110 insertions(+), 35 deletions(-) diff --git a/.github/workflows/apple-build-kunit.yml b/.github/workflows/apple-build-kunit.yml index bf46ef0e10fcb..477303d2a9806 100644 --- a/.github/workflows/apple-build-kunit.yml +++ b/.github/workflows/apple-build-kunit.yml @@ -9,12 +9,14 @@ name: Apple build and KUnit # (apple-drm-kunit.yml) and .kunitconfig.pmgr-pwrstate # (pmgr-pwrstate-kunit.yml). # -# KUnit tiering: on a pull request the plan job picks only the suites whose -# directories the PR changes (shared code such as include/, rust/, mm/, -# configs, Kconfig/Makefile, iommu or this workflow selects all of them). -# The full matrix runs on pushes and dispatches, once the PR is approved, and -# when a maintainer adds the kunit-full label (the merge train does this -# before merging). apple-build always runs. +# KUnit tiering (same-repo PRs): the plan job picks only the suites whose +# directories the PR changes; shared code (include/, rust/, mm/, configs, +# Kconfig/Makefile, iommu, soc/apple, this workflow) or any doubt selects all +# of them. The commit status "KUnit full matrix" on the PR head stays pending +# until a full-matrix run passes for that exact head. A full run happens when +# the PR is approved (the review starts a dispatch of this workflow for the +# PR), on a push to an approved PR, or when the kunit-full label is added. +# Fork PRs, pushes and plain dispatches always run the full matrix. on: pull_request: @@ -104,13 +106,21 @@ on: - '**/Kconfig*' - '**/Makefile' - '.github/workflows/apple-build-kunit.yml' + # An approval asks for the full matrix of a same-repo PR (request-full job). + pull_request_review: + types: [submitted] workflow_dispatch: + inputs: + pr: + description: Same-repo pull request to run the full KUnit matrix for (empty = this branch) + required: false + default: '' permissions: contents: read concurrency: - group: apple-build-kunit-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }}${{ (github.event.action == 'labeled' && github.event.label.name != 'kunit-full') && format('-label-{0}', github.run_id) || '' }} + group: apple-build-kunit-${{ github.event_name }}-${{ github.event.pull_request.number || inputs.pr || github.ref }}${{ (github.event.action == 'labeled' && github.event.label.name != 'kunit-full') && format('-label-{0}', github.run_id) || '' }} cancel-in-progress: true env: @@ -119,7 +129,7 @@ env: jobs: apple-build: - if: ${{ (github.event.action != 'labeled' || github.event.label.name == 'kunit-full') && ((github.event_name == 'pull_request_target' && vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]')) || (github.event_name == 'pull_request' && !(vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]'))) || (github.event_name != 'pull_request' && github.event_name != 'pull_request_target')) }} + if: ${{ github.event_name != 'pull_request_review' && (github.event.action != 'labeled' || github.event.label.name == 'kunit-full') && (github.event_name != 'workflow_dispatch' || inputs.pr == '') && ((github.event_name == 'pull_request_target' && vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]')) || (github.event_name == 'pull_request' && !(vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]'))) || (github.event_name != 'pull_request' && github.event_name != 'pull_request_target')) }} runs-on: ${{ (vars.AURORA_SELF_HOSTED == 'on' && (github.event_name == 'pull_request_target' || (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')))) && fromJSON('["self-hosted","aurora-buildbox","x64"]') || 'ubuntu-24.04' }} timeout-minutes: 120 steps: @@ -188,17 +198,22 @@ jobs: plan: name: KUnit plan - if: ${{ (github.event.action != 'labeled' || github.event.label.name == 'kunit-full') && ((github.event_name == 'pull_request_target' && vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]')) || (github.event_name == 'pull_request' && !(vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]'))) || (github.event_name != 'pull_request' && github.event_name != 'pull_request_target')) }} + if: ${{ github.event_name != 'pull_request_review' && (github.event.action != 'labeled' || github.event.label.name == 'kunit-full') && ((github.event_name == 'pull_request_target' && vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]')) || (github.event_name == 'pull_request' && !(vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]'))) || (github.event_name != 'pull_request' && github.event_name != 'pull_request_target')) }} runs-on: ${{ (vars.AURORA_SELF_HOSTED == 'on' && (github.event_name == 'pull_request_target' || (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')))) && fromJSON('["self-hosted","aurora-buildbox","x64"]') || 'ubuntu-24.04' }} timeout-minutes: 10 permissions: contents: read pull-requests: read + statuses: write outputs: matrix: ${{ steps.plan.outputs.matrix }} count: ${{ steps.plan.outputs.count }} + full: ${{ steps.plan.outputs.full }} + pr: ${{ steps.plan.outputs.pr }} + head: ${{ steps.plan.outputs.head }} + gate: ${{ steps.plan.outputs.gate }} steps: - # Reads the PR through the API only; no checkout, no PR code runs here. + # Reads the PR through the API only; no checkout, no PR code runs in this job. - name: Pick the KUnit suites for this change id: plan env: @@ -207,6 +222,7 @@ jobs: EVENT: ${{ github.event_name }} PR: ${{ github.event.pull_request.number }} HEAD: ${{ github.event.pull_request.head.sha }} + INPUT_PR: ${{ inputs.pr }} run: | cat > "$RUNNER_TEMP/plan.py" <<'PLAN' # KUnit tier planner for apple-build-kunit.yml (embedded in the workflow's plan job). @@ -271,7 +287,7 @@ jobs: print(json.dumps(plan(files, full), separators=(",", ":"))) PLAN cat > "$RUNNER_TEMP/files.py" <<'FILES' - # Changed files and the approval state, through the API. Any doubt selects the full matrix. + # Mode, PR head and changed files, through the API. Any doubt selects the full matrix. import json, os, urllib.request api = os.environ.get("GITHUB_API_URL", "https://api.github.com") def get(url, body=None): @@ -279,45 +295,60 @@ jobs: "Authorization": "Bearer " + os.environ["GITHUB_TOKEN"], "Accept": "application/vnd.github+json"}) with urllib.request.urlopen(req, timeout=60) as r: return json.load(r) - full, files = False, [] - if os.environ["EVENT"] not in ("pull_request", "pull_request_target"): - full = True - else: + ev, repo, t = os.environ["EVENT"], os.environ["REPO"], os.environ["RUNNER_TEMP"] + owner, name = repo.split("/") + full, files, pr, head, gate = True, [], "", "", "0" + if ev == "pull_request_target": + pr, head, gate = os.environ["PR"], os.environ["HEAD"], "1" try: - owner, name = os.environ["REPO"].split("/") q = ("query($o:String!,$n:String!,$p:Int!){repository(owner:$o,name:$n){pullRequest(number:$p){" "reviewDecision labels(first:100){nodes{name}} reviews(last:50){nodes{state commit{oid}}}}}}") - pr = get(api + "/graphql", {"query": q, "variables": {"o": owner, "n": name, "p": int(os.environ["PR"])}})["data"]["repository"]["pullRequest"] - if pr["reviewDecision"] == "APPROVED" or "kunit-full" in [l["name"] for l in pr["labels"]["nodes"]] \ - or any(r["state"] == "APPROVED" and (r["commit"] or {}).get("oid") == os.environ["HEAD"] for r in pr["reviews"]["nodes"]): - full = True - else: + d = get(api + "/graphql", {"query": q, "variables": {"o": owner, "n": name, "p": int(pr)}})["data"]["repository"]["pullRequest"] + if not (d["reviewDecision"] == "APPROVED" or "kunit-full" in [l["name"] for l in d["labels"]["nodes"]] + or any(r["state"] == "APPROVED" and (r["commit"] or {}).get("oid") == head for r in d["reviews"]["nodes"])): for page in range(1, 31): - got = get(f"{api}/repos/{owner}/{name}/pulls/{os.environ['PR']}/files?per_page=100&page={page}") + got = get(f"{api}/repos/{repo}/pulls/{pr}/files?per_page=100&page={page}") files += [f["filename"] for f in got] + [f["previous_filename"] for f in got if f.get("previous_filename")] if len(got) < 100: + full = False break - else: - full = True # 3000+ files: the API list is truncated except Exception as e: print(f"::warning::KUnit plan: {e}; running the full matrix") - full = True - t = os.environ["RUNNER_TEMP"] - open(t + "/full", "w").write("1" if full else "0") - open(t + "/files.txt", "w").write("\n".join(files)) + full, files = True, [] + elif ev == "workflow_dispatch" and os.environ.get("INPUT_PR"): + # A full run for a same-repo PR (requested by an approval or by hand); forks are refused. + p = get(f"{api}/repos/{repo}/pulls/{int(os.environ['INPUT_PR'])}") + if p["state"] != "open" or (p["head"]["repo"] or {}).get("full_name") != repo: + raise SystemExit(f"::error::PR {p['number']} is not an open same-repo pull request") + pr, head, gate = str(p["number"]), p["head"]["sha"], "1" + for k, v in (("full", "1" if full else "0"), ("files.txt", "\n".join(files)), ("pr", pr), ("head", head), ("gate", gate)): + open(f"{t}/{k}", "w").write(v) FILES python3 -I "$RUNNER_TEMP/files.py" m=$(FULL=$(cat "$RUNNER_TEMP/full") FILES=$(cat "$RUNNER_TEMP/files.txt") python3 -I "$RUNNER_TEMP/plan.py") n=$(printf '%s' "$m" | python3 -I -c 'import json,sys;print(len(json.load(sys.stdin)["include"]))') - echo "matrix=$m" >> "$GITHUB_OUTPUT" - echo "count=$n" >> "$GITHUB_OUTPUT" + { echo "matrix=$m"; echo "count=$n"; echo "full=$(cat "$RUNNER_TEMP/full")" + echo "pr=$(cat "$RUNNER_TEMP/pr")"; echo "head=$(cat "$RUNNER_TEMP/head")"; echo "gate=$(cat "$RUNNER_TEMP/gate")"; } >> "$GITHUB_OUTPUT" echo "### KUnit plan: $n suite(s)" >> "$GITHUB_STEP_SUMMARY" printf '%s\n' "$m" | python3 -I -c 'import json,sys;[print("- "+x["suite"]) for x in json.load(sys.stdin)["include"]]' >> "$GITHUB_STEP_SUMMARY" + - name: Mark the full matrix pending for this head + env: + GITHUB_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + GATE: ${{ steps.plan.outputs.gate }} + HEAD: ${{ steps.plan.outputs.head }} + STATE: pending + DESC: ${{ steps.plan.outputs.full == '1' && 'Full matrix running' || 'Narrow run; the full matrix runs on approval or kunit-full' }} + run: | + [ "$GATE" = 1 ] || exit 0 + curl -fsS -X POST -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" \ + "$GITHUB_API_URL/repos/$REPO/statuses/$HEAD" \ + -d "{\"state\":\"$STATE\",\"context\":\"KUnit full matrix\",\"description\":\"$DESC\",\"target_url\":\"$GITHUB_SERVER_URL/$REPO/actions/runs/$GITHUB_RUN_ID\"}" >/dev/null kunit: name: KUnit ${{ matrix.suite }} needs: plan - if: ${{ needs.plan.outputs.count != '0' && (github.event.action != 'labeled' || github.event.label.name == 'kunit-full') && ((github.event_name == 'pull_request_target' && vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]')) || (github.event_name == 'pull_request' && !(vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]'))) || (github.event_name != 'pull_request' && github.event_name != 'pull_request_target')) }} + if: ${{ needs.plan.outputs.count != '0' && github.event_name != 'pull_request_review' && (github.event.action != 'labeled' || github.event.label.name == 'kunit-full') && ((github.event_name == 'pull_request_target' && vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]')) || (github.event_name == 'pull_request' && !(vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]'))) || (github.event_name != 'pull_request' && github.event_name != 'pull_request_target')) }} runs-on: ${{ (vars.AURORA_SELF_HOSTED == 'on' && (github.event_name == 'pull_request_target' || (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')))) && fromJSON('["self-hosted","aurora-buildbox","x64"]') || 'ubuntu-24.04' }} timeout-minutes: 60 strategy: @@ -327,16 +358,16 @@ jobs: steps: - uses: actions/checkout@v4 with: - ref: ${{ github.event_name == 'pull_request_target' && format('refs/pull/{0}/merge', github.event.pull_request.number) || '' }} + ref: ${{ needs.plan.outputs.pr != '' && format('refs/pull/{0}/merge', needs.plan.outputs.pr) || '' }} persist-credentials: false fetch-depth: 1 - name: Verify the PR merge ref matches this event - if: github.event_name == 'pull_request_target' + if: needs.plan.outputs.pr != '' env: - WANT: ${{ github.event.pull_request.head.sha }} + WANT: ${{ needs.plan.outputs.head }} run: | got=$(git cat-file -p HEAD | sed -n 's/^parent //p' | sed -n 2p) - [ "$got" = "$WANT" ] || { echo "::error::refs/pull merge ref is for head $got, this event is for $WANT (the PR moved or this is a stale re-run; the newest run covers the current head)"; exit 1; } + [ "$got" = "$WANT" ] || { echo "::error::refs/pull merge ref is for head $got, this run is for $WANT (the PR moved or this is a stale re-run; the newest run covers the current head)"; exit 1; } - name: Install kernel build and QEMU dependencies run: | # As sep-source.yml: avoid the hosted runner's Azure mirror. @@ -364,3 +395,47 @@ jobs: --make_options LLVM=1 \ --kunitconfig="$KUNITCONFIG" \ --jobs="$(nproc)" --timeout=900 + + kunit-full: + name: Record KUnit full matrix + needs: [plan, kunit] + # Records the result for the PR head; never runs PR code. + if: ${{ always() && needs.plan.result == 'success' && needs.plan.outputs.gate == '1' }} + runs-on: ${{ (vars.AURORA_SELF_HOSTED == 'on' && (github.event_name == 'pull_request_target' || (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')))) && fromJSON('["self-hosted","aurora-buildbox","x64"]') || 'ubuntu-24.04' }} + timeout-minutes: 10 + permissions: + statuses: write + steps: + - name: Record the KUnit result for this head + env: + GITHUB_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + GATE: '1' + HEAD: ${{ needs.plan.outputs.head }} + STATE: ${{ (needs.plan.outputs.full == '1' && needs.kunit.result == 'success') && 'success' || (needs.kunit.result == 'failure' && 'failure' || 'pending') }} + DESC: ${{ (needs.plan.outputs.full == '1' && needs.kunit.result == 'success') && 'All suites passed at this head' || (needs.kunit.result == 'failure' && 'A suite failed' || (needs.plan.outputs.full == '1' && 'Full run did not finish; re-run it' || 'Narrow run; the full matrix runs on approval or kunit-full')) }} + run: | + [ "$GATE" = 1 ] || exit 0 + curl -fsS -X POST -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" \ + "$GITHUB_API_URL/repos/$REPO/statuses/$HEAD" \ + -d "{\"state\":\"$STATE\",\"context\":\"KUnit full matrix\",\"description\":\"$DESC\",\"target_url\":\"$GITHUB_SERVER_URL/$REPO/actions/runs/$GITHUB_RUN_ID\"}" >/dev/null + + request-full: + name: Request the full KUnit matrix + # An approval of a same-repo PR dispatches this workflow from main for the PR (GITHUB_TOKEN + # dispatches do start workflows). Forks always run the full matrix and need no request. + if: ${{ github.event_name == 'pull_request_review' && github.event.review.state == 'approved' && github.event.pull_request.head.repo.full_name == github.repository }} + runs-on: ubuntu-24.04 + timeout-minutes: 5 + permissions: + actions: write + steps: + - env: + GITHUB_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + PR: ${{ github.event.pull_request.number }} + BRANCH: ${{ github.event.repository.default_branch }} + run: | + curl -fsS -X POST -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" \ + "$GITHUB_API_URL/repos/$REPO/actions/workflows/apple-build-kunit.yml/dispatches" \ + -d "{\"ref\":\"$BRANCH\",\"inputs\":{\"pr\":\"$PR\"}}" From 550fe8374addbbaa454703ca36e816cd4bee72ea Mon Sep 17 00:00:00 2001 From: Ryan <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 30 Nov 2026 13:23:05 +1100 Subject: [PATCH 3/8] ci: apple-build-kunit: a late narrow run never takes back a full pass Review: the narrow PR run and the dispatched full run are in different concurrency groups and can finish in either order, so a slow narrow run could write pending over a full pass for the same head. Pending writes (the plan job's and the final job's) now read the head's statuses first and keep an existing "KUnit full matrix" success. Only a full run records failure; a narrow run's failing suite shows in its own check and leaves the status pending. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- .github/workflows/apple-build-kunit.yml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/apple-build-kunit.yml b/.github/workflows/apple-build-kunit.yml index 477303d2a9806..80a1b7b6b9b65 100644 --- a/.github/workflows/apple-build-kunit.yml +++ b/.github/workflows/apple-build-kunit.yml @@ -341,6 +341,13 @@ jobs: DESC: ${{ steps.plan.outputs.full == '1' && 'Full matrix running' || 'Narrow run; the full matrix runs on approval or kunit-full' }} run: | [ "$GATE" = 1 ] || exit 0 + if [ "$STATE" = pending ]; then + # A narrow or late run never takes back a full pass already recorded for this head. + last=$(curl -fsS -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" \ + "$GITHUB_API_URL/repos/$REPO/commits/$HEAD/statuses?per_page=100" | + python3 -I -c 'import json,sys;print(next((x["state"] for x in json.load(sys.stdin) if x["context"]=="KUnit full matrix"),""))') + [ "$last" = success ] && { echo "full matrix already passed at $HEAD; keeping it"; exit 0; } + fi curl -fsS -X POST -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" \ "$GITHUB_API_URL/repos/$REPO/statuses/$HEAD" \ -d "{\"state\":\"$STATE\",\"context\":\"KUnit full matrix\",\"description\":\"$DESC\",\"target_url\":\"$GITHUB_SERVER_URL/$REPO/actions/runs/$GITHUB_RUN_ID\"}" >/dev/null @@ -412,10 +419,17 @@ jobs: REPO: ${{ github.repository }} GATE: '1' HEAD: ${{ needs.plan.outputs.head }} - STATE: ${{ (needs.plan.outputs.full == '1' && needs.kunit.result == 'success') && 'success' || (needs.kunit.result == 'failure' && 'failure' || 'pending') }} - DESC: ${{ (needs.plan.outputs.full == '1' && needs.kunit.result == 'success') && 'All suites passed at this head' || (needs.kunit.result == 'failure' && 'A suite failed' || (needs.plan.outputs.full == '1' && 'Full run did not finish; re-run it' || 'Narrow run; the full matrix runs on approval or kunit-full')) }} + STATE: ${{ needs.plan.outputs.full == '1' && (needs.kunit.result == 'success' && 'success' || (needs.kunit.result == 'failure' && 'failure' || 'pending')) || 'pending' }} + DESC: ${{ needs.plan.outputs.full == '1' && (needs.kunit.result == 'success' && 'All suites passed at this head' || (needs.kunit.result == 'failure' && 'A suite failed in the full run' || 'Full run did not finish; re-run it')) || 'Narrow run; the full matrix runs on approval or kunit-full' }} run: | [ "$GATE" = 1 ] || exit 0 + if [ "$STATE" = pending ]; then + # A narrow or late run never takes back a full pass already recorded for this head. + last=$(curl -fsS -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" \ + "$GITHUB_API_URL/repos/$REPO/commits/$HEAD/statuses?per_page=100" | + python3 -I -c 'import json,sys;print(next((x["state"] for x in json.load(sys.stdin) if x["context"]=="KUnit full matrix"),""))') + [ "$last" = success ] && { echo "full matrix already passed at $HEAD; keeping it"; exit 0; } + fi curl -fsS -X POST -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" \ "$GITHUB_API_URL/repos/$REPO/statuses/$HEAD" \ -d "{\"state\":\"$STATE\",\"context\":\"KUnit full matrix\",\"description\":\"$DESC\",\"target_url\":\"$GITHUB_SERVER_URL/$REPO/actions/runs/$GITHUB_RUN_ID\"}" >/dev/null From c1360daf2ee4ca21992e141d670ffafae0d02048 Mon Sep 17 00:00:00 2001 From: Ryan <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 30 Nov 2026 13:26:38 +1100 Subject: [PATCH 4/8] ci: apple-build-kunit: one owner for the full-matrix status per head Review: a read-then-write across independent runs can interleave, so a narrow run could read pending, a full run post success, and the narrow run then post pending over it. Full runs now own "KUnit full matrix": they write pending when they start (keeping an existing pass) and their outcome when they finish. A narrow run writes nothing at the end, and at the start only marks a head that has no status yet. Any status means a full run has started, and a full pass is always preceded by that run's own pending write, so a full pass cannot land between a narrow run's read and its write. Two full runs racing on one head can at worst leave pending until the later one reports (fails closed). Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- .github/workflows/apple-build-kunit.yml | 33 ++++++++++++++++--------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/.github/workflows/apple-build-kunit.yml b/.github/workflows/apple-build-kunit.yml index 80a1b7b6b9b65..b021012792cc4 100644 --- a/.github/workflows/apple-build-kunit.yml +++ b/.github/workflows/apple-build-kunit.yml @@ -338,15 +338,19 @@ jobs: GATE: ${{ steps.plan.outputs.gate }} HEAD: ${{ steps.plan.outputs.head }} STATE: pending + MODE: ${{ steps.plan.outputs.full == '1' && 'keep-success' || 'first' }} DESC: ${{ steps.plan.outputs.full == '1' && 'Full matrix running' || 'Narrow run; the full matrix runs on approval or kunit-full' }} run: | [ "$GATE" = 1 ] || exit 0 - if [ "$STATE" = pending ]; then - # A narrow or late run never takes back a full pass already recorded for this head. + # One owner per head: full runs own the result (pending at start, then the outcome). A narrow run + # only marks a head that has no status yet; any status means a full run has started and owns it. + # A full run never takes back a pass for this head when it starts. + if [ "$MODE" != terminal ]; then last=$(curl -fsS -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" \ "$GITHUB_API_URL/repos/$REPO/commits/$HEAD/statuses?per_page=100" | - python3 -I -c 'import json,sys;print(next((x["state"] for x in json.load(sys.stdin) if x["context"]=="KUnit full matrix"),""))') - [ "$last" = success ] && { echo "full matrix already passed at $HEAD; keeping it"; exit 0; } + python3 -I -c 'import json,sys;print(next((x["state"] for x in json.load(sys.stdin) if x["context"]=="KUnit full matrix"),"none"))') + if [ "$MODE" = first ] && [ "$last" != none ]; then echo "a full run owns the status at $HEAD ($last)"; exit 0; fi + if [ "$last" = success ]; then echo "full matrix already passed at $HEAD; keeping it"; exit 0; fi fi curl -fsS -X POST -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" \ "$GITHUB_API_URL/repos/$REPO/statuses/$HEAD" \ @@ -407,7 +411,7 @@ jobs: name: Record KUnit full matrix needs: [plan, kunit] # Records the result for the PR head; never runs PR code. - if: ${{ always() && needs.plan.result == 'success' && needs.plan.outputs.gate == '1' }} + if: ${{ always() && needs.plan.result == 'success' && needs.plan.outputs.gate == '1' && needs.plan.outputs.full == '1' }} runs-on: ${{ (vars.AURORA_SELF_HOSTED == 'on' && (github.event_name == 'pull_request_target' || (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')))) && fromJSON('["self-hosted","aurora-buildbox","x64"]') || 'ubuntu-24.04' }} timeout-minutes: 10 permissions: @@ -417,18 +421,23 @@ jobs: env: GITHUB_TOKEN: ${{ github.token }} REPO: ${{ github.repository }} - GATE: '1' + # Narrow runs write nothing here; the full run that owns the head records its outcome. + GATE: ${{ needs.plan.outputs.full == '1' && '1' || '0' }} + MODE: terminal HEAD: ${{ needs.plan.outputs.head }} - STATE: ${{ needs.plan.outputs.full == '1' && (needs.kunit.result == 'success' && 'success' || (needs.kunit.result == 'failure' && 'failure' || 'pending')) || 'pending' }} - DESC: ${{ needs.plan.outputs.full == '1' && (needs.kunit.result == 'success' && 'All suites passed at this head' || (needs.kunit.result == 'failure' && 'A suite failed in the full run' || 'Full run did not finish; re-run it')) || 'Narrow run; the full matrix runs on approval or kunit-full' }} + STATE: ${{ needs.kunit.result == 'success' && 'success' || (needs.kunit.result == 'failure' && 'failure' || 'pending') }} + DESC: ${{ needs.kunit.result == 'success' && 'All suites passed at this head' || (needs.kunit.result == 'failure' && 'A suite failed in the full run' || 'Full run did not finish; re-run it') }} run: | [ "$GATE" = 1 ] || exit 0 - if [ "$STATE" = pending ]; then - # A narrow or late run never takes back a full pass already recorded for this head. + # One owner per head: full runs own the result (pending at start, then the outcome). A narrow run + # only marks a head that has no status yet; any status means a full run has started and owns it. + # A full run never takes back a pass for this head when it starts. + if [ "$MODE" != terminal ]; then last=$(curl -fsS -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" \ "$GITHUB_API_URL/repos/$REPO/commits/$HEAD/statuses?per_page=100" | - python3 -I -c 'import json,sys;print(next((x["state"] for x in json.load(sys.stdin) if x["context"]=="KUnit full matrix"),""))') - [ "$last" = success ] && { echo "full matrix already passed at $HEAD; keeping it"; exit 0; } + python3 -I -c 'import json,sys;print(next((x["state"] for x in json.load(sys.stdin) if x["context"]=="KUnit full matrix"),"none"))') + if [ "$MODE" = first ] && [ "$last" != none ]; then echo "a full run owns the status at $HEAD ($last)"; exit 0; fi + if [ "$last" = success ]; then echo "full matrix already passed at $HEAD; keeping it"; exit 0; fi fi curl -fsS -X POST -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" \ "$GITHUB_API_URL/repos/$REPO/statuses/$HEAD" \ From eeaf0155588d6105eb919c8853120d3d10c8f20b Mon Sep 17 00:00:00 2001 From: Ryan <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 30 Nov 2026 13:28:42 +1100 Subject: [PATCH 5/8] ci: apple-build-kunit: trusted approvals only, no self-cancelling runs From an independent review of the gate: - Only approvals by owners, members or collaborators dispatch the full matrix; anyone can submit an approving review on a public repository, which would have started self-hosted runs at will. - Review-triggered runs get a per-run concurrency group, so a later review cannot cancel an approval's run before it dispatches. - kunit-full label runs get their own group, so adding the label does not cancel the PR's in-flight run (a cancelled check reads as failing to the readiness bot). - Dispatched runs are named after the PR (run-name and job names), so their checks on main's tip are not mistaken for main's own KUnit. - Files outside the trigger paths now select all suites unless they are known to be unrelated (DT sources, Documentation, other workflows' tests and tools, .github), so shared code such as lib/, kernel/ or the KUnit tooling is not skipped. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- .github/workflows/apple-build-kunit.yml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/apple-build-kunit.yml b/.github/workflows/apple-build-kunit.yml index b021012792cc4..ae92af7ca6eea 100644 --- a/.github/workflows/apple-build-kunit.yml +++ b/.github/workflows/apple-build-kunit.yml @@ -1,4 +1,5 @@ name: Apple build and KUnit +run-name: ${{ inputs.pr != '' && format('Apple KUnit full matrix for PR {0}', inputs.pr) || '' }} # Compiles every Apple driver directory with the configuration a Mac runs # (arm64 defconfig plus asahi.config, LLVM=1 and Rust), and runs each Apple @@ -120,7 +121,7 @@ permissions: contents: read concurrency: - group: apple-build-kunit-${{ github.event_name }}-${{ github.event.pull_request.number || inputs.pr || github.ref }}${{ (github.event.action == 'labeled' && github.event.label.name != 'kunit-full') && format('-label-{0}', github.run_id) || '' }} + group: apple-build-kunit-${{ github.event_name }}-${{ github.event.pull_request.number || inputs.pr || github.ref }}${{ ((github.event.action == 'labeled' && github.event.label.name != 'kunit-full') || github.event_name == 'pull_request_review') && format('-{0}', github.run_id) || (github.event.action == 'labeled' && '-full' || '') }} cancel-in-progress: true env: @@ -256,6 +257,9 @@ jobs: "drivers/power/", "drivers/soc/apple/", "drivers/thunderbolt/", "fs/splice.c", "include/", "kernel/sys.c", "mm/", "rust/", "security/keys/", "tools/testing/selftests/drivers/ane/", ".github/workflows/apple-build-kunit.yml"] + # Outside the trigger paths and unable to change these suites (DT, docs, other workflows' tests and tools). + UNRELATED = ["arch/arm64/boot/dts/", "Documentation/", "tools/testing/selftests/drivers/gpu/", + "tools/aurora-sep/", "tools/aurora-diag/", "scripts/dtc/", "MAINTAINERS", ".github/"] # Compiled by the apple-build job; no KUnit suite lives there. BUILD_ONLY = ["drivers/nvme/host/", "drivers/thunderbolt/", "drivers/net/wireless/apple/"] @@ -267,7 +271,10 @@ jobs: full = True # build configuration: every suite break if not any(f.startswith(t) for t in TRIGGERS): - continue # outside this workflow's paths + if any(f.startswith(u) for u in UNRELATED): + continue # checked by other workflows; cannot change these suites + full = True # shared code outside the trigger paths (lib/, kernel/, drivers/base, kunit tooling, ...) + break hit = [s for s, _, _, pre in SUITES if any(f.startswith(p) for p in pre)] if hit: names.update(hit) @@ -357,7 +364,7 @@ jobs: -d "{\"state\":\"$STATE\",\"context\":\"KUnit full matrix\",\"description\":\"$DESC\",\"target_url\":\"$GITHUB_SERVER_URL/$REPO/actions/runs/$GITHUB_RUN_ID\"}" >/dev/null kunit: - name: KUnit ${{ matrix.suite }} + name: ${{ inputs.pr != '' && format('PR {0} KUnit {1}', inputs.pr, matrix.suite) || format('KUnit {0}', matrix.suite) }} needs: plan if: ${{ needs.plan.outputs.count != '0' && github.event_name != 'pull_request_review' && (github.event.action != 'labeled' || github.event.label.name == 'kunit-full') && ((github.event_name == 'pull_request_target' && vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]')) || (github.event_name == 'pull_request' && !(vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]'))) || (github.event_name != 'pull_request' && github.event_name != 'pull_request_target')) }} runs-on: ${{ (vars.AURORA_SELF_HOSTED == 'on' && (github.event_name == 'pull_request_target' || (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')))) && fromJSON('["self-hosted","aurora-buildbox","x64"]') || 'ubuntu-24.04' }} @@ -447,7 +454,7 @@ jobs: name: Request the full KUnit matrix # An approval of a same-repo PR dispatches this workflow from main for the PR (GITHUB_TOKEN # dispatches do start workflows). Forks always run the full matrix and need no request. - if: ${{ github.event_name == 'pull_request_review' && github.event.review.state == 'approved' && github.event.pull_request.head.repo.full_name == github.repository }} + if: ${{ github.event_name == 'pull_request_review' && github.event.review.state == 'approved' && github.event.pull_request.head.repo.full_name == github.repository && contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.review.author_association) }} runs-on: ubuntu-24.04 timeout-minutes: 5 permissions: From 44654d5993692d1431232e58040fedf26fff4c7f Mon Sep 17 00:00:00 2001 From: Ryan <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 30 Nov 2026 14:25:30 +1100 Subject: [PATCH 6/8] ci: apple-build-kunit: drop the status gate; the merge train asks for the full run Decision on the gate: the full-matrix commit status, the approval dispatch and the recorder job are removed. linux has no required checks, so a status cannot gate merges by itself, and serializing its writers across runs needs more machinery than it is worth. Instead the merge train adds the kunit-full label with a maintainer token before merging a linux PR and waits for all 16 KUnit suites to pass at the head. kunit-full runs get their own concurrency group, so the label does not cancel the PR's in-flight run. Unapproved same-repo PRs still run only their suites; pushes, dispatches, fork PRs, pushes to approved PRs and API doubt run the full matrix. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- .github/workflows/apple-build-kunit.yml | 149 ++++-------------------- 1 file changed, 23 insertions(+), 126 deletions(-) diff --git a/.github/workflows/apple-build-kunit.yml b/.github/workflows/apple-build-kunit.yml index ae92af7ca6eea..c20ef8e499f84 100644 --- a/.github/workflows/apple-build-kunit.yml +++ b/.github/workflows/apple-build-kunit.yml @@ -1,5 +1,4 @@ name: Apple build and KUnit -run-name: ${{ inputs.pr != '' && format('Apple KUnit full matrix for PR {0}', inputs.pr) || '' }} # Compiles every Apple driver directory with the configuration a Mac runs # (arm64 defconfig plus asahi.config, LLVM=1 and Rust), and runs each Apple @@ -12,12 +11,11 @@ run-name: ${{ inputs.pr != '' && format('Apple KUnit full matrix for PR {0}', in # # KUnit tiering (same-repo PRs): the plan job picks only the suites whose # directories the PR changes; shared code (include/, rust/, mm/, configs, -# Kconfig/Makefile, iommu, soc/apple, this workflow) or any doubt selects all -# of them. The commit status "KUnit full matrix" on the PR head stays pending -# until a full-matrix run passes for that exact head. A full run happens when -# the PR is approved (the review starts a dispatch of this workflow for the -# PR), on a push to an approved PR, or when the kunit-full label is added. -# Fork PRs, pushes and plain dispatches always run the full matrix. +# Kconfig/Makefile, iommu, soc/apple, lib/, kernel/, this workflow) or any +# doubt selects all of them. The full matrix runs on pushes, dispatches and +# fork PRs, on a push to an approved PR, and when the kunit-full label is +# added. The merge train adds kunit-full (with a maintainer token, so the +# label event starts this workflow) and waits for it to pass before merging. on: pull_request: @@ -107,21 +105,13 @@ on: - '**/Kconfig*' - '**/Makefile' - '.github/workflows/apple-build-kunit.yml' - # An approval asks for the full matrix of a same-repo PR (request-full job). - pull_request_review: - types: [submitted] workflow_dispatch: - inputs: - pr: - description: Same-repo pull request to run the full KUnit matrix for (empty = this branch) - required: false - default: '' permissions: contents: read concurrency: - group: apple-build-kunit-${{ github.event_name }}-${{ github.event.pull_request.number || inputs.pr || github.ref }}${{ ((github.event.action == 'labeled' && github.event.label.name != 'kunit-full') || github.event_name == 'pull_request_review') && format('-{0}', github.run_id) || (github.event.action == 'labeled' && '-full' || '') }} + group: apple-build-kunit-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }}${{ github.event.action == 'labeled' && (github.event.label.name == 'kunit-full' && '-full' || format('-{0}', github.run_id)) || '' }} cancel-in-progress: true env: @@ -130,7 +120,7 @@ env: jobs: apple-build: - if: ${{ github.event_name != 'pull_request_review' && (github.event.action != 'labeled' || github.event.label.name == 'kunit-full') && (github.event_name != 'workflow_dispatch' || inputs.pr == '') && ((github.event_name == 'pull_request_target' && vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]')) || (github.event_name == 'pull_request' && !(vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]'))) || (github.event_name != 'pull_request' && github.event_name != 'pull_request_target')) }} + if: ${{ (github.event.action != 'labeled' || github.event.label.name == 'kunit-full') && ((github.event_name == 'pull_request_target' && vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]')) || (github.event_name == 'pull_request' && !(vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]'))) || (github.event_name != 'pull_request' && github.event_name != 'pull_request_target')) }} runs-on: ${{ (vars.AURORA_SELF_HOSTED == 'on' && (github.event_name == 'pull_request_target' || (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')))) && fromJSON('["self-hosted","aurora-buildbox","x64"]') || 'ubuntu-24.04' }} timeout-minutes: 120 steps: @@ -199,20 +189,15 @@ jobs: plan: name: KUnit plan - if: ${{ github.event_name != 'pull_request_review' && (github.event.action != 'labeled' || github.event.label.name == 'kunit-full') && ((github.event_name == 'pull_request_target' && vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]')) || (github.event_name == 'pull_request' && !(vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]'))) || (github.event_name != 'pull_request' && github.event_name != 'pull_request_target')) }} + if: ${{ (github.event.action != 'labeled' || github.event.label.name == 'kunit-full') && ((github.event_name == 'pull_request_target' && vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]')) || (github.event_name == 'pull_request' && !(vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]'))) || (github.event_name != 'pull_request' && github.event_name != 'pull_request_target')) }} runs-on: ${{ (vars.AURORA_SELF_HOSTED == 'on' && (github.event_name == 'pull_request_target' || (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')))) && fromJSON('["self-hosted","aurora-buildbox","x64"]') || 'ubuntu-24.04' }} timeout-minutes: 10 permissions: contents: read pull-requests: read - statuses: write outputs: matrix: ${{ steps.plan.outputs.matrix }} count: ${{ steps.plan.outputs.count }} - full: ${{ steps.plan.outputs.full }} - pr: ${{ steps.plan.outputs.pr }} - head: ${{ steps.plan.outputs.head }} - gate: ${{ steps.plan.outputs.gate }} steps: # Reads the PR through the API only; no checkout, no PR code runs in this job. - name: Pick the KUnit suites for this change @@ -223,7 +208,6 @@ jobs: EVENT: ${{ github.event_name }} PR: ${{ github.event.pull_request.number }} HEAD: ${{ github.event.pull_request.head.sha }} - INPUT_PR: ${{ inputs.pr }} run: | cat > "$RUNNER_TEMP/plan.py" <<'PLAN' # KUnit tier planner for apple-build-kunit.yml (embedded in the workflow's plan job). @@ -294,7 +278,7 @@ jobs: print(json.dumps(plan(files, full), separators=(",", ":"))) PLAN cat > "$RUNNER_TEMP/files.py" <<'FILES' - # Mode, PR head and changed files, through the API. Any doubt selects the full matrix. + # Changed files and approval state of a same-repo PR, through the API. Any doubt selects the full matrix. import json, os, urllib.request api = os.environ.get("GITHUB_API_URL", "https://api.github.com") def get(url, body=None): @@ -303,11 +287,11 @@ jobs: with urllib.request.urlopen(req, timeout=60) as r: return json.load(r) ev, repo, t = os.environ["EVENT"], os.environ["REPO"], os.environ["RUNNER_TEMP"] - owner, name = repo.split("/") - full, files, pr, head, gate = True, [], "", "", "0" - if ev == "pull_request_target": - pr, head, gate = os.environ["PR"], os.environ["HEAD"], "1" + full, files = True, [] + if ev == "pull_request_target": # forks (pull_request), pushes and dispatches always run everything try: + owner, name = repo.split("/") + pr, head = os.environ["PR"], os.environ["HEAD"] q = ("query($o:String!,$n:String!,$p:Int!){repository(owner:$o,name:$n){pullRequest(number:$p){" "reviewDecision labels(first:100){nodes{name}} reviews(last:50){nodes{state commit{oid}}}}}}") d = get(api + "/graphql", {"query": q, "variables": {"o": owner, "n": name, "p": int(pr)}})["data"]["repository"]["pullRequest"] @@ -322,51 +306,20 @@ jobs: except Exception as e: print(f"::warning::KUnit plan: {e}; running the full matrix") full, files = True, [] - elif ev == "workflow_dispatch" and os.environ.get("INPUT_PR"): - # A full run for a same-repo PR (requested by an approval or by hand); forks are refused. - p = get(f"{api}/repos/{repo}/pulls/{int(os.environ['INPUT_PR'])}") - if p["state"] != "open" or (p["head"]["repo"] or {}).get("full_name") != repo: - raise SystemExit(f"::error::PR {p['number']} is not an open same-repo pull request") - pr, head, gate = str(p["number"]), p["head"]["sha"], "1" - for k, v in (("full", "1" if full else "0"), ("files.txt", "\n".join(files)), ("pr", pr), ("head", head), ("gate", gate)): - open(f"{t}/{k}", "w").write(v) + open(t + "/full", "w").write("1" if full else "0") + open(t + "/files.txt", "w").write("\n".join(files)) FILES python3 -I "$RUNNER_TEMP/files.py" m=$(FULL=$(cat "$RUNNER_TEMP/full") FILES=$(cat "$RUNNER_TEMP/files.txt") python3 -I "$RUNNER_TEMP/plan.py") n=$(printf '%s' "$m" | python3 -I -c 'import json,sys;print(len(json.load(sys.stdin)["include"]))') - { echo "matrix=$m"; echo "count=$n"; echo "full=$(cat "$RUNNER_TEMP/full")" - echo "pr=$(cat "$RUNNER_TEMP/pr")"; echo "head=$(cat "$RUNNER_TEMP/head")"; echo "gate=$(cat "$RUNNER_TEMP/gate")"; } >> "$GITHUB_OUTPUT" - echo "### KUnit plan: $n suite(s)" >> "$GITHUB_STEP_SUMMARY" + { echo "matrix=$m"; echo "count=$n"; } >> "$GITHUB_OUTPUT" + echo "### KUnit plan: $n of 16 suite(s)$( [ "$(cat "$RUNNER_TEMP/full")" = 1 ] && echo ' (full matrix)')" >> "$GITHUB_STEP_SUMMARY" printf '%s\n' "$m" | python3 -I -c 'import json,sys;[print("- "+x["suite"]) for x in json.load(sys.stdin)["include"]]' >> "$GITHUB_STEP_SUMMARY" - - name: Mark the full matrix pending for this head - env: - GITHUB_TOKEN: ${{ github.token }} - REPO: ${{ github.repository }} - GATE: ${{ steps.plan.outputs.gate }} - HEAD: ${{ steps.plan.outputs.head }} - STATE: pending - MODE: ${{ steps.plan.outputs.full == '1' && 'keep-success' || 'first' }} - DESC: ${{ steps.plan.outputs.full == '1' && 'Full matrix running' || 'Narrow run; the full matrix runs on approval or kunit-full' }} - run: | - [ "$GATE" = 1 ] || exit 0 - # One owner per head: full runs own the result (pending at start, then the outcome). A narrow run - # only marks a head that has no status yet; any status means a full run has started and owns it. - # A full run never takes back a pass for this head when it starts. - if [ "$MODE" != terminal ]; then - last=$(curl -fsS -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" \ - "$GITHUB_API_URL/repos/$REPO/commits/$HEAD/statuses?per_page=100" | - python3 -I -c 'import json,sys;print(next((x["state"] for x in json.load(sys.stdin) if x["context"]=="KUnit full matrix"),"none"))') - if [ "$MODE" = first ] && [ "$last" != none ]; then echo "a full run owns the status at $HEAD ($last)"; exit 0; fi - if [ "$last" = success ]; then echo "full matrix already passed at $HEAD; keeping it"; exit 0; fi - fi - curl -fsS -X POST -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" \ - "$GITHUB_API_URL/repos/$REPO/statuses/$HEAD" \ - -d "{\"state\":\"$STATE\",\"context\":\"KUnit full matrix\",\"description\":\"$DESC\",\"target_url\":\"$GITHUB_SERVER_URL/$REPO/actions/runs/$GITHUB_RUN_ID\"}" >/dev/null kunit: - name: ${{ inputs.pr != '' && format('PR {0} KUnit {1}', inputs.pr, matrix.suite) || format('KUnit {0}', matrix.suite) }} + name: KUnit ${{ matrix.suite }} needs: plan - if: ${{ needs.plan.outputs.count != '0' && github.event_name != 'pull_request_review' && (github.event.action != 'labeled' || github.event.label.name == 'kunit-full') && ((github.event_name == 'pull_request_target' && vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]')) || (github.event_name == 'pull_request' && !(vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]'))) || (github.event_name != 'pull_request' && github.event_name != 'pull_request_target')) }} + if: ${{ needs.plan.outputs.count != '0' && (github.event.action != 'labeled' || github.event.label.name == 'kunit-full') && ((github.event_name == 'pull_request_target' && vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]')) || (github.event_name == 'pull_request' && !(vars.AURORA_SELF_HOSTED == 'on' && github.event.pull_request.head.repo.full_name == github.repository && !endsWith(github.actor, '[bot]'))) || (github.event_name != 'pull_request' && github.event_name != 'pull_request_target')) }} runs-on: ${{ (vars.AURORA_SELF_HOSTED == 'on' && (github.event_name == 'pull_request_target' || (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')))) && fromJSON('["self-hosted","aurora-buildbox","x64"]') || 'ubuntu-24.04' }} timeout-minutes: 60 strategy: @@ -376,16 +329,16 @@ jobs: steps: - uses: actions/checkout@v4 with: - ref: ${{ needs.plan.outputs.pr != '' && format('refs/pull/{0}/merge', needs.plan.outputs.pr) || '' }} + ref: ${{ github.event_name == 'pull_request_target' && format('refs/pull/{0}/merge', github.event.pull_request.number) || '' }} persist-credentials: false fetch-depth: 1 - name: Verify the PR merge ref matches this event - if: needs.plan.outputs.pr != '' + if: github.event_name == 'pull_request_target' env: - WANT: ${{ needs.plan.outputs.head }} + WANT: ${{ github.event.pull_request.head.sha }} run: | got=$(git cat-file -p HEAD | sed -n 's/^parent //p' | sed -n 2p) - [ "$got" = "$WANT" ] || { echo "::error::refs/pull merge ref is for head $got, this run is for $WANT (the PR moved or this is a stale re-run; the newest run covers the current head)"; exit 1; } + [ "$got" = "$WANT" ] || { echo "::error::refs/pull merge ref is for head $got, this event is for $WANT (the PR moved or this is a stale re-run; the newest run covers the current head)"; exit 1; } - name: Install kernel build and QEMU dependencies run: | # As sep-source.yml: avoid the hosted runner's Azure mirror. @@ -413,59 +366,3 @@ jobs: --make_options LLVM=1 \ --kunitconfig="$KUNITCONFIG" \ --jobs="$(nproc)" --timeout=900 - - kunit-full: - name: Record KUnit full matrix - needs: [plan, kunit] - # Records the result for the PR head; never runs PR code. - if: ${{ always() && needs.plan.result == 'success' && needs.plan.outputs.gate == '1' && needs.plan.outputs.full == '1' }} - runs-on: ${{ (vars.AURORA_SELF_HOSTED == 'on' && (github.event_name == 'pull_request_target' || (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')))) && fromJSON('["self-hosted","aurora-buildbox","x64"]') || 'ubuntu-24.04' }} - timeout-minutes: 10 - permissions: - statuses: write - steps: - - name: Record the KUnit result for this head - env: - GITHUB_TOKEN: ${{ github.token }} - REPO: ${{ github.repository }} - # Narrow runs write nothing here; the full run that owns the head records its outcome. - GATE: ${{ needs.plan.outputs.full == '1' && '1' || '0' }} - MODE: terminal - HEAD: ${{ needs.plan.outputs.head }} - STATE: ${{ needs.kunit.result == 'success' && 'success' || (needs.kunit.result == 'failure' && 'failure' || 'pending') }} - DESC: ${{ needs.kunit.result == 'success' && 'All suites passed at this head' || (needs.kunit.result == 'failure' && 'A suite failed in the full run' || 'Full run did not finish; re-run it') }} - run: | - [ "$GATE" = 1 ] || exit 0 - # One owner per head: full runs own the result (pending at start, then the outcome). A narrow run - # only marks a head that has no status yet; any status means a full run has started and owns it. - # A full run never takes back a pass for this head when it starts. - if [ "$MODE" != terminal ]; then - last=$(curl -fsS -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" \ - "$GITHUB_API_URL/repos/$REPO/commits/$HEAD/statuses?per_page=100" | - python3 -I -c 'import json,sys;print(next((x["state"] for x in json.load(sys.stdin) if x["context"]=="KUnit full matrix"),"none"))') - if [ "$MODE" = first ] && [ "$last" != none ]; then echo "a full run owns the status at $HEAD ($last)"; exit 0; fi - if [ "$last" = success ]; then echo "full matrix already passed at $HEAD; keeping it"; exit 0; fi - fi - curl -fsS -X POST -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" \ - "$GITHUB_API_URL/repos/$REPO/statuses/$HEAD" \ - -d "{\"state\":\"$STATE\",\"context\":\"KUnit full matrix\",\"description\":\"$DESC\",\"target_url\":\"$GITHUB_SERVER_URL/$REPO/actions/runs/$GITHUB_RUN_ID\"}" >/dev/null - - request-full: - name: Request the full KUnit matrix - # An approval of a same-repo PR dispatches this workflow from main for the PR (GITHUB_TOKEN - # dispatches do start workflows). Forks always run the full matrix and need no request. - if: ${{ github.event_name == 'pull_request_review' && github.event.review.state == 'approved' && github.event.pull_request.head.repo.full_name == github.repository && contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.review.author_association) }} - runs-on: ubuntu-24.04 - timeout-minutes: 5 - permissions: - actions: write - steps: - - env: - GITHUB_TOKEN: ${{ github.token }} - REPO: ${{ github.repository }} - PR: ${{ github.event.pull_request.number }} - BRANCH: ${{ github.event.repository.default_branch }} - run: | - curl -fsS -X POST -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" \ - "$GITHUB_API_URL/repos/$REPO/actions/workflows/apple-build-kunit.yml/dispatches" \ - -d "{\"ref\":\"$BRANCH\",\"inputs\":{\"pr\":\"$PR\"}}" From 61cbf4295fbd0a34ff4c3ce248bc0fb4a625aaae Mon Sep 17 00:00:00 2001 From: Ryan <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 30 Nov 2026 14:32:32 +1100 Subject: [PATCH 7/8] ci: apple-build-kunit: the kunit-full label event forces the full plan Review: the planner re-read the label through a bounded GraphQL list, so a kunit-full label missing from that response could leave the requested full run narrow. The label name now comes from the event payload, and a kunit-full label event runs every suite without asking the API. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- .github/workflows/apple-build-kunit.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/apple-build-kunit.yml b/.github/workflows/apple-build-kunit.yml index c20ef8e499f84..e7caf8885432b 100644 --- a/.github/workflows/apple-build-kunit.yml +++ b/.github/workflows/apple-build-kunit.yml @@ -208,6 +208,7 @@ jobs: EVENT: ${{ github.event_name }} PR: ${{ github.event.pull_request.number }} HEAD: ${{ github.event.pull_request.head.sha }} + LABEL: ${{ github.event.action == 'labeled' && github.event.label.name || '' }} run: | cat > "$RUNNER_TEMP/plan.py" <<'PLAN' # KUnit tier planner for apple-build-kunit.yml (embedded in the workflow's plan job). @@ -288,7 +289,8 @@ jobs: return json.load(r) ev, repo, t = os.environ["EVENT"], os.environ["REPO"], os.environ["RUNNER_TEMP"] full, files = True, [] - if ev == "pull_request_target": # forks (pull_request), pushes and dispatches always run everything + if ev == "pull_request_target" and os.environ.get("LABEL") != "kunit-full": + # forks (pull_request), pushes, dispatches and the kunit-full label event always run everything try: owner, name = repo.split("/") pr, head = os.environ["PR"], os.environ["HEAD"] From 008450baf14e5c54aae2e5c22919727cb5147db4 Mon Sep 17 00:00:00 2001 From: Ryan <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 30 Nov 2026 14:40:24 +1100 Subject: [PATCH 8/8] ci: apple-build-kunit: pass the planner its file list through a file Review nit: the changed-file list went to the planner in one environment variable, which a PR with a few thousand files could push past the kernel's per-variable size limit (E2BIG) instead of falling back to the full matrix. The planner now reads it from the runner's temp file. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- .github/workflows/apple-build-kunit.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/apple-build-kunit.yml b/.github/workflows/apple-build-kunit.yml index e7caf8885432b..3ccb7deb4f216 100644 --- a/.github/workflows/apple-build-kunit.yml +++ b/.github/workflows/apple-build-kunit.yml @@ -274,7 +274,10 @@ jobs: return {"include": [dict(suite=s, kunitconfig=k, **({"rust": True} if r else {})) for s, k, r, _ in pick]} if __name__ == "__main__": - files = [l.strip() for l in os.environ.get("FILES", "").splitlines() if l.strip()] + # The file list comes from a file, not the environment: a large PR would exceed the per-variable size limit. + src = os.environ.get("FILES_FILE") + text = open(src).read() if src else os.environ.get("FILES", "") + files = [l.strip() for l in text.splitlines() if l.strip()] full = os.environ.get("FULL") == "1" or not files print(json.dumps(plan(files, full), separators=(",", ":"))) PLAN @@ -312,7 +315,7 @@ jobs: open(t + "/files.txt", "w").write("\n".join(files)) FILES python3 -I "$RUNNER_TEMP/files.py" - m=$(FULL=$(cat "$RUNNER_TEMP/full") FILES=$(cat "$RUNNER_TEMP/files.txt") python3 -I "$RUNNER_TEMP/plan.py") + m=$(FULL=$(cat "$RUNNER_TEMP/full") FILES_FILE="$RUNNER_TEMP/files.txt" python3 -I "$RUNNER_TEMP/plan.py") n=$(printf '%s' "$m" | python3 -I -c 'import json,sys;print(len(json.load(sys.stdin)["include"]))') { echo "matrix=$m"; echo "count=$n"; } >> "$GITHUB_OUTPUT" echo "### KUnit plan: $n of 16 suite(s)$( [ "$(cat "$RUNNER_TEMP/full")" = 1 ] && echo ' (full matrix)')" >> "$GITHUB_STEP_SUMMARY"