diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index ec0cdd16e..68e00a194 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -166,11 +166,22 @@ jobs: gh release delete "$old_tag" --cleanup-tag -y || true fi done + echo "Determining GHCR owner type..." + OWNER_TYPE=$(gh api -H "Accept: application/vnd.github+json" \ + /users/${{ github.repository_owner }} --jq '.type') + + if [ "$OWNER_TYPE" = "Organization" ]; then + BASE_URL="/orgs/${{ github.repository_owner }}/packages/container" + else + BASE_URL="/users/${{ github.repository_owner }}/packages/container" + fi + + PACKAGE_URL="$BASE_URL/${{ github.event.repository.name }}/versions" + 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" \ + UNTAGGED_VERSIONS=$(gh api --paginate -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ - /user/packages/container/picoclaw/versions \ + "$PACKAGE_URL" \ --jq '.[] | select((.metadata.container.tags | length) == 0) | .id' 2>/dev/null || true) for version_id in $UNTAGGED_VERSIONS; do @@ -178,22 +189,21 @@ jobs: 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 + "$PACKAGE_URL/$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" \ + OLD_NIGHTLY_VERSIONS=$(gh api --paginate -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ - /user/packages/container/picoclaw/versions \ - --jq ". | map(select(any(.metadata.container.tags[]; startswith(\"nightly-\") and (. != \"nightly\") and (. != \"$TAG\"))) | .id) | unique[]" 2>/dev/null || true) + "$PACKAGE_URL" \ + --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 + "$PACKAGE_URL/$version_id" || true fi done