diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index ca4edc2ab..6741b9c76 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -165,3 +165,34 @@ jobs: gh release delete "$old_tag" --cleanup-tag -y || true fi done + echo "Cleaning up all untagged Docker images on GHCR..." + # Get all version IDs for the package that have no tags + UNTAGGED_VERSIONS=$(gh api -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + /user/packages/container/picoclaw/versions \ + --jq '.[] | select((.metadata.container.tags | length) == 0) | .id' 2>/dev/null || true) + + for version_id in $UNTAGGED_VERSIONS; do + if [ -n "$version_id" ]; then + echo "Deleting untagged Docker image version ID: $version_id" + gh api --method DELETE -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "/user/packages/container/picoclaw/versions/$version_id" || true + fi + done + + echo "Cleaning up old 'nightly-YYYYMMDD-SHA' Docker images on GHCR..." + # Fetch all version IDs where at least one tag starts with "nightly-", excluding the current newly created $TAG + OLD_NIGHTLY_VERSIONS=$(gh api -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + /user/packages/container/picoclaw/versions \ + --jq ".[] | select(.metadata.container.tags[] | startswith(\"nightly-\") and (. != \"nightly\") and (. != \"$TAG\")) | .id" 2>/dev/null || true) + + for version_id in $OLD_NIGHTLY_VERSIONS; do + if [ -n "$version_id" ]; then + echo "Deleting old nightly Docker image version ID: $version_id" + gh api --method DELETE -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "/user/packages/container/picoclaw/versions/$version_id" || true + fi + done