From 1ab46ff6cd5d9b7cbe6ec4142632ebb003ec220f Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Fri, 26 Jul 2024 14:31:55 +0200 Subject: [PATCH] Update container image cleanup GitHub actions Switch to dataaxiom/ghcr-cleanup-action which treats multi-arch images correctly and refactor the cleanup jobs so that we delete untagged versions once a day from Monday to Friday and delete PR tags once the PR is closed (merged or unmerged). --- .github/workflows/gitlab-container-image.yml | 8 ++++++++ .github/workflows/prune-old-container-images.yml | 12 +++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/gitlab-container-image.yml b/.github/workflows/gitlab-container-image.yml index bf8af21..721cc8b 100644 --- a/.github/workflows/gitlab-container-image.yml +++ b/.github/workflows/gitlab-container-image.yml @@ -46,3 +46,11 @@ jobs: platforms: linux/amd64,linux/arm64 push: true tags: 'ghcr.io/${{ env.IMAGE }}:${{ env.VERSION }}' + + - name: Delete PR container image when PR is closed + if: github.event.pull_request.state == 'closed' + uses: dataaxiom/ghcr-cleanup-action@v1 + with: + tags: ${{ env.VERSION }} + package: ${{ github.repository }}/gitlab + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/prune-old-container-images.yml b/.github/workflows/prune-old-container-images.yml index 641ef66..9a63bd7 100644 --- a/.github/workflows/prune-old-container-images.yml +++ b/.github/workflows/prune-old-container-images.yml @@ -1,5 +1,5 @@ --- -name: Prune old container images +name: Prune untagged container images "on": schedule: @@ -10,10 +10,8 @@ jobs: prune: runs-on: ubuntu-latest steps: - - uses: actions/delete-package-versions@v5 + - uses: dataaxiom/ghcr-cleanup-action@v1 with: - package-name: "${{ github.repository }}-gitlab" - package-type: container - # never delete release versions or latest - ignore-versions: "^(v.*|latest)$" - min-versions-to-keep: 3 + token: ${{ secrets.GITHUB_TOKEN }} + package: ${{ github.repository }}/gitlab + validate: true