Skip to content

Commit

Permalink
WIP container cleanup script
Browse files Browse the repository at this point in the history
  • Loading branch information
rnijveld committed Apr 7, 2024
1 parent 0c7c80c commit 4d180fe
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/container-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Container Cleanup

permissions:
contents: read
packages: write

on:
pull_request:

jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Remove untagged docker images
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const versions = await github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({
package_type: 'container',
package_name: 'debian',
org: context.repo.owner,
per_page: 100,
state: 'active',
});
const to_remove = [];
for (const p of versions.data) {
if ((p.metadata?.container?.tags ?? []).length === 0) {
to_remove.push({
id: p.id,
name: p.name,
});
}
}
console.log(`Found ${to_remove.length} untagged container images to remove`);
for (const r of to_remove) {
await github.rest.packages.deletePackageVersionForOrg({
package_type: 'container',
package_name: 'debian',
org: context.repo.owner,
package_version_id: r.id,
});
console.log(`Deleted untagged container image ${r.name}`);
}

0 comments on commit 4d180fe

Please sign in to comment.