]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Allow configuring gen_build_info.py through environment variables (#25162)
authorAlex Nordlund <deep.alexander@gmail.com>
Mon, 12 Feb 2024 22:19:28 +0000 (23:19 +0100)
committerGitHub <noreply@github.com>
Mon, 12 Feb 2024 22:19:28 +0000 (15:19 -0700)
This makes the life of forks slightly easier by letting you pass an
environment variable instead of having to maintain this file yourself.

Tools/gen_build_info.py

index 0207f568dd72f067098ce8a25abb29e4073db185..0da5d7f48f6c97fa10b5bf74e172b80e0a8dc197 100755 (executable)
@@ -19,11 +19,11 @@ SERVER_FILES = [
     "SS14.Server_osx-x64.zip"
 ]
 
-VERSION = os.environ['GITHUB_SHA']
-FORK_ID = "wizards"
-BUILD_URL = f"https://cdn.centcomm.spacestation14.com/builds/wizards/builds/{{FORK_VERSION}}/{FILE}"
-MANIFEST_URL = f"https://cdn.centcomm.spacestation14.com/cdn/version/{{FORK_VERSION}}/manifest"
-MANIFEST_DOWNLOAD_URL = f"https://cdn.centcomm.spacestation14.com/cdn/version/{{FORK_VERSION}}/download"
+FORK_ID = os.environ.get("CDN_FORK_ID", "wizards")
+HOSTNAME = os.environ.get("CDN_HOSTNAME", "cdn.centcomm.spacestation14.com")
+BUILD_URL = f"https://{HOSTNAME}/builds/{FORK_ID}/builds/{{FORK_VERSION}}/{FILE}"
+MANIFEST_URL = f"https://{HOSTNAME}/version/{{FORK_VERSION}}/manifest"
+MANIFEST_DOWNLOAD_URL = f"https://{HOSTNAME}/version/{{FORK_VERSION}}/download"
 
 def main() -> None:
     client_file = os.path.join("release", FILE)
@@ -38,17 +38,25 @@ def inject_manifest(zip_path: str, manifest: str) -> None:
         z.writestr("build.json", manifest)
 
 
+def get_git_sha() -> str:
+    proc = subprocess.run(["git", "rev-parse", "HEAD"], stdout=subprocess.PIPE, check=True, encoding="UTF-8")
+    tag = proc.stdout.strip()
+    return tag
+
 def generate_build_json(file: str) -> str:
     # Env variables set by Jenkins.
 
     hash = sha256_file(file)
     engine_version = get_engine_version()
     manifest_hash = generate_manifest_hash(file)
+    version = os.environ.get("GITHUB_SHA")
+    if not version:
+        version = get_git_sha()
 
     return json.dumps({
         "download": BUILD_URL,
         "hash": hash,
-        "version": VERSION,
+        "version": version,
         "fork_id": FORK_ID,
         "engine_version": engine_version,
         "manifest_url": MANIFEST_URL,
@@ -56,6 +64,7 @@ def generate_build_json(file: str) -> str:
         "manifest_hash": manifest_hash
     })
 
+
 def generate_manifest_hash(file: str) -> str:
     zip = ZipFile(file)
     infos = zip.infolist()
@@ -83,7 +92,6 @@ def get_engine_version() -> str:
     assert tag.startswith("v")
     return tag[1:] # Cut off v prefix.
 
-
 def sha256_file(path: str) -> str:
     with open(path, "rb") as f:
         h = hashlib.sha256()