From 137f071fee2d6cf1fa6a575cc784771bc2892d69 Mon Sep 17 00:00:00 2001 From: hanthor Date: Sat, 19 Sep 2026 11:39:57 +0000 Subject: [PATCH] Stop fork pull requests failing on a GHCR permission they cannot have #154, #157 and #158 are all red for the same reason, and none of it is in their diffs. Each touches scripts/install-ogc-kernel.sh, which rotates the kernel cache tag, so kernel_cache compiles the kernel -- twenty minutes -- and then dies: Error: writing blob: initiating layer upload to /v2/projectbluefin/utah-kernel-cache/blobs/uploads/ in ghcr.io: denied: installation not allowed to Write organization package ##[error]Process completed with exit code 125 A pull request from a fork gets a read-only GITHUB_TOKEN. No contributor can be granted that write, so every kernel change from a fork is permanently red on a step that has nothing to say about the change. The compile is the part that validates a kernel change, and it already passes. So the build stays unconditional and only the push is gated: when the token cannot publish, the job emits a notice saying the kernel compiled and that the flavored images are not built here, and exits 0. build_kernel is skipped in that case rather than left to fail pulling an image that was never pushed -- kernel_cache now reports whether the image is available and build_kernel requires it. dispatch-iso already tolerates a skipped build_kernel. The GHCR login is also allowed to fail: only the push needs credentials, and a cache hit can be read anonymously. What this does not do is pretend the flavors were validated. The notice is explicit, and the honest fix for a kernel change is a branch in this repository, where the push works -- which is why my own kernel PRs are green and these three are not. Trading a red job for a quiet skip would be the wrong trade if the skip were silent; it is not. tests/test_iso_ci.py asserts the ordering that matters: the build is in front of the guard and the push behind it, a cache hit still reports the image as available, and build_kernel requires that output. Removing the build_kernel gate fails the suite. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01W6BYLUD6KBzF8rBFXKjP7M --- .github/workflows/build.yml | 34 +++++++++++++++++++++++-- tests/test_iso_ci.py | 51 +++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fb923dca9..e0f4889ad 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -80,6 +80,10 @@ jobs: permissions: contents: read packages: write + outputs: + # Whether the flavored builds can pull the cache image. False on a fork + # pull request, where the kernel is compiled but cannot be published. + available: ${{ steps.cache.outputs.available }} steps: - name: Checkout uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5 @@ -91,20 +95,46 @@ jobs: - name: Log in to GHCR env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: echo "$GITHUB_TOKEN" | podman login ghcr.io -u "${{ github.actor }}" --password-stdin + run: | + # Anonymous pulls are enough to check whether the tag is published; + # only the push needs credentials, and a fork PR has none to give. + echo "$GITHUB_TOKEN" | podman login ghcr.io -u "${{ github.actor }}" --password-stdin \ + || echo "::warning title=ghcr login failed::continuing; a cache hit can still be read anonymously" - name: Build the kernel cache image if it is not published yet + id: cache env: REPO_ORGANIZATION: ${{ github.repository_owner }} + # Empty head repository means this is not a pull request at all, so + # the comparison holds for pushes, schedules and dispatches too. + CAN_PUBLISH: ${{ github.event.pull_request.head.repo.full_name == '' + || github.event.pull_request.head.repo.full_name == github.repository }} run: | set -euo pipefail ref="ghcr.io/${REPO_ORGANIZATION,,}/utah-kernel-cache:$(./scripts/kernel-cache-tag.sh)" if podman pull -q "$ref" >/dev/null 2>&1; then echo "Cache hit: $ref is already published" + echo "available=true" >> "$GITHUB_OUTPUT" exit 0 fi echo "Cache miss: building $ref" podman build --tag "$ref" --file Containerfile.kernel . + # A pull request from a fork gets a read-only GITHUB_TOKEN, so the + # push fails no matter how well the kernel built: + # + # denied: installation not allowed to Write organization package + # + # That is what #154, #157 and #158 have been red for -- all three + # compiled the kernel and died publishing it, twenty minutes in, on a + # permission no contributor can be granted from a fork. The compile is + # the part that validates their change, so run it and say plainly that + # the flavored images cannot be built from here. + if [ "${CAN_PUBLISH}" != "true" ]; then + echo "::notice title=kernel cache not published::The kernel compiled, but a fork pull request cannot write to ghcr.io/${REPO_ORGANIZATION,,}. The flavored images are not built for this PR; push the branch to projectbluefin/utah to validate them." + echo "available=false" >> "$GITHUB_OUTPUT" + exit 0 + fi podman push "$ref" + echo "available=true" >> "$GITHUB_OUTPUT" # main starts the moment the contract check passes. It never pulls the kernel # cache, so there is no reason for it to wait on that job; before this split @@ -157,7 +187,7 @@ jobs: # digest artifact, which post-testing-e2e matches by glob. build_kernel: needs: [contract, kernel_cache] - if: ${{ !cancelled() && needs.contract.result == 'success' && needs.kernel_cache.result == 'success' && needs.contract.outputs.kernel_flavors != '[]' }} + if: ${{ !cancelled() && needs.contract.result == 'success' && needs.kernel_cache.result == 'success' && needs.kernel_cache.outputs.available == 'true' && needs.contract.outputs.kernel_flavors != '[]' }} uses: projectbluefin/actions/.github/workflows/reusable-build.yml@8895d09342174927b950abc75dccd6da2c8ba36f # v1 permissions: contents: read diff --git a/tests/test_iso_ci.py b/tests/test_iso_ci.py index 314b16619..ae01fc097 100644 --- a/tests/test_iso_ci.py +++ b/tests/test_iso_ci.py @@ -227,3 +227,54 @@ def test_harness_delegates_the_decision_and_prints_the_transcript_on_failure(sel self.assertIn("fastfetch-ocr-match.sh", script) self.assertNotIn("grep -qi 'UTAH.E2E.FASTFETCH'", script) self.assertIn("last OCR transcript", script) + + +class ForkPullRequestKernelCacheTests(unittest.TestCase): + """A fork PR cannot publish the kernel cache, and must not go red for it. + + #154, #157 and #158 were all red on the same thing: the kernel compiled and + the push then failed with "denied: installation not allowed to Write + organization package", twenty minutes in, on a permission no contributor can + be granted from a fork. Three PRs blocked by CI plumbing rather than by + anything in their diffs. + """ + + WORKFLOW = ROOT / ".github/workflows/build.yml" + + def setUp(self): + import yaml + self.text = self.WORKFLOW.read_text() + self.jobs = yaml.safe_load(self.text)["jobs"] + + def test_the_push_is_conditional_but_the_build_is_not(self): + step = next(s for s in self.jobs["kernel_cache"]["steps"] + if s.get("id") == "cache") + run = step["run"] + # The compile is what validates a kernel change, so it always runs. + self.assertIn("podman build --tag", run) + build = run.index("podman build --tag") + guard = run.index('if [ "${CAN_PUBLISH}" != "true" ]') + push = run.index("podman push") + self.assertLess(build, guard, "the build must not be behind the guard") + self.assertLess(guard, push, "the push must be behind the guard") + + def test_can_publish_is_true_for_everything_that_is_not_a_fork_pr(self): + step = next(s for s in self.jobs["kernel_cache"]["steps"] + if s.get("id") == "cache") + env = step["env"]["CAN_PUBLISH"] + # An empty head repository is a push, a schedule or a dispatch. + self.assertIn("github.event.pull_request.head.repo.full_name == ''", env) + self.assertIn("== github.repository", env) + + def test_the_flavored_builds_are_skipped_rather_than_left_to_fail(self): + # Without this they would try to pull an image that was never pushed. + self.assertIn("needs.kernel_cache.outputs.available == 'true'", + self.jobs["build_kernel"]["if"]) + self.assertEqual(self.jobs["kernel_cache"]["outputs"]["available"], + "${{ steps.cache.outputs.available }}") + + def test_a_cache_hit_still_reports_the_image_as_available(self): + step = next(s for s in self.jobs["kernel_cache"]["steps"] + if s.get("id") == "cache") + hit = step["run"].index("Cache hit") + self.assertIn("available=true", step["run"][hit:hit + 200])