From 9a4b7e709b731f366134c6c57f88659c0e066bc4 Mon Sep 17 00:00:00 2001 From: Anatoli Nicolae Date: Mon, 12 Feb 2024 22:59:30 +0100 Subject: [PATCH] Add ghcr.io cleanup workflow Signed-off-by: Anatoli Nicolae --- .github/workflows/ghcr_cleanup.yml | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/ghcr_cleanup.yml diff --git a/.github/workflows/ghcr_cleanup.yml b/.github/workflows/ghcr_cleanup.yml new file mode 100644 index 000000000..343f6aae0 --- /dev/null +++ b/.github/workflows/ghcr_cleanup.yml @@ -0,0 +1,39 @@ +# https://github.com/Koenkk/zigbee2mqtt/blob/fe0742a628fb782692f9679367e2ab1b11139dd6/.github/workflows/ghcr_cleanup.yml + +name: ๐Ÿงน ghcr.io Cleanup + +on: + workflow_dispatch: + +permissions: + actions: write + contents: read + packages: write + +env: + PACKAGE_NAME: shelf + PER_PAGE: 2000 + +jobs: + clean: + runs-on: ubuntu-latest + + steps: + - name: ๐Ÿ—‘ Delete untagged images + uses: actions/github-script@v7 + with: + script: | + const response = await github.request("GET /user/packages/container/${{ env.PACKAGE_NAME }}/versions", + { per_page: ${{ env.PER_PAGE }} + }); + for(version of response.data) { + if (version.metadata.container.tags.length == 0) { + try { + console.log("delete " + version.id) + const deleteResponse = await github.request("DELETE /user/packages/container/${{ env.PACKAGE_NAME }}/versions/" + version.id, { }); + console.log("status " + deleteResponse.status) + } catch (e) { + console.log("failed") + } + } + }