mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-10-20 18:59:07 -05:00
feat: record the commit a branch scrape read
Six platforms are read from a branch: System.dat, batocera-systems.json, checkBIOS.sh, the MiSTer BiosDB, the RetroPie scriptmodules and the RetroDECK component manifests. Their YAML named the branch, so the native export patched whatever the branch had become since the scrape. Each scraper now resolves the branch head once, reads every file at that commit and writes it into source. The export follows a recorded tarball and a recorded tree as it already followed a raw file URL.
This commit is contained in:
1 parent
eafb73bf55
commit
16f6ef8cbf
17 files changed
+203
-38
No files matched your search
@@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
import urllib.error
|
||||
@@ -296,6 +297,25 @@ def fetch_github_latest_version(repo: str) -> str:
|
||||
return tag
|
||||
|
||||
|
||||
def fetch_branch_head(repo: str, branch: str) -> str:
|
||||
"""The commit a branch of a GitHub repo points at right now.
|
||||
|
||||
A platform read from a moving branch records this sha in its source URL,
|
||||
so the exporter later patches the revision the data was read from and
|
||||
not whatever the branch has become. Raises like the release lookup.
|
||||
"""
|
||||
url = f"https://api.github.com/repos/{repo}/commits/{branch}"
|
||||
try:
|
||||
req = urllib.request.Request(url, headers=github_headers())
|
||||
with urllib.request.urlopen(req, timeout=15) as resp:
|
||||
sha = json.loads(resp.read()).get("sha", "")
|
||||
except (urllib.error.URLError, json.JSONDecodeError) as e:
|
||||
raise RuntimeError(f"cannot read the head of {repo}@{branch}: {e}") from e
|
||||
if not re.fullmatch(r"[0-9a-f]{40}", sha or ""):
|
||||
raise RuntimeError(f"{repo}@{branch} answered no commit sha")
|
||||
return sha
|
||||
|
||||
|
||||
class _PlatformDumper(yaml.SafeDumper):
|
||||
"""Quote scalars that a YAML reader could misparse.
|
||||
|
||||
|
||||
Reference in new issue
Block a user