release: v1.0.2
加固:release 构建 + R8 混淆,清理无用资源,修启动链路
This commit is contained in:
1 parent
967e93af98
commit
9b5038818f
1 file changed
+48
-18
+48
-18
@@ -242,18 +242,33 @@ def token() -> str:
|
|||||||
raise SystemExit("没有 token:设置环境变量 GITEA_TOKEN,或写 tools/.release-token")
|
raise SystemExit("没有 token:设置环境变量 GITEA_TOKEN,或写 tools/.release-token")
|
||||||
|
|
||||||
|
|
||||||
def api(path: str, method: str = "GET", body=None):
|
def api(path: str, method: str = "GET", body=None, tries: int = 5):
|
||||||
|
"""Gitea 走 Cloudflare,偶发 [SSL: UNEXPECTED_EOF] 直接断连,重试几次就好。"""
|
||||||
|
import ssl
|
||||||
|
import time
|
||||||
url = "%s/api/v1/repos/%s/%s%s" % (SITE, OWNER, REPO, path)
|
url = "%s/api/v1/repos/%s/%s%s" % (SITE, OWNER, REPO, path)
|
||||||
data = json.dumps(body, ensure_ascii=False).encode("utf-8") if body else None
|
data = json.dumps(body, ensure_ascii=False).encode("utf-8") if body else None
|
||||||
headers = {"Authorization": "token " + token(), "User-Agent": UA,
|
headers = {"Authorization": "token " + token(), "User-Agent": UA,
|
||||||
"Accept": "application/json", "Content-Type": "application/json"}
|
"Accept": "application/json", "Content-Type": "application/json"}
|
||||||
req = urllib.request.Request(url, data=data, method=method, headers=headers)
|
last = None
|
||||||
try:
|
for attempt in range(tries):
|
||||||
resp = urllib.request.urlopen(req, timeout=60)
|
req = urllib.request.Request(url, data=data, method=method, headers=headers)
|
||||||
txt = resp.read().decode("utf-8")
|
try:
|
||||||
return json.loads(txt) if txt.strip() else {}
|
resp = urllib.request.urlopen(req, timeout=90)
|
||||||
except urllib.error.HTTPError as exc:
|
txt = resp.read().decode("utf-8")
|
||||||
raise SystemExit("%s %s -> HTTP %s %s" % (method, path, exc.code, exc.read()[:300]))
|
return json.loads(txt) if txt.strip() else {}
|
||||||
|
except urllib.error.HTTPError as exc:
|
||||||
|
detail = exc.read()[:400]
|
||||||
|
# 4xx 是请求本身的问题,重试没意义,直接抛
|
||||||
|
if 400 <= exc.code < 500:
|
||||||
|
raise SystemExit("%s %s -> HTTP %s %s" % (method, path, exc.code, detail))
|
||||||
|
last = "HTTP %s %s" % (exc.code, detail)
|
||||||
|
except (urllib.error.URLError, ssl.SSLError, OSError) as exc:
|
||||||
|
last = "%s: %s" % (type(exc).__name__, exc)
|
||||||
|
wait = 2 * (attempt + 1)
|
||||||
|
print(" 第 %d 次失败(%s),%ds 后重试" % (attempt + 1, last, wait))
|
||||||
|
time.sleep(wait)
|
||||||
|
raise SystemExit("%s %s 连续 %d 次失败:%s" % (method, path, tries, last))
|
||||||
|
|
||||||
|
|
||||||
def tag_exists(tag: str) -> bool:
|
def tag_exists(tag: str) -> bool:
|
||||||
@@ -307,11 +322,13 @@ def run(cmd, cwd=None, check=True):
|
|||||||
def git_commit_push(where, msg):
|
def git_commit_push(where, msg):
|
||||||
run(["git", "add", "-A"], cwd=where)
|
run(["git", "add", "-A"], cwd=where)
|
||||||
r = run(["git", "status", "--porcelain"], cwd=where, check=False)
|
r = run(["git", "status", "--porcelain"], cwd=where, check=False)
|
||||||
if not (r.stdout or "").strip():
|
if (r.stdout or "").strip():
|
||||||
print(" 没有变更,跳过提交")
|
run(["git", "-c", "user.name=maipulse", "-c", "[email protected]",
|
||||||
return False
|
"commit", "-m", msg], cwd=where, check=False)
|
||||||
run(["git", "-c", "user.name=maipulse", "-c", "[email protected]",
|
else:
|
||||||
"commit", "-m", msg], cwd=where, check=False)
|
print(" 工作区无变更")
|
||||||
|
# 不管这次有没有新提交,都推一次:
|
||||||
|
# 上一次可能 commit 了但 push 失败,工作区是干净的,只看 status 会误判成"没变化"。
|
||||||
run(["git", "push", "origin", "HEAD:main"], cwd=where)
|
run(["git", "push", "origin", "HEAD:main"], cwd=where)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -393,11 +410,24 @@ def main():
|
|||||||
payload = head + blob + ("\r\n--%s--\r\n" % boundary).encode("utf-8")
|
payload = head + blob + ("\r\n--%s--\r\n" % boundary).encode("utf-8")
|
||||||
url = "%s/api/v1/repos/%s/%s/releases/%s/assets?name=maipulse-%s.apk" % (
|
url = "%s/api/v1/repos/%s/%s/releases/%s/assets?name=maipulse-%s.apk" % (
|
||||||
SITE, OWNER, REPO, rel.get("id"), new_ver)
|
SITE, OWNER, REPO, rel.get("id"), new_ver)
|
||||||
req = urllib.request.Request(url, data=payload, method="POST", headers={
|
asset = None
|
||||||
"Authorization": "token " + token(), "User-Agent": UA,
|
import ssl
|
||||||
"Content-Type": "multipart/form-data; boundary=" + boundary,
|
import time
|
||||||
})
|
for attempt in range(5):
|
||||||
asset = json.loads(urllib.request.urlopen(req, timeout=600).read().decode("utf-8"))
|
req = urllib.request.Request(url, data=payload, method="POST", headers={
|
||||||
|
"Authorization": "token " + token(), "User-Agent": UA,
|
||||||
|
"Content-Type": "multipart/form-data; boundary=" + boundary,
|
||||||
|
})
|
||||||
|
try:
|
||||||
|
asset = json.loads(urllib.request.urlopen(req, timeout=600).read().decode("utf-8"))
|
||||||
|
break
|
||||||
|
except urllib.error.HTTPError as exc:
|
||||||
|
raise SystemExit("上传失败 HTTP %s %s" % (exc.code, exc.read()[:400]))
|
||||||
|
except (urllib.error.URLError, ssl.SSLError, OSError) as exc:
|
||||||
|
print(" 第 %d 次上传失败(%s),重试" % (attempt + 1, exc))
|
||||||
|
time.sleep(3 * (attempt + 1))
|
||||||
|
if asset is None:
|
||||||
|
raise SystemExit("上传 APK 连续失败")
|
||||||
print(" %s %d B" % (asset.get("name"), asset.get("size")))
|
print(" %s %d B" % (asset.get("name"), asset.get("size")))
|
||||||
|
|
||||||
print("\n发版完成")
|
print("\n发版完成")
|
||||||
|
|||||||
Reference in new issue
Block a user