From 2c7572da005415c43e9d022a6fceebd95bbdbeb4 Mon Sep 17 00:00:00 2001 From: Max Davis Date: Sun, 22 Nov 2026 15:19:19 -0800 Subject: [PATCH 1/2] chore: retain only the newest three SHA-only GHCR versions --- .github/workflows/publish.yml | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9e64f3e..81d1b70 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -52,3 +52,39 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + + # Keep only three newest SHA-only versions; preserve releases and untagged manifests. + - name: Prune old SHA-only image versions + uses: actions/github-script@v8 + env: + GHCR_CLEANUP_PACKAGES: rerun + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const owner = context.repo.owner; + const packageType = 'container'; + const packageNames = process.env.GHCR_CLEANUP_PACKAGES.split(',').filter(Boolean); + for (const packageName of packageNames) { + const versions = await github.paginate( + github.rest.packages.getAllPackageVersionsForPackageOwnedByUser, + { username: owner, package_type: packageType, package_name: packageName, per_page: 100 } + ); + // A semver/latest tag on the same digest protects the entire version. + // Untagged versions (including multi-platform child manifests) are untouched. + const candidates = versions.filter(v => { + const tags = v.metadata?.container?.tags ?? []; + return tags.length === 1 && /^sha-[a-f0-9]{7,40}$/.test(tags[0]); + }).sort((a, b) => + Date.parse(b.created_at) - Date.parse(a.created_at) || b.id - a.id + ); + core.info(`${packageName}: ${candidates.length} SHA-only versions; retaining newest 3.`); + for (const version of candidates.slice(3)) { + core.info(`Deleting ${packageName} ${version.metadata.container.tags[0]} (version ${version.id})`); + await github.rest.packages.deletePackageVersionForUser({ + username: owner, + package_type: packageType, + package_name: packageName, + package_version_id: version.id, + }); + } + } From 7dcd3636cb0aed01dfd96a0ae7c3c4e489de6699 Mon Sep 17 00:00:00 2001 From: Max Davis Date: Sun, 22 Nov 2026 15:50:30 -0800 Subject: [PATCH 2/2] chore: retain five SHA-only GHCR image versions --- .github/workflows/publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 81d1b70..9dfcacd 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -77,8 +77,8 @@ jobs: }).sort((a, b) => Date.parse(b.created_at) - Date.parse(a.created_at) || b.id - a.id ); - core.info(`${packageName}: ${candidates.length} SHA-only versions; retaining newest 3.`); - for (const version of candidates.slice(3)) { + core.info(`${packageName}: ${candidates.length} SHA-only versions; retaining newest 5.`); + for (const version of candidates.slice(5)) { core.info(`Deleting ${packageName} ${version.metadata.container.tags[0]} (version ${version.id})`); await github.rest.packages.deletePackageVersionForUser({ username: owner,