Skip to content

ci: prune old continuous main builds from GHCR daily - #2293

Merged
Nashon-Steffen merged 2 commits into
mainfrom
Nashon-Steffen/prune-main-builds
Oct 13, 2026
Merged

Nashon-Steffen merged 2 commits into
mainfrom
Nashon-Steffen/prune-main-builds

Conversation

@Nashon-Steffen

@Nashon-Steffen Nashon-Steffen commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds .github/workflows/prune-main-builds.yml, a daily job that deletes old continuous main builds from GHCR. continuous.yml (#2292) publishes two images and two charts for each main commit that passes CI, which is about 11 builds a day (75 a week), and nothing removed them.

Stacked on #2292. The base branch is Nashon-Steffen/studio-continuous-main; retarget it once that PR merges.

Retention. The job only touches the four main/ packages. Release images and charts are never named.

Package Kept
mecatl/main/charts/mecak8s, mecatl/main/charts/mecatl-studio everything younger than 7 days, plus the newest 20 older versions
mecatl/main/mecak8s, mecatl/main/studio everything younger than 7 days, plus the newest 30 older versions
  • Only version tags count: keep-n counts only the *-main.* version tags (v<version> images, <version> charts). ko also tags each platform image's SBOM as sha256-<digest>.sbom; counted as versions, those would take two of every three main/mecak8s slots.
  • Images keep more than charts, so every kept chart still resolves its digest-pinned images unless more than 10 older runs failed between pushing an image and pushing the charts.
  • Followers: a follower that tracks the newest chart never runs a pruned build. One more than 7 days and 20 builds behind loses its images.
  • Leftovers: untagged leftovers of failed runs are removed once they pass the same 7-day age. Orphaned artifacts, such as a deleted image's per-platform SBOMs, are removed whenever a run finds them.

Why dataaxiom/ghcr-cleanup-action. Deleting untagged GHCR versions naively (for example with actions/delete-package-versions) breaks multi-arch images, whose platform manifests are untagged. This action deletes a multi-arch image together with:

  • its platform manifests;
  • its signature, SBOM, and attestation artifacts, whether a sha256-<digest> tag or an OCI referrer links them.

It skips any child manifest that another image still uses. It is pinned to the v1.2.2 commit (d52806a) and runs with packages: write.

Behaviour:

  • Missing packages fail: a package that doesn't exist or that this repository can't access fails its job. Merging ci: publish signed main builds of mecak8s, Studio, and their charts #2292 runs continuous.yml on its merge commit, so the packages exist before this PR reaches main.
  • Manual runs: dispatching by hand defaults to a dry run.
  • Branches and forks: the job runs only from main in stacklok/mecatl, so a dispatch from another branch can't prune with edited inputs.
  • Validation is advisory: the action's validate rechecks the package after deleting and only warns.

Issue relationship

Relates to #2292

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe): CI workflow

Test plan

Baseline checks

  • Linting (task lint): no Go changes. actionlint v1.7.7 (with shellcheck) reported nothing for the new workflow.
  • Fast offline test suite (task test): no Go changes.
  • Pre-review race suite (task test:race): no Go changes.
  • Offline demo (go run ./cmd/mecademo): no runtime changes.
  • Markdown changed: task docs:check passed with 0 broken links or anchors.
  • User docs/user-facing behavior changed: site build (task site:build)
  • Guarded engine API affected: compatibility check (task api:check)
  • Intentional engine API change: task api:update + engine/CHANGELOG.md

Exercised locally:

  • The *-main.* pattern, with the wildcard-match version the action uses: it matches v0.0.48-main.123.1.gabcdef12 and 0.0.48-main.123.1.gabcdef12, and none of sha256-<digest>.sbom, sha256-<digest>, v0.0.47, or latest.
  • The pinned action, in dry-run mode, against the existing release package mecatl/studio, before delete-tags was added, using a token without package write or delete scopes. The 7-day / keep-N rules were the same as here, with N=5 to exercise the keep logic.
    • It resolved the slash-containing package name and loaded all 88 manifests.
    • Its multi-arch and referrer validation found no errors.
    • It kept every tagged release older than 7 days, since there were 5 and N was 5.
    • It would have deleted 10 old untagged multi-arch indexes and skipped every child manifest still used by another image.
  • Not yet exercised: a dry run against a ko-built package with delete-tags. The release package mecatl/mecak8s has the same per-platform SBOM tags as main/mecak8s.
  • No real deletion has run anywhere.

