How To
-
Create a Personal Access Token (PAT) with the following scopes: a.
repob.delete:packagesc.read:org -
Log in to GitHub CLI using
gh auth login: a. Select:github.comb. Protocol:httpsc. Authentication method: Use the generated token -
Create a shell script,
remove-image-untagged-batch.sh:#!/bin/bash GH_ORG="organization" PACKAGE_NAME="repo" VERSIONS=$(gh api --paginate "https://api.github.com/orgs/$GH_ORG/packages/container/$PACKAGE_NAME/versions" | jq -r '.[] | select(.metadata.container.tags == []) | .id') for VERSION in $VERSIONS; do echo "Deleting untagged image version ID: $VERSION" gh api --silent --method DELETE "https://api.github.com/orgs/$GH_ORG/packages/container/$PACKAGE_NAME/versions/$VERSION" done