Frontend Manager: avoid redundant gh calls for static versions

This commit is contained in:
Alex "mcmonkey" Goodwin 2024-10-04 11:49:41 -07:00
parent 6f021d8aa0
commit 762c267821

View File

@ -151,6 +151,15 @@ class FrontendManager:
return cls.DEFAULT_FRONTEND_PATH
repo_owner, repo_name, version = cls.parse_version_string(version_string)
if version.startswith("v"):
expected_path = str(Path(cls.CUSTOM_FRONTENDS_ROOT) / f"{repo_owner}_{repo_name}" / version.lstrip("v"))
if os.path.exists(expected_path):
logging.info(f"Using existing copy of specific frontend version tag: {repo_owner}/{repo_name}@{version}")
return expected_path
logging.info(f"Initializing frontend: {repo_owner}/{repo_name}@{version}, requesting version details from GitHub...")
provider = provider or FrontEndProvider(repo_owner, repo_name)
release = provider.get_release(version)
@ -159,16 +168,21 @@ class FrontendManager:
Path(cls.CUSTOM_FRONTENDS_ROOT) / provider.folder_name / semantic_version
)
if not os.path.exists(web_root):
tmp_path = web_root + ".tmp"
if os.path.exists(tmp_path):
os.rmdir(tmp_path)
try:
os.makedirs(web_root, exist_ok=True)
os.makedirs(tmp_path, exist_ok=True)
logging.info(
"Downloading frontend(%s) version(%s) to (%s)",
provider.folder_name,
semantic_version,
web_root,
tmp_path,
)
logging.debug(release)
download_release_asset_zip(release, destination_path=web_root)
download_release_asset_zip(release, destination_path=tmp_path)
if os.listdir(tmp_path):
os.rename(tmp_path, web_root)
finally:
# Clean up the directory if it is empty, i.e. the download failed
if not os.listdir(web_root):