Publish APK certificate identity for multi-server compatibility
This commit is contained in:
+23
-1
@@ -144,12 +144,29 @@ def signing_dir():
|
||||
return directory
|
||||
|
||||
|
||||
def apk_signing_fingerprint(output):
|
||||
"""Read one verified APK signer identity, never private key material."""
|
||||
try:
|
||||
value = (output / "signing-certificate-sha256.txt").read_text().strip().lower()
|
||||
except OSError as error:
|
||||
raise ValueError("APK build is missing its verified signing certificate fingerprint") from error
|
||||
if len(value) != 64 or any(c not in "0123456789abcdef" for c in value):
|
||||
raise ValueError("APK build must report exactly one SHA-256 signing certificate fingerprint")
|
||||
return value
|
||||
|
||||
|
||||
def build(kind, runner=subprocess.run, app=APP, cache=None, arguments=(), log=print):
|
||||
"""The directory holding the finished [kind] build, built only when needed."""
|
||||
cache = Path(cache) if cache else default_cache()
|
||||
key = digest(kind, app, arguments)
|
||||
entry = cache / f"{kind}-{key}"
|
||||
usable = web_cache_complete(entry) if kind == "web" else (entry / ".complete").is_file()
|
||||
if kind == "apk" and usable:
|
||||
try:
|
||||
apk_signing_fingerprint(entry)
|
||||
usable = (entry / "pipelines.apk").is_file()
|
||||
except ValueError:
|
||||
usable = False
|
||||
if kind == "linux":
|
||||
usable = usable and (entry / "pipelines-app").is_file() and (entry / "data/flutter_assets").is_dir() and (entry / "lib").is_dir()
|
||||
if usable:
|
||||
@@ -188,6 +205,8 @@ def build(kind, runner=subprocess.run, app=APP, cache=None, arguments=(), log=pr
|
||||
code = built // 60
|
||||
stamp = (f"--build-number={code}", f"--build-name=0.1.{code}")
|
||||
docker(runner, *command, tag, "pipelines-app-build", kind, *build_arguments, *stamp)
|
||||
if kind == "apk":
|
||||
apk_signing_fingerprint(work)
|
||||
if kind == "linux" and not ((work / "pipelines-app").is_file() and
|
||||
(work / "data/flutter_assets").is_dir() and (work / "lib").is_dir()):
|
||||
raise RuntimeError("Linux build did not produce its complete executable/data/lib bundle")
|
||||
@@ -253,6 +272,8 @@ def build_apk(prefix, server_url=None, notes="", runner=subprocess.run, log=prin
|
||||
# reuse one APK and every rebuild is newer than the last.
|
||||
arguments = (f"--dart-define=PIPELINES_SERVER_URL={server}",)
|
||||
output = build("apk", runner, arguments=arguments, log=log)
|
||||
fingerprint = apk_signing_fingerprint(output)
|
||||
apk_sha256 = hashlib.sha256((output / "pipelines.apk").read_bytes()).hexdigest()
|
||||
built = json.loads((output / ".complete").read_text())["built"]
|
||||
code = built // 60
|
||||
target = Path(updates)
|
||||
@@ -260,7 +281,8 @@ def build_apk(prefix, server_url=None, notes="", runner=subprocess.run, log=prin
|
||||
shutil.copyfile(output / "pipelines.apk", target / "pipelines.apk.next")
|
||||
os.replace(target / "pipelines.apk.next", target / "pipelines.apk")
|
||||
(target / "version.json").write_text(json.dumps({
|
||||
"versionCode": code, "versionName": f"0.1.{code}", "apk": "pipelines.apk", "notes": notes}) + "\n")
|
||||
"versionCode": code, "versionName": f"0.1.{code}", "apk": "pipelines.apk", "notes": notes,
|
||||
"signingCertificateSha256": fingerprint, "sha256": apk_sha256}) + "\n")
|
||||
log(f"APK ready: {target / 'pipelines.apk'} (build {code}, server {server}).")
|
||||
log("Phones get it from Settings → App updates → Check for updates, or download "
|
||||
f"{server.replace('wss://', 'https://').replace('ws://', 'http://').removesuffix('/connect')}/updates/pipelines.apk")
|
||||
|
||||
Reference in New Issue
Block a user