Skip to content

Delete Untagged Packages #65

Delete Untagged Packages

Delete Untagged Packages #65

name: Delete Untagged
env:
PER_PAGE: 100
on:
workflow_dispatch:
workflow_run:
workflows: ["Docker Image CI", "Docker Image CI - buildx experiment"]
types:
- completed
jobs:
delete-untagged:
runs-on: ubuntu-latest
steps:
-
run: |
echo "PACKAGE_NAME=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}
echo "OWNER=orgs/${GITHUB_REPOSITORY_OWNER,,}" >> ${GITHUB_ENV}
-
uses: actions/github-script@v3
with:
github-token: ${{ secrets.DELETE_PACKAGES_TOKEN }}
script: |
const response = await github.request("GET /${{ env.OWNER }}/packages/container/${{ github.event.repository.name }}/versions",
{ per_page: ${{ env.PER_PAGE }}
});
for(version of response.data) {
if (version.metadata.container.tags.length == 0) {
console.log("delete " + version.id)
const deleteResponse = await github.request("DELETE /${{ env.OWNER }}/packages/container/${{ github.event.repository.name }}/versions/" + version.id, { });
console.log("status " + deleteResponse.status)
}
}