Skip to content

The agent that grows with you

ci(skills-index): re-mint the App token before the catalog stars probe; keep fetched_at honest on failure

teknium1c3021aff0dcb
diff --git a/.github/workflows/skills-index.yml b/.github/workflows/skills-index.yml
index 6bcbbaaaa1a..4fec0fb43fc 100644
--- a/.github/workflows/skills-index.yml
+++ b/.github/workflows/skills-index.yml
@@ -54,9 +54,20 @@ jobs:
# Plugin-catalog star counts follow the same rule as the index: GitHub is consulted
# only here, on the schedule (one GraphQL request for every catalog repo), and docs
# deploys reuse the artifact / live copy without touching the API.
+ #
+ # Fresh token: the App installation token minted at job start lives 1 h, and the
+ # index walk above runs 60-85 min, so the probe used an expired token and 401'd on
+ # every scheduled run from Sep 18 (#118113). Mint again right before the probe.
+ - name: Get GitHub App token for the stars probe
+ id: probe-token
+ uses: ./.github/actions/get-app-token
+ with:
+ client-id: ${{ vars.APP_CLIENT_ID }}
+ private-key: ${{ secrets.APP_PRIVATE_KEY }}
+
- name: Probe plugin catalog stars
env:
- GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
+ GITHUB_TOKEN: ${{ steps.probe-token.outputs.token }}
run: python website/scripts/fetch-plugin-stars.py --probe
- name: Upload index artifact
diff --git a/tests/website/test_fetch_plugin_stars.py b/tests/website/test_fetch_plugin_stars.py
index b0d11344940..b9d430105d2 100644
--- a/tests/website/test_fetch_plugin_stars.py
+++ b/tests/website/test_fetch_plugin_stars.py
@@ -78,3 +78,20 @@ def test_probe_is_one_graphql_request_and_a_failure_keeps_previous_counts(mod, t
monkeypatch.setattr(mod, "_graphql", limited)
assert mod.main(catalog_dir=cat, output=out, probe=True, live_url=None, token="t") == 0
assert json.loads(out.read_text())["stars"] == {"a/one": 42, "b/two": 9}
+
+
+def test_failed_probe_keeps_the_previous_timestamp_and_warns(mod, tmp_path, monkeypatch, capsys):
+ """An expired-token 401 must not restamp ``fetched_at``: the catalog footer reads it as
+ "ranking as of <date>" and showed today's date over five-day-old counts (#118113)."""
+ cat = _catalog(tmp_path, "https://github.com/a/one", "https://github.com/b/two")
+ out = tmp_path / "plugin-stars.json"
+ out.write_text(json.dumps({"fetched_at": "2026-09-16T18:40:16+00:00", "stars": {"a/one": 7}}), encoding="utf-8")
+
+ def unauthorized(query, token):
+ raise urllib.error.HTTPError("u", 401, "Unauthorized", hdrs=None, fp=None)
+ monkeypatch.setattr(mod, "_graphql", unauthorized)
+
+ assert mod.main(catalog_dir=cat, output=out, probe=True, live_url=None, token="expired") == 0
+ data = json.loads(out.read_text())
+ assert data == {"fetched_at": "2026-09-16T18:40:16+00:00", "stars": {"a/one": 7}}
+ assert "::warning::" in capsys.readouterr().out
diff --git a/website/scripts/fetch-plugin-stars.py b/website/scripts/fetch-plugin-stars.py
index e10e6655434..9f16f01970f 100644
--- a/website/scripts/fetch-plugin-stars.py
+++ b/website/scripts/fetch-plugin-stars.py
@@ -111,18 +111,21 @@ def stars_query(slugs: list[str]) -> str:
return "query {\n" + fields + "\n}"
-def probe_stars(slugs: list[str], previous: dict[str, int], token: str | None) -> dict[str, int]:
- """One GraphQL request for all repos; on failure keep every previous count (never regress to 0)."""
+def probe_stars(slugs: list[str], previous: dict[str, int], token: str | None) -> tuple[dict[str, int], bool]:
+ """One GraphQL request for all repos -> ``(stars, probed)``. On failure keep every previous
+ count (never regress to 0) and report ``probed=False`` so the caller does not restamp
+ ``fetched_at`` over counts that are days old (#118113)."""
+ kept = {s: previous[s] for s in slugs if s in previous}
if not slugs:
- return {}
+ return {}, True
if not token:
_log("no GITHUB_TOKEN; keeping previous counts without probing")
- return {s: previous[s] for s in slugs if s in previous}
+ return kept, False
try:
payload = _graphql(stars_query(slugs), token)
except (urllib.error.URLError, OSError, ValueError) as e:
_log(f"GraphQL probe failed ({e}); keeping previous counts")
- return {s: previous[s] for s in slugs if s in previous}
+ return kept, False
data = payload.get("data") or {}
for err in payload.get("errors") or []:
_log(f"GraphQL: {err.get('message')}") # e.g. a renamed/deleted repo; its previous count is kept
@@ -133,7 +136,7 @@ def probe_stars(slugs: list[str], previous: dict[str, int], token: str | None) -
stars[slug] = node["stargazerCount"]
elif slug in previous:
stars[slug] = previous[slug]
- return stars
+ return stars, True
def main(catalog_dir: Path = DEFAULT_CATALOG_DIR, output: Path = DEFAULT_OUTPUT,
@@ -150,11 +153,17 @@ def main(catalog_dir: Path = DEFAULT_CATALOG_DIR, output: Path = DEFAULT_OUTPUT,
slugs = catalog_slugs(catalog_dir)
prev_stars = {k: int(v) for k, v in (previous.get("stars") or {}).items() if isinstance(v, (int, float))}
- stars = probe_stars(slugs, prev_stars, token or os.environ.get("GITHUB_TOKEN") or os.environ.get("GH_TOKEN"))
- probed = stars != prev_stars or not previous
- fetched_at = datetime.now(timezone.utc).isoformat() if probed or stars else str(previous.get("fetched_at") or "")
+ stars, probed = probe_stars(slugs, prev_stars, token or os.environ.get("GITHUB_TOKEN") or os.environ.get("GH_TOKEN"))
+ fetched_at = datetime.now(timezone.utc).isoformat() if probed else previous.get("fetched_at")
output.write_text(json.dumps({"fetched_at": fetched_at, "stars": stars}, separators=(",", ":")),
encoding="utf-8")
+ if not probed:
+ # Visible in the run summary: the ranking page would otherwise claim today's date over stale counts.
+ missing = len(slugs) - len(stars)
+ print(f"::warning::plugin star probe failed; reused {len(stars)} cached counts from {fetched_at}, "
+ f"{missing} of {len(slugs)} catalog repos have no star count")
+ print(f"Probe failed; wrote {len(stars)} cached star counts (as of {fetched_at}) to {output}")
+ return 0
print(f"Probed {len(slugs)} repos in one GraphQL request, wrote {len(stars)} star counts to {output}")
return 0