From 1db12612e6887b11d9fe964e25c622ef6d4a4811 Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Wed, 1 Jun 2022 14:18:41 +0200 Subject: [PATCH] Add GHCR cleanup (#12669) * Create ghcr_cleanup.yml * Update ghcr_cleanup.yml * Update ghcr_cleanup.yml * Update ghcr_cleanup.yml * Update ghcr_cleanup.yml --- .github/workflows/ghcr_cleanup.yml | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 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..c0bfa569d --- /dev/null +++ b/.github/workflows/ghcr_cleanup.yml @@ -0,0 +1,35 @@ +on: + workflow_dispatch: + schedule: + - cron: "0 4 * * *" + +name: ghcr cleanup + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Delete untagged images + uses: actions/github-script@v3 + with: + github-token: ${{ secrets.CR_PAT }} + script: | + const response = await github.request("GET /${{ env.OWNER }}/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 /${{ env.OWNER }}/packages/container/${{ env.PACKAGE_NAME }}/versions/" + version.id, { }); + console.log("status " + deleteResponse.status) + } catch (e) { + console.log("failed") + } + } + } + env: + OWNER: user + PACKAGE_NAME: zigbee2mqtt + PER_PAGE: 2000