Special notes for reviewers

  • Delete permission: deleting a version needs the Admin role on the package. GitHub grants that to the repository whose GITHUB_TOKEN created the package, so it holds for the main/ packages continuous.yml creates. If the first scheduled run fails with a permission error or a 404, grant this repository Admin under each package's "Manage Actions access".
  • Third-party action: packages: write on GITHUB_TOKEN reaches every package this repository administers, release packages included. Pinning by commit is the control; review Renovate bumps of this action with that in mind.
  • Suggested rollout: after the first main builds publish, dispatch once (dry run is the default) and read the job summary. The tagged versions it lists for main/mecak8s should all be v* tags, with no sha256-*.sbom entries.

🤖 Generated with Claude Code

@Nashon-Steffen Nashon-Steffen left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

This PR adds a daily, CI-only job that prunes the four main/ GHCR packages with a pinned dataaxiom/ghcr-cleanup-action. The approach is sound. The action applies the age filter before keep-n, so "everything younger than 7 days plus the newest N older" is what actually happens. Slash-containing package names are encoded correctly, the dry-run expression gives the right value on both triggers, and the permissions are minimal.

One retention bug needs fixing before the schedule deletes anything. Because of how ko publishes main/mecak8s, that package keeps about 10 older builds rather than 30, so older kept charts point at deleted images. The other comments are smaller: one about failure visibility and some comment accuracy.

