From 5f9acd345fb990e3c723b15a3b2b445ec5a68139 Mon Sep 17 00:00:00 2001 From: Peter Gallwas Date: Tue, 12 Nov 2024 21:14:56 +1300 Subject: [PATCH] Now? --- .github/workflows/dlold.yml | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/.github/workflows/dlold.yml b/.github/workflows/dlold.yml index 7f96d79..7183a5a 100644 --- a/.github/workflows/dlold.yml +++ b/.github/workflows/dlold.yml @@ -1,15 +1,9 @@ name: Clean up old packages on: - push: - tags: - - 'cr*' - branches: - - 'master' - - 'dev' schedule: - - cron: '0 0 * * 0' # Run weekly on Sunday at midnight - workflow_dispatch: # Allow manual trigger + - cron: '0 0 * * 0' + workflow_dispatch: jobs: cleanup: @@ -19,15 +13,36 @@ jobs: contents: read steps: - - name: Delete old packages + - name: Delete untagged and SHA packages uses: actions/delete-package-versions@v5 with: package-name: 10 package-type: 'container' - min-versions-to-keep: 10 - delete-only-untagged-versions: false + min-versions-to-keep: 0 + delete-only-untagged-versions: true # Target untagged/SHA versions ignore-versions: | master dev cr* token: ${{ github.token }} + + - name: Delete SHA tagged packages + uses: actions/github-script@v7 + with: + script: | + const pkgs = await github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({ + package_type: 'container', + package_name: '10', + org: context.repo.owner + }); + + for (const pkg of pkgs.data) { + if (pkg.metadata.container.tags.some(tag => tag.startsWith('sha256:'))) { + await github.rest.packages.deletePackageVersionForOrg({ + package_type: 'container', + package_name: '10', + org: context.repo.owner, + package_version_id: pkg.id + }); + } + } \ No newline at end of file