@@ -174,12 +174,14 @@ jobs:
174174 - name : Build data quality summary
175175 shell : bash
176176 run : |
177+ git -C TechAPI fetch --no-tags --depth=1 origin main
177178 python - <<'PY'
178179 from __future__ import annotations
179180
180181 import hashlib
181182 import json
182183 import re
184+ import subprocess
183185 from collections import Counter
184186 from pathlib import Path
185187 from typing import Any
@@ -213,6 +215,44 @@ jobs:
213215 def digest(path: Path) -> str:
214216 return hashlib.sha256(path.read_bytes()).hexdigest()
215217
218+ def changed_data_from_git() -> dict[str, dict[str, list[str]]]:
219+ changes = {
220+ category: {"added": [], "modified": [], "deleted": []}
221+ for category in CATEGORIES
222+ }
223+ output = subprocess.check_output(
224+ [
225+ "git",
226+ "-C",
227+ "TechAPI",
228+ "diff",
229+ "--name-status",
230+ "--no-renames",
231+ "FETCH_HEAD",
232+ "HEAD",
233+ "--",
234+ "data",
235+ ],
236+ text=True,
237+ )
238+ status_map = {"A": "added", "M": "modified", "D": "deleted"}
239+ for line in output.splitlines():
240+ parts = line.split("\t")
241+ if len(parts) < 2:
242+ continue
243+ bucket = status_map.get(parts[0][:1])
244+ path = parts[1]
245+ if bucket is None or not path.startswith("data/") or not path.endswith(".json"):
246+ continue
247+ rel = path.removeprefix("data/").replace("\\", "/")
248+ category = rel.split("/", 1)[0]
249+ if category in changes:
250+ changes[category][bucket].append(rel)
251+ for category_changes in changes.values():
252+ for paths in category_changes.values():
253+ paths.sort()
254+ return changes
255+
216256 def rel_site_files(root: Path) -> dict[str, Path]:
217257 site = root / "site"
218258 if not site.exists():
@@ -376,24 +416,16 @@ jobs:
376416 change_lines.append("| --- | ---: | ---: | ---: | ---: | ---: | ---: |")
377417
378418 all_added: list[tuple[str, str, Path]] = []
379- changed_by_category: dict[str, dict[str, list[str]]] = {}
419+ changed_by_category = changed_data_from_git()
380420 for category in CATEGORIES:
381- head = rel_jsons(HEAD, category)
382- base = rel_jsons(BASE, category)
383- added_keys = sorted(set(head) - set(base))
384- deleted_keys = sorted(set(base) - set(head))
385- modified_keys = sorted(
386- key for key in set(head) & set(base) if digest(head[key]) != digest(base[key])
387- )
388- changed_by_category[category] = {
389- "added": added_keys,
390- "modified": modified_keys,
391- "deleted": deleted_keys,
392- }
421+ added_keys = changed_by_category[category]["added"]
422+ modified_keys = changed_by_category[category]["modified"]
423+ deleted_keys = changed_by_category[category]["deleted"]
393424 added_verified = added_unverified = added_kaggle = 0
394425 for key in added_keys:
395- record = load_json(head[key])
396- all_added.append((category, key, head[key]))
426+ path = HEAD / key
427+ record = load_json(path)
428+ all_added.append((category, key, path))
397429 if verified_value(record) is True:
398430 added_verified += 1
399431 elif verified_value(record) is False:
0 commit comments