# Finding Severity Score
1 ko per-platform .sbom tags count toward keep-n-tagged, so main/mecak8s keeps about 10 older builds HIGH 8/10
2 The existence check reports a permission 404 as a green "nothing to prune" MEDIUM 9/10
3 The header comment describes cleanup inaccurately (orphans aren't age-gated; there are no .sig/.att tags) LOW 8/10
4 Retention guarantees are stated without their conditions LOW 8/10
5 A live (non-dry-run) dispatch isn't restricted to main LOW 7/10
6 validate: true only warns, after deleting LOW 8/10

Verifying #1: the dry run in the PR used mecatl/studio, which buildx publishes and which has no per-platform SBOM tags. Running the same dry run against the release package mecatl/mecak8s, which ko publishes the same way continuous.yml does, with keep-n-tagged: 5 should list sha256-<child>.sbom entries among the tagged versions it keeps and deletes.

Hardening (optional): packages: write can also delete release-package versions. Lowering this repository's role from Admin to Write on the release packages would make "release packages are never named" an enforced boundary rather than a convention. A separate Renovate rule for this action, with a release-age delay, would keep its bumps out of the grouped actions PR.

🤖 Generated with Claude Code

fail-fast: false
matrix:
include:
- {package: mecatl/main/mecak8s, keep: 30}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ko's per-platform SBOM tags count toward keep-n-tagged, so this package keeps about 10 older builds, not 30. (HIGH)

continuous.yml builds this image with ko build --platform=linux/amd64,linux/arm64 --sbom=spdx. ko pushes one SBOM per platform child, each under a sha256-<child>.sbom tag. You can see this in the release package mecatl/mecak8s: every release has an index plus two tagged sha256-<child>.sbom versions (for example, v0.0.47 has sha256-a6e49b…sbom and sha256-b4b95c…sbom).

In v1.2.2, initFilterSet (manifest-analyzer.ts:125-151) iterates a Set and deletes from it as it goes. The API lists the index before its children, so when it visits the index it deletes the children from the set before visiting them. Their .sbom referrer tags are only removed when the child itself is visited, so those SBOM versions stay in the filter set as top-level tagged images. collectKeepNTaggedCandidates (deletion-strategy.ts:264-276) counts any version with a tag. Each mecak8s build therefore uses 3 of the 30 slots, so about 10 older builds survive while each chart package keeps 20. Older kept charts then pin mecak8s digests that have been deleted, which breaks the guarantee in the header and README. main/studio (buildx, no per-child SBOMs) isn't affected.

Possible fixes:

  • Drop --sbom=spdx from the ko step in ci: publish signed main builds of mecak8s, Studio, and their charts #2292. The anchore SBOM is already attested with cosign attest.
  • Or limit what keep-n counts, for example with a per-package delete-tags matching only the version tags. While keep-n-tagged is set, keep-n counts only the matched tags and nothing is deleted by tag alone (deletion-strategy.ts:91-93, 248-262).

Either way, dry-run against mecatl/mecak8s to confirm.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in ced717d. Added delete-tags: '*-main.*' so keep-n-tagged counts only the version tags (v<version> images, <version> charts). The per-platform sha256-<child>.sbom versions no longer take slots and are removed as orphans the run after their image goes.

Comment thread .github/workflows/prune-main-builds.yml Outdated
encoded=$(jq -rn --arg p "$PACKAGE" '$p | @uri')
if gh api "/orgs/${OWNER}/packages/container/${encoded}" --silent 2> lookup.err; then
echo "found=true" >> "$GITHUB_OUTPUT"
elif grep -q 'HTTP 404' lookup.err; then

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A permission 404 is reported as "not published yet" and the job stays green. (MEDIUM)

The Packages API returns 404 both for a package that doesn't exist and for a private package the token can't see. If this repository loses Actions access to a main/ package, or a path here drifts from continuous.yml, this leg posts a notice and succeeds every day. Pruning stops and storage grows without anyone noticing. Without this check, the action would have failed loudly on the same 404 (package-repo.ts:232-252).

continuous.yml publishes all four packages in its first run, so the bootstrap window this check covers is short. Suggestion: once #2292 has published, remove the check or fail on 404. At minimum, use ::warning with "not found or not accessible to this repository".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in ced717d. Removed the pre-check: #2292 merging runs continuous.yml on its own merge commit, so the packages exist before this lands on main, and a missing or inaccessible package now fails its job via the action's own 404.

Comment thread .github/workflows/prune-main-builds.yml Outdated
Comment on lines +9 to +14
# signatures whose image is gone are removed once they pass the same age.
#
# ghcr-cleanup-action deletes a multi-arch image together with its platform
# manifests, its sha256-<digest>.{sig,att,sbom} tags, and its OCI referrers
# (the build-provenance attestations), so nothing a kept build needs is
# removed. Deleting a version needs the Admin role on the package, which the

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The header doesn't match what the action and the publisher actually do. (LOW)

  • Line 9: orphaned signatures are not age-gated. findOrphanedImages scans every tag and subject referrer in the package (image-validator.ts:199-228), and the orchestrator adds the results straight to the delete set, without checking the age-filtered set (cleanup-orchestrator.ts:206-213). Orphans are removed on the next run, whatever their age.
  • Line 12: cosign v3 publishes signatures and attestations as a sha256-<digest> referrer-tag index with no suffix. The only suffixed tags are ko's .sbom tags. The release mecatl/mecak8s package has no .sig or .att tags.
  • Lines 13-14: cascading deletion stops a pruned build from leaving leftovers. What keeps a kept build intact is that children and referrers are never deletion candidates on their own. Also, per-platform .sbom tags are not cascaded (image-deleter.ts:315-358); they become orphans and go on the following run.

Suggested wording: "…its platform manifests and its signature, SBOM, and attestation artifacts (sha256- tags or OCI referrers). Orphans are removed whenever found."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in ced717d. The header now says orphaned artifacts are removed whenever found (not age-gated), describes artifacts as sha256- tags or OCI referrers rather than .sig/.att suffixes, and separates cascade cleanup from why kept builds stay intact.

Comment thread .github/workflows/prune-main-builds.yml Outdated
Comment on lines +5 to +8
# older ones (20 charts, 30 images). Images keep more than charts, so every kept
# chart still resolves its digest-pinned images even when a few runs failed
# between pushing an image and pushing the charts. Followers select the newest
# chart, so they never run a pruned build. Untagged leftovers of failed runs and

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The retention guarantees are stated without their conditions. (LOW)

  • Kept charts: "every kept chart still resolves its digest-pinned images" holds only while there are at most 10 image-only runs in the older window (30 − 20, once mecatui: subagent / Task visibility (agent hierarchy dashboard) #1 on line 49 is fixed). A failed mecak8s run is tagged by ko and uses a slot; a failed studio run stays untagged and doesn't. README line 37 states the guarantee with no condition at all.
  • Followers: "they never run a pruned build" holds only for followers that keep up. A paused or stuck follower more than 7 days and 20 builds behind loses its images, and its next pod reschedule fails to pull.

Suggest stating both bounds here and in the README.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in ced717d. The header and README now state the 10-failed-run margin and that a follower more than 7 days and 20 builds behind loses its images.

Comment thread .github/workflows/prune-main-builds.yml Outdated

jobs:
prune:
if: github.repository == 'stacklok/mecatl'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A live dispatch isn't restricted to main. (LOW)

Anyone with write access can dispatch from any branch. That runs the branch's copy of this workflow with packages: write and dry_run=false, including any edited package names or keep counts. continuous.yml gates its dispatch on github.ref == 'refs/heads/main' (continuous.yml:78). Suggestion:

Suggested change
if: github.repository == 'stacklok/mecatl'
if: github.repository == 'stacklok/mecatl' && github.ref == 'refs/heads/main'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in ced717d. The job condition now also requires github.ref == 'refs/heads/main'; scheduled runs use the default branch, so they are unaffected.

keep-n-tagged: ${{ matrix.keep }}
delete-untagged: true
delete-orphaned-images: true
validate: true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validate doesn't act as a safety gate. (LOW)

It runs after deletion (cleanup-orchestrator.ts:266-272) and reports problems with core.warning. The orchestrator ignores the hasErrors it returns, so a run that breaks a kept image still finishes green, and on a schedule nobody reads the annotations. Keeping it for diagnostics is fine. If you want a real check that kept charts still resolve, add a follow-up step that resolves the pinned image digest of each kept chart and fails if one is missing.

@Nashon-Steffen Nashon-Steffen Oct 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in ced717d. Kept validate for diagnostics and marked it advisory in a comment, and the header no longer claims nothing a kept build needs can be removed.

Nashon-Steffen added a commit that referenced this pull request Oct 13, 2026
ko tags each platform image's SBOM as sha256-<digest>.sbom, and the
cleanup action counted those versions toward keep-n-tagged, so
main/mecak8s kept about 10 older builds instead of 30 and older kept
charts pinned deleted images. Restrict keep-n to the *-main.* version
tags. Drop the package-existence pre-check so a package this repository
can't access fails its job instead of passing with a notice, prune only
from main's copy of the workflow, and correct the comments and README on
orphan handling, artifact shapes, retention conditions, and validate.

Addresses #2293 review comments:
- HIGH .github/workflows/prune-main-builds.yml:49 (4262507174): ko per-platform .sbom tags used keep-n-tagged slots
- MEDIUM .github/workflows/prune-main-builds.yml:67 (4262507191): permission 404 reported as a green notice
- LOW .github/workflows/prune-main-builds.yml:9-14 (4262507204): header misdescribed orphan and artifact cleanup
- LOW .github/workflows/prune-main-builds.yml:5-8 (4262507212): retention guarantees stated without conditions
- LOW .github/workflows/prune-main-builds.yml:39 (4262507223): live dispatch not restricted to main
- LOW .github/workflows/prune-main-builds.yml:86 (4262507244): validate is advisory, not a gate

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Nashon-Steffen
Nashon-Steffen force-pushed the Nashon-Steffen/studio-continuous-main branch from 41db157 to 6a72e27 Compare October 13, 2026 19:59
Base automatically changed from Nashon-Steffen/studio-continuous-main to main October 13, 2026 19:59
Nashon-Steffen added a commit that referenced this pull request Oct 13, 2026
ko tags each platform image's SBOM as sha256-<digest>.sbom, and the
cleanup action counted those versions toward keep-n-tagged, so
main/mecak8s kept about 10 older builds instead of 30 and older kept
charts pinned deleted images. Restrict keep-n to the *-main.* version
tags. Drop the package-existence pre-check so a package this repository
can't access fails its job instead of passing with a notice, prune only
from main's copy of the workflow, and correct the comments and README on
orphan handling, artifact shapes, retention conditions, and validate.

Addresses #2293 review comments:
- HIGH .github/workflows/prune-main-builds.yml:49 (4262507174): ko per-platform .sbom tags used keep-n-tagged slots
- MEDIUM .github/workflows/prune-main-builds.yml:67 (4262507191): permission 404 reported as a green notice
- LOW .github/workflows/prune-main-builds.yml:9-14 (4262507204): header misdescribed orphan and artifact cleanup
- LOW .github/workflows/prune-main-builds.yml:5-8 (4262507212): retention guarantees stated without conditions
- LOW .github/workflows/prune-main-builds.yml:39 (4262507223): live dispatch not restricted to main
- LOW .github/workflows/prune-main-builds.yml:86 (4262507244): validate is advisory, not a gate

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Nashon-Steffen
Nashon-Steffen force-pushed the Nashon-Steffen/prune-main-builds branch from ced717d to d1a7255 Compare October 13, 2026 19:59
Nashon-Steffen and others added 2 commits October 13, 2026 13:00
continuous.yml publishes two images and two charts for every main
commit that passes CI, roughly a dozen builds a day, and nothing removes
them. Add a daily job that prunes only the four main/ packages: each
keeps every build younger than 7 days plus the newest 20 older charts
and 30 older images, so every kept chart still resolves its digest-pinned
images.

dataaxiom/ghcr-cleanup-action (pinned by commit) deletes a multi-arch
image together with its platform manifests, cosign and SBOM tags, and
OCI referrers, and removes untagged leftovers of failed runs and orphaned
signatures. A package that has not been published yet is skipped, and a
manual dispatch defaults to a dry run.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
ko tags each platform image's SBOM as sha256-<digest>.sbom, and the
cleanup action counted those versions toward keep-n-tagged, so
main/mecak8s kept about 10 older builds instead of 30 and older kept
charts pinned deleted images. Restrict keep-n to the *-main.* version
tags. Drop the package-existence pre-check so a package this repository
can't access fails its job instead of passing with a notice, prune only
from main's copy of the workflow, and correct the comments and README on
orphan handling, artifact shapes, retention conditions, and validate.

Addresses #2293 review comments:
- HIGH .github/workflows/prune-main-builds.yml:49 (4262507174): ko per-platform .sbom tags used keep-n-tagged slots
- MEDIUM .github/workflows/prune-main-builds.yml:67 (4262507191): permission 404 reported as a green notice
- LOW .github/workflows/prune-main-builds.yml:9-14 (4262507204): header misdescribed orphan and artifact cleanup
- LOW .github/workflows/prune-main-builds.yml:5-8 (4262507212): retention guarantees stated without conditions
- LOW .github/workflows/prune-main-builds.yml:39 (4262507223): live dispatch not restricted to main
- LOW .github/workflows/prune-main-builds.yml:86 (4262507244): validate is advisory, not a gate

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Nashon-Steffen
Nashon-Steffen force-pushed the Nashon-Steffen/prune-main-builds branch from d1a7255 to 4c5c1d0 Compare October 13, 2026 20:00
@Nashon-Steffen
Nashon-Steffen merged commit 2cda452 into main Oct 13, 2026
5 checks passed
@Nashon-Steffen
Nashon-Steffen deleted the Nashon-Steffen/prune-main-builds branch October 13, 2026 20:00
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Oct 20, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants