How To

  1. Create a Personal Access Token (PAT) with the following scopes: a. repo b. delete:packages c. read:org

  2. Log in to GitHub CLI using gh auth login: a. Select: github.com b. Protocol: https c. Authentication method: Use the generated token

  3. 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