From 4f6a7d5c0ce455e6a8ea88adb4d59ed3c13babd2 Mon Sep 17 00:00:00 2001 From: Christof Marti Date: Sun, 22 Nov 2026 11:23:04 +0100 Subject: [PATCH 1/3] Check owner IDs of added and changed collection index entries Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .github/scripts/check-collection-index.sh | 77 +++++++++++++++++++++++ .github/workflows/lint.yml | 16 +++++ 2 files changed, 93 insertions(+) create mode 100644 .github/scripts/check-collection-index.sh diff --git a/.github/scripts/check-collection-index.sh b/.github/scripts/check-collection-index.sh new file mode 100644 index 00000000..b480555f --- /dev/null +++ b/.github/scripts/check-collection-index.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash +# Checks the entries of _data/collection-index.yml that were added or changed compared to the given git ref: +# required properties are present, and ghcr.io collections have an ownerId matching the owner's GitHub account ID. +# Usage: check-collection-index.sh +set -euo pipefail + +INDEX=_data/collection-index.yml +BASE_REF=${1:?Usage: $0 } +ERRORS=0 + +error() { + echo "::error file=$INDEX::$1" + ERRORS=$((ERRORS + 1)) +} + +# Prints the numeric ID of a GitHub account, nothing if it doesn't exist, and fails on other errors. +github_user_id() { + local login=$1 resp status=403 + resp=$(mktemp) + fetch() { curl -sS -o "$resp" -w '%{http_code}' -H 'Accept: application/vnd.github+json' "$@" "https://api.github.com/users/$login"; } + if [ -n "${GITHUB_TOKEN:-}" ]; then + status=$(fetch -H "Authorization: Bearer $GITHUB_TOKEN") + fi + if [ "$status" = 403 ]; then + # Organizations with an IP allow list reject the Actions token, even for public profile data. + status=$(fetch) + fi + case $status in + 200) jq -r '.id' "$resp" ;; + 404) ;; + *) + echo "::error::Failed to look up GitHub account '$login': HTTP $status $(jq -r '.message // ""' "$resp" 2>/dev/null || true)" >&2 + return 1 + ;; + esac +} + +changed=$(jq -c -n \ + --argjson head "$(yq -o=json '.' "$INDEX")" \ + --argjson base "$(git show "$BASE_REF:$INDEX" | yq -o=json '.')" \ + '$head - $base | .[]') + +count=0 +while IFS= read -r entry; do + [ -n "$entry" ] || continue + count=$((count + 1)) + name=$(jq -r '.name // .ociReference // ""' <<<"$entry") + + for key in name maintainer contact repository ociReference; do + if [ -z "$(jq -r --arg key "$key" '.[$key] // "" | tostring' <<<"$entry")" ]; then + error "'$name': Missing '$key'." + fi + done + + oci=$(jq -r '.ociReference // ""' <<<"$entry") + if [[ "$(tr '[:upper:]' '[:lower:]' <<<"$oci")" != ghcr.io/* ]]; then + continue + fi + + owner=$(cut -d/ -f2 <<<"$oci") + owner_id=$(jq -r 'if (.ownerId | type) == "number" then .ownerId else "" end' <<<"$entry") + if ! [[ "$owner" =~ ^[A-Za-z0-9-]+$ ]]; then + error "'$name': '$oci' doesn't start with 'ghcr.io//'." + elif [ -z "$owner_id" ]; then + error "'$name': Missing or non-numeric 'ownerId'. Set it to the numeric 'id' from https://api.github.com/users/$owner." + else + id=$(github_user_id "$owner") + if [ -z "$id" ]; then + error "'$name': GitHub account '$owner' not found." + elif [ "$id" != "$owner_id" ]; then + error "'$name': 'ownerId' is $owner_id, but GitHub account '$owner' has ID $id." + fi + fi +done <<<"$changed" + +echo "Checked $count added or changed entries, found $ERRORS problems." +[ "$ERRORS" -eq 0 ] diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 8ffa44c1..ae2f5df7 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -3,6 +3,8 @@ on: pull_request: paths: - _data/collection-index.yml + - .github/scripts/check-collection-index.sh + - .github/workflows/lint.yml permissions: contents: read @@ -24,3 +26,17 @@ jobs: yamllint_comment: true env: GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + entries: + name: 'Check added and changed entries' + runs-on: ubuntu-latest + steps: + - name: 'Checkout' + uses: actions/checkout@v6 + - name: 'Check entries' + run: | + git fetch --depth=1 origin "$BASE_REF" + bash .github/scripts/check-collection-index.sh FETCH_HEAD + env: + BASE_REF: ${{ github.base_ref }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 4dbcb5f6f8c4f67755ea50bcf1ffe02f2614e793 Mon Sep 17 00:00:00 2001 From: Christof Marti Date: Sun, 22 Nov 2026 11:23:45 +0100 Subject: [PATCH 2/3] Temporary: exercise the entry check in CI (to be reverted) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- _data/collection-index.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/_data/collection-index.yml b/_data/collection-index.yml index 5be6bf4f..b6e9ccdc 100644 --- a/_data/collection-index.yml +++ b/_data/collection-index.yml @@ -1421,7 +1421,7 @@ ociReference: ghcr.io/mattmazzola/devcontainers ownerId: 2856501 - name: W&B Catnip - maintainer: Weights and Biases + maintainer: Weights and Biases (test) contact: https://github.com/wandb/catnip/issues repository: https://github.com/wandb/catnip ociReference: ghcr.io/wandb/catnip/feature @@ -1934,3 +1934,9 @@ repository: https://github.com/mchawa/eidos ociReference: ghcr.io/mchawa/eidos ownerId: 78374013 +- name: Reused name (test) + maintainer: Test + contact: https://github.com/git-saj/x/issues + repository: https://github.com/git-saj/x + ociReference: ghcr.io/git-saj/x + ownerId: 1 From 75674d68b6f47f142c4638c6c2b1e47fe0b420fa Mon Sep 17 00:00:00 2001 From: Christof Marti Date: Sun, 22 Nov 2026 11:24:37 +0100 Subject: [PATCH 3/3] Revert temporary CI test Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- _data/collection-index.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/_data/collection-index.yml b/_data/collection-index.yml index b6e9ccdc..5be6bf4f 100644 --- a/_data/collection-index.yml +++ b/_data/collection-index.yml @@ -1421,7 +1421,7 @@ ociReference: ghcr.io/mattmazzola/devcontainers ownerId: 2856501 - name: W&B Catnip - maintainer: Weights and Biases (test) + maintainer: Weights and Biases contact: https://github.com/wandb/catnip/issues repository: https://github.com/wandb/catnip ociReference: ghcr.io/wandb/catnip/feature @@ -1934,9 +1934,3 @@ repository: https://github.com/mchawa/eidos ociReference: ghcr.io/mchawa/eidos ownerId: 78374013 -- name: Reused name (test) - maintainer: Test - contact: https://github.com/git-saj/x/issues - repository: https://github.com/git-saj/x - ociReference: ghcr.io/git-saj/x - ownerId: 1