How To
-
Create a Personal Access Token (PAT) with the following scopes: a.
repo
b.delete:packages
c.read:org
-
Log in to GitHub CLI using
gh auth login
: a. Select:github.com
b. Protocol:https
c. 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