@@ -22,7 +22,9 @@ permissions:
2222 packages : write # needed for deletions with GITHUB_TOKEN
2323
2424env :
25- UNTAGGED_RETENTION_DAYS : 2
25+ # Untagged versions are orphaned GHCR package versions left after tags move or manifests/caches are rewritten.
26+ UNTAGGED_RETENTION_HOURS : 12
27+ # Stale tagged versions still have tags, but those tags are no longer generated by the current image matrix.
2628 STALE_TAGGED_RETENTION_DAYS : 14
2729
2830jobs :
@@ -74,14 +76,14 @@ jobs:
7476 KEEP_TAGS : ${{ steps.keep-tags.outputs.json }}
7577 MANAGED_IMAGES : ${{ steps.keep-tags.outputs.images }}
7678 DRY_RUN : ${{ inputs.dry_run || 'false' }}
77- UNTAGGED_RETENTION_DAYS : ${{ env.UNTAGGED_RETENTION_DAYS }}
79+ UNTAGGED_RETENTION_HOURS : ${{ env.UNTAGGED_RETENTION_HOURS }}
7880 STALE_TAGGED_RETENTION_DAYS : ${{ env.STALE_TAGGED_RETENTION_DAYS }}
7981 with :
8082 script : |
8183 const keepTags = new Set(JSON.parse(process.env.KEEP_TAGS));
8284 const managedImages = JSON.parse(process.env.MANAGED_IMAGES);
8385 const dryRun = process.env.DRY_RUN === 'true';
84- const untaggedRetentionMs = Number(process.env.UNTAGGED_RETENTION_DAYS) * 24 * 60 * 60 * 1000;
86+ const untaggedRetentionMs = Number(process.env.UNTAGGED_RETENTION_HOURS) * 60 * 60 * 1000;
8587 const staleTaggedRetentionMs = Number(process.env.STALE_TAGGED_RETENTION_DAYS) * 24 * 60 * 60 * 1000;
8688 const now = Date.now();
8789
@@ -118,13 +120,15 @@ jobs:
118120 let deleted = 0;
119121 for (const version of versions) {
120122 const tags = version.metadata?.container?.tags ?? [];
123+ const createdAt = new Date(version.created_at).getTime();
121124 const updatedAt = new Date(version.updated_at).getTime();
122- const ageMs = now - updatedAt ;
125+ const ageMs = now - createdAt ;
123126 const tagList = tags.length ? tags.join(', ') : '<untagged>';
127+ const dates = `created ${version.created_at}, updated ${version.updated_at}`;
124128
125129 let reason = null;
126130 if (tags.length === 0 && ageMs > untaggedRetentionMs) {
127- reason = `untagged older than ${process.env.UNTAGGED_RETENTION_DAYS} days `;
131+ reason = `untagged older than ${process.env.UNTAGGED_RETENTION_HOURS} hours `;
128132 } else if (
129133 tags.length > 0 &&
130134 ageMs > staleTaggedRetentionMs &&
@@ -135,11 +139,11 @@ jobs:
135139 }
136140
137141 if (!reason) {
138- core.info(`keep ${version.id}: ${tagList}`);
142+ core.info(`keep ${version.id}: ${tagList} (${dates}) `);
139143 continue;
140144 }
141145
142- core.info(`${dryRun ? 'would delete' : 'delete'} ${version.id}: ${tagList} (${reason})`);
146+ core.info(`${dryRun ? 'would delete' : 'delete'} ${version.id}: ${tagList} (${reason}; ${dates} )`);
143147 if (!dryRun) {
144148 await deleteVersion({
145149 ...ownerArgs,
0 commit comments