From 162f20cc723ca791a5752b02f05239186aa2357f Mon Sep 17 00:00:00 2001 From: Andrew Hosgood Date: Mon, 25 Mar 2024 17:39:33 +0000 Subject: [PATCH] Delete untagged Docker images --- .github/workflows/remove-untagged.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/remove-untagged.yml diff --git a/.github/workflows/remove-untagged.yml b/.github/workflows/remove-untagged.yml new file mode 100644 index 0000000..e597b08 --- /dev/null +++ b/.github/workflows/remove-untagged.yml @@ -0,0 +1,27 @@ +name: Remove untagged container images + +on: + workflow_dispatch: + +jobs: + remove-untagged: + runs-on: ubuntu-latest + env: + PER_PAGE: 100 + steps: + - name: Delete untagged images + uses: actions/github-script@v6.3.3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const response = await github.request("GET /orgs/${{ github.repository_owner }}/packages/container/${{ vars.DOCKER_IMAGE_NAME }}/versions", + { per_page: ${{ env.PER_PAGE }} + }); + for(version of response.data) { + if (version.metadata.container.tags.length == 0 && version.name !== "latest" && version.name !== "preview") { + console.log("Delete " + version.id) + + const deleteResponse = await github.request("DELETE /orgs/${{ github.repository_owner }}/packages/container/${{ vars.DOCKER_IMAGE_NAME }}/versions/" + version.id, { }); + console.log("status " + deleteResponse.status) + } + }