mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-10-31 08:07:19 -05:00
fix: refuse an unknown mame or fbneo version
This commit is contained in:
1 parent
a848730a80
commit
a70ff264d2
3 files changed
+39
-18
No files matched your search
@@ -117,8 +117,11 @@ def _extract_version() -> tuple[str, str]:
|
|||||||
if t["name"] != "latest" and t["name"].startswith("v"):
|
if t["name"] != "latest" and t["name"].startswith("v"):
|
||||||
version = t["name"]
|
version = t["name"]
|
||||||
break
|
break
|
||||||
except (urllib.error.URLError, OSError):
|
except (urllib.error.URLError, OSError) as exc:
|
||||||
pass
|
raise RuntimeError(f"cannot determine the FBNeo version: {exc}") from exc
|
||||||
|
if version == "unknown":
|
||||||
|
# Written as core_version otherwise, and cached for a day.
|
||||||
|
raise RuntimeError("cannot determine the FBNeo version: no tag, resource.h or release")
|
||||||
|
|
||||||
sha_result = subprocess.run(
|
sha_result = subprocess.run(
|
||||||
["git", "rev-parse", "HEAD"],
|
["git", "rev-parse", "HEAD"],
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import logging
|
import logging
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
@@ -109,24 +110,28 @@ def _sparse_clone() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def _get_version() -> str:
|
def _get_version() -> str:
|
||||||
# version.cpp is generated at build time, not in the repo.
|
"""The latest MAME release, from the GitHub API.
|
||||||
# Use GitHub API to get the latest release tag.
|
|
||||||
|
version.cpp is generated at build time, not in the repo. A failed lookup
|
||||||
|
raises: "unknown" was cached for a day and written as core_version.
|
||||||
|
"""
|
||||||
|
headers = {
|
||||||
|
"User-Agent": "retrobios-scraper/1.0",
|
||||||
|
"Accept": "application/vnd.github.v3+json",
|
||||||
|
}
|
||||||
|
token = os.environ.get("GITHUB_TOKEN")
|
||||||
|
if token:
|
||||||
|
headers["Authorization"] = f"Bearer {token}"
|
||||||
|
url = "https://api.github.com/repos/mamedev/mame/releases/latest"
|
||||||
try:
|
try:
|
||||||
req = urllib.request.Request(
|
req = urllib.request.Request(url, headers=headers)
|
||||||
"https://api.github.com/repos/mamedev/mame/releases/latest",
|
|
||||||
headers={
|
|
||||||
"User-Agent": "retrobios-scraper/1.0",
|
|
||||||
"Accept": "application/vnd.github.v3+json",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
with urllib.request.urlopen(req, timeout=10) as resp:
|
with urllib.request.urlopen(req, timeout=10) as resp:
|
||||||
data = json.loads(resp.read())
|
tag = json.loads(resp.read()).get("tag_name", "")
|
||||||
tag = data.get("tag_name", "")
|
except (urllib.error.URLError, json.JSONDecodeError, OSError) as exc:
|
||||||
if tag:
|
raise RuntimeError(f"cannot read the MAME release from {url}: {exc}") from exc
|
||||||
return _parse_version_tag(tag)
|
if not tag:
|
||||||
except (urllib.error.URLError, json.JSONDecodeError, OSError):
|
raise RuntimeError(f"no tag_name in {url}")
|
||||||
pass
|
return _parse_version_tag(tag)
|
||||||
return "unknown"
|
|
||||||
|
|
||||||
|
|
||||||
def _parse_version_tag(tag: str) -> str:
|
def _parse_version_tag(tag: str) -> str:
|
||||||
|
|||||||
@@ -113,5 +113,18 @@ class RetroPieModuleFlags(unittest.TestCase):
|
|||||||
self.assertEqual(targets["x86_64"]["cores"], ["beetle_psx", "dosbox", "dosbox-staging"])
|
self.assertEqual(targets["x86_64"]["cores"], ["beetle_psx", "dosbox", "dosbox-staging"])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class HashScrapersRefuseAnUnknownVersion(unittest.TestCase):
|
||||||
|
"""mame_hash_scraper wrote core_version "unknown" after a failed API call
|
||||||
|
and cached it for a day; the pipeline step still read OK."""
|
||||||
|
|
||||||
|
def test_mame_raises(self):
|
||||||
|
from scripts.scraper import mame_hash_scraper # noqa: PLC0415
|
||||||
|
|
||||||
|
with mock.patch.object(mame_hash_scraper.urllib.request, "urlopen", _refuse), \
|
||||||
|
self.assertRaises(RuntimeError):
|
||||||
|
mame_hash_scraper._get_version()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
Reference in new issue
Block a user