From 1ca1b89822f0d59006a60095e740d8a2f60ebcae Mon Sep 17 00:00:00 2001 From: Niklas Wagner Date: Sun, 1 Nov 2026 18:43:23 +0100 Subject: [PATCH] fix: exclude PR preview tags from container documentation --- docs/maintainers/adding-a-repository.md | 13 ++- docs/maintainers/container-releases.md | 117 +++++++----------------- docs/maintainers/website.md | 5 + macros/main.py | 8 +- macros/tests/test_main.py | 25 ++++- 5 files changed, 69 insertions(+), 99 deletions(-) diff --git a/docs/maintainers/adding-a-repository.md b/docs/maintainers/adding-a-repository.md index 238ecfe..61219e2 100644 --- a/docs/maintainers/adding-a-repository.md +++ b/docs/maintainers/adding-a-repository.md @@ -36,7 +36,6 @@ The normal layout is: ```text .github/workflows/container.yml -.github/workflows/container-pr-cleanup.yml .dockerignore Containerfile LICENSE @@ -131,12 +130,13 @@ pass credentials through build arguments or write them into images. ### Workflows -Add the [shared container caller](container-releases.md#calling-the-workflow) -and separate [PR-preview cleanup caller](container-releases.md#cleaning-up-pr-previews). +Add the [shared container caller](container-releases.md#calling-the-workflow). Do not duplicate shared build, test, or publishing jobs. Keep `uses` and `shared-ref` coordinated when pinning shared tooling. -PRs test all active tracks and platforms without moving production tags. +PRs test all active tracks and platforms without moving production aliases. +Same-repository PRs publish retained `pr-` tags into the production package; +there is no automatic preview cleanup. Reserve this prefix for PR builds. Default-branch pushes can publish real releases. For an empty repository, a README-only default branch followed by a container PR keeps the first publication behind review. Do not push release workflows to the default branch @@ -160,9 +160,8 @@ existing repositories before managing them through OpenTofu. Set and verify the GitHub About description and homepage, enable Renovate, and require `container / pull-request-check` before merging container changes. -Verify GHCR visibility and Actions access for both production and preview -packages. Preview cleanup needs package admin access. Do not assume a workflow -token makes a newly created package public. +Verify GHCR visibility and Actions write access for the shared production and +preview package. Do not assume a workflow token makes a newly created package public. ## Validate and submit diff --git a/docs/maintainers/container-releases.md b/docs/maintainers/container-releases.md index 6b8ff4f..6cedb0b 100644 --- a/docs/maintainers/container-releases.md +++ b/docs/maintainers/container-releases.md @@ -56,7 +56,7 @@ for both production and PR builds: | Label | Production value | PR value | | --- | --- | --- | -| `org.opencontainers.image.source` | Caller repository URL, such as `https://github.com/tuxcrate/sonarr` | Same caller repository URL, not the separate preview package URL | +| `org.opencontainers.image.source` | Caller repository URL, such as `https://github.com/tuxcrate/sonarr` | Same caller repository URL | | `org.opencontainers.image.version` | Full immutable image tag, including `-rN` | Full preview package version | | `org.opencontainers.image.revision` | Source Git commit SHA | Tested merge commit SHA | @@ -89,13 +89,13 @@ PRs whose images remain local: | `io.tuxcrate.repository` | Caller repository, such as `tuxcrate/sonarr` | Identifies the repository that owns the preview | | `io.tuxcrate.pull-request` | PR number as a string, such as `12` | Identifies the PR that owns the preview | -Preview cleanup uses these annotations to recognize untagged indexes left by -reruns. They are not container labels and do not appear in `Config.Labels`. +These annotations identify preview artifacts independently of their mutable +tags. They are not container labels and do not appear in `Config.Labels`. Production indexes do not receive these preview annotations. For a published preview, inspect the raw index with: ```sh -docker buildx imagetools inspect --raw ghcr.io/tuxcrate/sonarr-pr:pr-12-stable +docker buildx imagetools inspect --raw ghcr.io/tuxcrate/sonarr:pr-12-stable ``` The keys appear in the index's `annotations` mapping. The `index:` prefix in @@ -147,7 +147,7 @@ For local authenticated builds, add ### Behavior and tags - PRs build both platforms using QEMU, export a local OCI archive, and test each platform before any registry upload. - Same-repository PRs then publish test images to a separate `ghcr.io/-pr` package; fork PRs build and test locally, with no registry login or upload. + Same-repository PRs then publish test images to the production package under `pr-` tags; fork PRs build and test locally, with no registry login or upload. PRs never create GitHub releases or update production aliases. The Containerfile's `RUN` assertions execute on both architectures; no host ZFS kernel module is needed for zrepl's smoke tests. - Default-branch pushes build and publish only tracks whose build or publication inputs differ from their last successfully published release. @@ -225,22 +225,28 @@ Every eligible same-repository PR publishes two tags per track. For PR 12's stable track in `tuxcrate/zrepl`: ```text -ghcr.io/tuxcrate/zrepl-pr:pr-12-stable -ghcr.io/tuxcrate/zrepl-pr:pr-12-stable- +ghcr.io/tuxcrate/zrepl:pr-12-stable +ghcr.io/tuxcrate/zrepl:pr-12-stable- ``` The first tag follows the PR. The second identifies the exact merge commit tested by `pull_request`, not just the PR branch's head commit. Rerunning the same commit may refresh OS packages and replace either tag; pin the image digest when an exact artifact is required. Tracks have separate tags to avoid collisions. -The preview package always derives from the caller repository, regardless of any production `image` override in `meta.yaml`. +Previews use the same package as production, including any `image` override in +`meta.yaml`. The `pr-` prefix is reserved for PR previews and cannot be declared +as a production moving tag. ```sh -docker pull ghcr.io/tuxcrate/zrepl-pr:pr-12-stable +docker pull ghcr.io/tuxcrate/zrepl:pr-12-stable ``` Preview builds include uncached multiarch smoke tests, provenance, and SBOMs. They do not allocate release revisions, publish GitHub releases, move production aliases, or notify the website. -The shared cleanup workflow removes closed-PR previews when installed as described below. +Preview tags and artifacts are retained after PRs close; there is no automatic +cleanup. Reruns can also leave untagged artifacts. Actual preview pulls contribute +to the same package-wide download total as production pulls; retaining an image +does not itself increase that total. The website excludes `pr-` tags from its +release tables and tag selectors, even if they point to a production digest. After a successful push, the workflow posts pull commands, the tested merge commit, platforms, image digest, and a build link in the PR. The same comment includes the generated `release.json` in a collapsed section labeled as synthetic validation metadata. Its revision is a placeholder; its digest identifies the tested multiarchitecture artifact. @@ -252,83 +258,25 @@ Fork PRs do not log in or push. Keep GitHub's default read-only token policy for fork PRs. Never switch to `pull_request_target` to publish fork code. Same-repository publishing uses `GITHUB_TOKEN` in the build job. -The `-pr` package has a separate name, but this does not restrict what the token can access. +Publishing previews to the production package does not restrict what the token can access. Only trusted contributors should be able to create branches in the repository. -On first publication, set the new `-pr` package's visibility to public if anonymous pulls are intended. -For an existing preview package, grant the caller repository Actions write access, just as for the production package. +Set the shared package's visibility to public if anonymous pulls are intended, +and grant the caller repository Actions write access for an existing package. -### Cleaning up PR previews +### Migrating from separate preview packages -Add a separate `.github/workflows/container-pr-cleanup.yml` to each image repository: +Deploy the website's `pr-` tag filtering before publishing previews into production +packages. Remove `.github/workflows/container-pr-cleanup.yml` from every caller +before removing the shared cleanup workflow and tooling, so scheduled callers +cannot reference a deleted workflow. Then publish the updated shared container +workflow, keeping pinned `uses` and `shared-ref` values coordinated. -{% raw %} -```yaml -name: Clean up container PR previews - -on: - pull_request: - types: [closed] - schedule: - - cron: '41 3 * * *' - workflow_dispatch: - inputs: - dry-run: - description: Report matching images without deleting them - default: true - type: boolean - -permissions: - contents: read - -jobs: - cleanup: - if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository - permissions: - contents: read - packages: write - pull-requests: read - uses: tuxcrate/github-actions/.github/workflows/container-pr-cleanup.yml@main - with: - dry-run: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run || false }} -``` -{% endraw %} - -Publish the shared workflow and tooling before enabling callers. -For a pinned caller, set `with.shared-ref` to the same ref as `uses`. -Install the caller on the default branch so closed-PR events and scheduled sweeps can run. - -The close event covers both merged and unmerged same-repository PRs; fork close events are skipped because forks do not publish previews. -Every run checks current PR state through the API and scans all historical preview tracks and commits, including tracks no longer in `meta.yaml`. -The daily schedule catches older closed PRs, missed events, and previews left by late builds. -Manual runs default to dry-run mode; inspect their logs before disabling it to perform deletion. -No organization-wide token or additional secret is needed. - -The caller repository's `GITHUB_TOKEN` needs admin access to its `-pr` package to delete versions, in addition to the workflow's `packages: write` permission. -Packages created by that repository's workflow normally grant this automatically; check the package's Manage Actions access settings for existing packages. -Production publishing access alone does not establish access to the separate preview package. -GitHub can report inaccessible packages as not found. Cleanup logs and skips missing or inaccessible packages, so verify package access if previews remain. - -Cleanup is limited to `ghcr.io/-pr`, even when production uses an overridden image name. -It deletes entire package versions, including their tags: - -- All tags on a tagged version must identify closed PRs. Open-PR images and versions with unknown tags are retained. -- Eligible image roots are processed oldest first using their creation timestamp (with a version-ID tie-breaker). If no tagged version would otherwise remain, the newest eligible tagged image and its complete manifest graph are retained because GHCR rejects deletion of the last tagged version. Once a newer preview exists, a subsequent sweep can remove the older retained image. This does not delete or recreate the package, so its visibility and access settings remain intact. -- The registry's manifest graph identifies associated platform images and provenance/SBOM attestations. Descendants still referenced by retained images are preserved. -- New preview indexes carry repository and PR annotations, allowing cleanup to recognize untagged indexes left by reruns. Cleanup retains older untagged images when PR ownership cannot be proven; timestamps alone do not establish ownership. -- Discovery and PR-state checks must succeed before deletion. Cleanup rechecks closed PRs and the package snapshot before deleting; changed state aborts the run for a later retry. -- Children are deleted before their index so a partial failure leaves its ownership discoverable on a retry. Registry-managed blobs are not deleted individually. - -The close-event cleanup shares the PR build's concurrency group, so it waits for that PR's active build. -Scheduled sweeps can overlap other PR builds; the snapshot check detects changes during discovery, and a later sweep catches previews published after a cleanup run. -Production packages, Git tags, GitHub releases, and the preview package itself are never deleted. -The run fails if GitHub blocks deletion, for example when a public version exceeds GitHub's download threshold. Cleanup does not bypass these restrictions. - -Cleanup uses ordinary `pull_request: closed` events, not `pull_request_target`; no opt-out from GitHub's public-repository event policy is needed. -The caller and shared job both skip fork close events, keeping fork tokens read-only. -The workflow checks out trusted shared tooling, never caller or PR sources, and never builds or executes PR code. -Do not pass an untrusted PR ref as `shared-ref`. -The shared workflow also temporarily accepts existing same-repository `pull_request_target: closed` callers, allowing the shared change to be published before callers migrate. Replace that trigger with the example above to avoid GitHub's November 2, 2026 policy restriction. +Existing `-pr` packages are not migrated or deleted automatically. Historical PR +comments still point to those packages; new successful builds update the comments +to the shared package. Existing preview artifacts remain available unless retired +separately. Rerun all jobs in open PR workflows after the rollout to use the new +shared workflow and tooling. ### Required root metadata and release tracks @@ -483,6 +431,7 @@ The following rules apply to all tracks: Versions ending in `-rN` are reserved for image revisions. - Revisions are allocated per exact image version, including prerelease identifiers, using both Git tags and releases/drafts. They do not reset when a track is renamed or a version is reassigned to another track. +- The `pr-` tag prefix is reserved for PR previews and is rejected in production tags. - Promotion requires a reviewed configuration change; build order does not promote tracks. Removing a track stops its builds but does not delete historical tags or remove its old moving aliases from GHCR. Retire obsolete aliases explicitly; retaining one must not be interpreted as a promise of maintenance. @@ -564,7 +513,8 @@ When migrating existing protection, publish the shared workflow first, rerun all then apply the OpenTofu configuration to replace the old per-track requirements. Rerunning only failed jobs can reuse the old shared-workflow commit. Package discovery for one architecture is not proof of availability for another; rerun failed checks after delayed upstream publication. -PRs never publish production images or move production aliases. +PRs publish only `pr-` preview tags in the shared package, never production tags +or aliases. Packaging changelogs are scoped to the previous release of the same track; pre-existing stable releases without a track marker remain compatible. @@ -670,7 +620,6 @@ actionlint ``` The release CLI lives in `cmd/container-release`. -The preview cleanup CLI lives in `cmd/container-pr-cleanup`; use `-dry-run` with `GITHUB_REPOSITORY` and `GH_TOKEN` set to inspect candidates without deleting anything. It is written in Go and uses `go.yaml.in/yaml/v3` for strict YAML parsing. The workflow compiles it using the Go toolchain provided by the Ubuntu runner; Go 1.23 or newer is required. Build it with `go build -o /path/to/container-release ./cmd/container-release`. diff --git a/docs/maintainers/website.md b/docs/maintainers/website.md index cf1927f..a0e08bc 100644 --- a/docs/maintainers/website.md +++ b/docs/maintainers/website.md @@ -58,6 +58,8 @@ exact heading title because the display text may be abbreviated. The next build refreshes the count; no browser-side requests or third-party badge services are needed. Unpublished packages have no counter, since a zero would be misleading. Offline previews use fictional counts. +The total includes PR-preview downloads because previews share the production +package. It is not a production-only usage count. Keep `container.description` to two or three sentences explaining what the tool does. Put configuration details and prerequisites in the corresponding Markdown blocks. All three content blocks are optional; use them to keep longer documentation in Markdown. @@ -126,6 +128,9 @@ You do not need a separate generator, Go toolchain, Python requirements file, or - GHCR's tag list and current manifest digests verify that each displayed revision tag still matches its release metadata. The plugin fetches all pages of both APIs; missing or mismatched revision tags are excluded. Tags without matching metadata are not displayed; the plugin does not infer versions from tag names. + PR-preview tags beginning with `pr-` are skipped before manifest lookups and + excluded from displayed aliases even when they match a production digest. + Published prerelease tracks such as `develop` and `preview` remain visible. - Repositories without published `release.json` metadata show "No releases available yet". They do not query GHCR, which may not have a package before the first release. An empty registry tag list also shows this message. API errors still stop the build. diff --git a/macros/main.py b/macros/main.py index b1314f1..c8cae14 100644 --- a/macros/main.py +++ b/macros/main.py @@ -218,7 +218,7 @@ def collect_releases(repository: str, image: str) -> tuple[list[Metadata], list[ def collect_tags(repository: str, image: str) -> dict[str, str]: - """Resolve registry tags to verified manifest digests.""" + """Resolve non-PR registry tags to verified manifest digests.""" query = urlencode({"service": "ghcr.io", "scope": f"repository:{repository}:pull"}) credentials, _ = request(f"https://ghcr.io/token?{query}") headers = { @@ -231,7 +231,7 @@ def collect_tags(repository: str, image: str) -> dict[str, str]: if not TAG.fullmatch(tag): msg = "Invalid registry tag" raise ValueError(msg) - if tag in tags: + if tag.startswith("pr-") or tag in tags: continue _, response_headers = request( f"https://ghcr.io/v2/{repository}/manifests/{quote(tag, safe='')}", @@ -360,7 +360,9 @@ def gh_image_versions_data(name: str) -> Metadata: ( tag for tag, digest in item["tags"].items() - if digest == release["digest"] and tag != release["immutableTag"] + if digest == release["digest"] + and tag != release["immutableTag"] + and not tag.startswith("pr-") ), key=lambda tag: (tag != release["version"], tag), ) diff --git a/macros/tests/test_main.py b/macros/tests/test_main.py index 5234520..25221c6 100644 --- a/macros/tests/test_main.py +++ b/macros/tests/test_main.py @@ -225,6 +225,20 @@ def test_only_current_matching_aliases_are_shown(self) -> None: self.assertIn("latest", preview) self.assertNotIn("manual", text) + def test_pr_tags_are_never_shown_as_release_aliases(self) -> None: + """Hide PR tags even when fixtures point them at a production digest.""" + item = copy.deepcopy(IMAGE) + for release in item["releases"]: + item["tags"]["pr-12-" + release["track"]] = release["digest"] + item["tags"]["pr-12-" + release["track"] + "-" + "a" * 40] = release[ + "digest" + ] + text = render_versions(item) + self.assertNotIn("pr-12-", text) + self.assertIn('data-container-tag="latest"', text) + self.assertIn('data-container-tag="2.0.0-rc.1-r0"', text) + self.assertIn("### Preview", text) + def test_all_verified_revisions_are_listed_newest_first(self) -> None: """Order every verified revision by publication time.""" item = copy.deepcopy(IMAGE) @@ -1006,8 +1020,8 @@ def test_no_release_metadata_skips_registry(self, request: Mock) -> None: @patch("macros.main.collect_releases", return_value=(IMAGE["releases"], [])) @patch("macros.main.request") def test_empty_registry_tags(self, request: Mock, releases: Mock) -> None: - """Treat null and empty registry tag lists as an empty published table.""" - for tags in (None, []): + """Treat empty or PR-only tag lists as an empty published table.""" + for tags in (None, [], ["pr-12-stable", "pr-12-stable-" + "a" * 40]): with self.subTest(tags=tags): request.reset_mock() request.side_effect = [ @@ -1019,7 +1033,7 @@ def test_empty_registry_tags(self, request: Mock, releases: Mock) -> None: self.assertIsNone(item["pulls"]) self.assertIn("No releases available yet", render_versions(item)) self.assertEqual(request.call_count, 2) - self.assertEqual(releases.call_count, 2) + self.assertEqual(releases.call_count, 3) @patch("macros.main.collect_releases", return_value=(IMAGE["releases"], [])) @patch("macros.main.collect_tags", side_effect=RuntimeError("HTTP 403")) @@ -1093,11 +1107,11 @@ def test_paginated_releases_and_registry_tags(self, request: Mock) -> None: (record, {}), ({"token": "registry-secret"}, {}), ( - {"tags": ["latest"]}, + {"tags": ["pr-12-stable", "latest"]}, {"Link": '; rel="next"'}, ), (None, {"Docker-Content-Digest": record["digest"]}), - ({"tags": ["1.2.3-r1"]}, {}), + ({"tags": ["pr-12-stable-" + "a" * 40, "1.2.3-r1"]}, {}), (None, {"Docker-Content-Digest": record["digest"]}), ('Total downloads

12.3k

', {}), ] @@ -1117,6 +1131,7 @@ def test_paginated_releases_and_registry_tags(self, request: Mock) -> None: calls[4].kwargs["headers"]["Authorization"], "Bearer registry-secret" ) self.assertEqual(calls[5].kwargs["method"], "HEAD") + self.assertFalse(any("/manifests/pr-" in call.args[0] for call in calls)) self.assertNotIn("Authorization", calls[-1].kwargs["headers"]) @patch("macros.main.request")