Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ jobs:
GH_TOKEN: ${{ github.token }}
run: |
previous="$RUNNER_TEMP/adoption-history.json"
artifact=$(gh api "repos/$GITHUB_REPOSITORY/actions/artifacts?name=adoption-history&per_page=30" --jq '[.artifacts[] | select(.expired == false and .workflow_run.head_branch == "main")]
| max_by(.created_at) | .id // empty')
if [ -n "$artifact" ]; then
gh api "repos/$GITHUB_REPOSITORY/actions/artifacts/$artifact/zip" > "$RUNNER_TEMP/adoption-history.zip"
unzip -p "$RUNNER_TEMP/adoption-history.zip" adoption-history.json > "$previous"
archive="$RUNNER_TEMP/adoption-history.zip"
artifact=$(gh api "repos/$GITHUB_REPOSITORY/actions/artifacts?name=adoption-history&per_page=30" \
--jq '[.artifacts[] | select(.expired == false and .workflow_run.head_branch == "main")]
| max_by(.created_at) | .id // empty') || artifact=""
if [ -n "$artifact" ] \
&& gh api "repos/$GITHUB_REPOSITORY/actions/artifacts/$artifact/zip" > "$archive" \
&& unzip -p "$archive" adoption-history.json > "$previous.tmp"; then
mv "$previous.tmp" "$previous"
fi
python scripts/adoption_snapshot.py --previous "$previous"
python scripts/adoption_snapshot.py --previous "$previous" --restore-published
- name: Sum downloads across PyPI, npm and NuGet
if: github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'schedule')
run: python scripts/total_downloads.py
Expand Down
2 changes: 1 addition & 1 deletion docs/adoption.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Baseline **2026-11-29** (UTC). Waiting for the first snapshot on or after **2027

## Snapshots

The scheduled Docs workflow keeps the published baseline and carries later snapshots forward. For captures on the same UTC date, the latest successful value is kept for each metric. npm values must also describe the same download window.
The scheduled Docs workflow keeps the published baseline and carries later snapshots forward. The public history is used if the previous CI artifact is unavailable. For captures on the same UTC date, the latest successful value is kept for each metric. npm values must also describe the same download window.

| Date | Stars | Forks | External contributors | npm downloads | PyPI downloads | NuGet downloads | Public directory listings | Verified integrations |
| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
Expand Down
24 changes: 17 additions & 7 deletions scripts/adoption_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

REPO = "https://github.com/jmmana/sqlguardllm"
API = "https://api.github.com/repos/jmmana/sqlguardllm"
PUBLISHED_HISTORY = "https://jmmana.github.io/sqlguardllm/assets/adoption-history.json"
PYPI_STATS = "https://pypistats.org/api/packages/sqlguardllm/recent"
NUGET_QUERY = "/query?q=packageid%3ASqlGuardLlm&prerelease=true"
NUGET = "https://azuresearch-usnc.nuget.org" + NUGET_QUERY
Expand Down Expand Up @@ -170,15 +171,18 @@ def record_snapshot(history, row):
history[row["date"]] = merged


def load_history(previous):
def load_history(previous, *, restore_published=False):
"""Restore daily captures while keeping the published baseline authoritative."""
history = {BASELINE["date"]: BASELINE}
if previous is None or not previous.is_file():
if previous and previous.is_file():
rows = json.loads(previous.read_text(encoding="utf-8"))
elif restore_published:
rows = get_json(PUBLISHED_HISTORY)
else:
return history

rows = json.loads(previous.read_text(encoding="utf-8"))
if not isinstance(rows, list):
raise ValueError("Adoption history must be a list of daily captures")
if not isinstance(rows, list) or (restore_published and not rows):
raise ValueError("Adoption history must contain a list of daily captures")
for row in rows:
if not isinstance(row, dict) or not isinstance(row.get("date"), str):
raise ValueError("Adoption history contains a capture without a date")
Expand Down Expand Up @@ -274,7 +278,8 @@ def render(history):
"## Snapshots",
"",
"The scheduled Docs workflow keeps the published baseline and carries later "
"snapshots forward. For captures on the same UTC date, "
"snapshots forward. The public history is used if the previous CI artifact "
"is unavailable. For captures on the same UTC date, "
"the latest successful value is kept for "
"each metric. npm values must also describe the same download window.",
"",
Expand Down Expand Up @@ -332,11 +337,16 @@ def render(history):
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--previous", type=Path)
parser.add_argument(
"--restore-published",
action="store_true",
help="use the published history if the previous artifact is unavailable",
)
parser.add_argument(
"--offline", action="store_true", help="Render without collecting live metrics"
)
args = parser.parse_args()
history = load_history(args.previous)
history = load_history(args.previous, restore_published=args.restore_published)
if not args.offline:
row = collect(datetime.now(timezone.utc))
if row["date"] > BASELINE["date"]:
Expand Down
34 changes: 34 additions & 0 deletions tests/test_adoption_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,37 @@ def test_public_directory_sources_have_distribution_evidence() -> None:
for name, url in script["LISTINGS"].items():
row = next(line for line in tracker.splitlines() if line.startswith(f"| {name} |"))
assert f"]({url})" in row


def test_published_history_is_used_only_when_artifact_is_missing(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
script = runpy.run_path(str(SCRIPT))
load_history = script["load_history"]
baseline = script["BASELINE"]
published = {**baseline, "date": "2026-12-04", "stars": 20}
calls = []

def read(url: str) -> list:
calls.append(url)
return [baseline, published]

monkeypatch.setitem(load_history.__globals__, "get_json", read)
artifact = tmp_path / "adoption-history.json"
assert load_history(artifact, restore_published=True)[published["date"]] == published
assert calls == [script["PUBLISHED_HISTORY"]]

newer = {**published, "date": "2026-12-05", "stars": 21}
artifact.write_text(json.dumps([baseline, newer]), encoding="utf-8")
assert load_history(artifact, restore_published=True)[newer["date"]] == newer
assert calls == [script["PUBLISHED_HISTORY"]]


def test_empty_published_history_fails_before_replacing_captures(
monkeypatch: pytest.MonkeyPatch,
) -> None:
load_history = runpy.run_path(str(SCRIPT))["load_history"]
monkeypatch.setitem(load_history.__globals__, "get_json", lambda _url: [])

with pytest.raises(ValueError, match="list of daily captures"):
load_history(None, restore_published=True)
Loading