feat: Simplify keystore decoding process in build workflow using inline Python script
Build Android APK / build-apk (push) Failing after 13m51s

This commit is contained in:
2026-04-08 18:20:45 +07:00
parent 7ce286b63b
commit 68837362e1
+3 -52
View File
@@ -2,6 +2,8 @@ name: Build Android APK
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
release_tag:
@@ -85,58 +87,7 @@ jobs:
if [ -n "${ANDROID_KEYSTORE_BASE64}" ] && [ -n "${ANDROID_KEYSTORE_PASSWORD}" ] && [ -n "${ANDROID_KEY_ALIAS}" ] && [ -n "${ANDROID_KEY_PASSWORD}" ]; then
echo "Preparing release keystore from secrets"
if ! python3 - <<'PY'
import base64
import os
import re
import sys
s = os.environ.get("ANDROID_KEYSTORE_BASE64", "")
if not s:
print("ANDROID_KEYSTORE_BASE64 is empty")
sys.exit(1)
# Normalize common copy/paste formats.
s = s.strip().strip('"').strip("'")
s = s.replace("\\n", "")
s = re.sub(r"^data:[^,]*,", "", s)
s = re.sub(r"\s+", "", s)
if not s:
print("ANDROID_KEYSTORE_BASE64 is empty after normalization")
sys.exit(1)
def try_decode(value: str, urlsafe: bool, validate: bool):
value = value + ("=" * (-len(value) % 4))
if urlsafe:
value = value.replace("-", "+").replace("_", "/")
return base64.b64decode(value, validate=validate)
decoded = None
errors = []
for urlsafe in (False, True):
for validate in (True, False):
try:
decoded = try_decode(s, urlsafe=urlsafe, validate=validate)
if decoded:
break
except Exception as e:
errors.append(str(e))
if decoded:
break
if not decoded:
print("Failed to decode ANDROID_KEYSTORE_BASE64")
print("Tip: generate with: base64 < release.jks | tr -d '\\n'")
if errors:
print("Last decode error:", errors[-1])
sys.exit(1)
with open("android/release.keystore", "wb") as f:
f.write(decoded)
print(f"Decoded keystore bytes: {len(decoded)}")
PY
if ! python3 -c "import base64,os,re,sys; s=os.environ.get('ANDROID_KEYSTORE_BASE64',''); s=s.strip().strip(chr(34)).strip(chr(39)); s=s.replace('\\n',''); s=re.sub(r'^data:[^,]*,','',s); s=re.sub(r'\\s+','',s); s=s + ('=' * (-len(s) % 4)); (print('ANDROID_KEYSTORE_BASE64 is empty after normalization'), sys.exit(1)) if not s else None; d=base64.b64decode(s, validate=False); open('android/release.keystore','wb').write(d); print('Decoded keystore bytes:', len(d))"
then
echo "Keystore decoding failed"
exit 1