Android build v1.1.26
This commit is contained in:
+44
-15
@@ -5,6 +5,7 @@ import json
|
||||
import os
|
||||
import queue
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import threading
|
||||
@@ -153,6 +154,48 @@ def gitea_request(
|
||||
except urllib.error.HTTPError as exc:
|
||||
data = exc.read()
|
||||
return exc.code, data
|
||||
except urllib.error.URLError as exc:
|
||||
raise ReleaseError(f"{method} {url} failed: {exc.reason}") from exc
|
||||
|
||||
|
||||
def gitea_upload_asset(config: ReleaseConfig, path: str, apk_path: Path) -> tuple[int, bytes]:
|
||||
curl = shutil.which("curl")
|
||||
if curl is None:
|
||||
raise ReleaseError("curl is required for Gitea asset uploads")
|
||||
|
||||
url = config.gitea_url.rstrip("/") + path
|
||||
proc = subprocess.run(
|
||||
[
|
||||
curl,
|
||||
"--silent",
|
||||
"--show-error",
|
||||
"--retry",
|
||||
"3",
|
||||
"--retry-all-errors",
|
||||
"--retry-delay",
|
||||
"2",
|
||||
"--request",
|
||||
"POST",
|
||||
url,
|
||||
"--header",
|
||||
f"Authorization: token {config.token}",
|
||||
"--form",
|
||||
f"attachment=@{apk_path}",
|
||||
"--write-out",
|
||||
"\n%{http_code}",
|
||||
],
|
||||
check=False,
|
||||
capture_output=True,
|
||||
)
|
||||
if proc.returncode != 0:
|
||||
detail = (proc.stderr or proc.stdout).decode("utf-8", "replace").strip()
|
||||
raise ReleaseError(f"Gitea asset upload failed: curl exited {proc.returncode}: {detail}")
|
||||
try:
|
||||
body, status_text = proc.stdout.rsplit(b"\n", 1)
|
||||
return int(status_text), body
|
||||
except ValueError as exc:
|
||||
output = proc.stdout.decode("utf-8", "replace")
|
||||
raise ReleaseError(f"Gitea asset upload returned malformed curl output: {output}") from exc
|
||||
|
||||
|
||||
def parse_json_response(status: int, data: bytes, action: str) -> dict:
|
||||
@@ -211,26 +254,12 @@ def upload_release_asset(config: ReleaseConfig, log: Callable[[str], None]) -> N
|
||||
raise ReleaseError(f"APK not found for release upload: {apk_path}")
|
||||
release_id = find_or_create_release(config, log)
|
||||
|
||||
boundary = f"----iwanttoheal{int(time.time() * 1000)}"
|
||||
header = (
|
||||
f"--{boundary}\r\n"
|
||||
f'Content-Disposition: form-data; name="attachment"; filename="{apk_path.name}"\r\n'
|
||||
"Content-Type: application/vnd.android.package-archive\r\n\r\n"
|
||||
).encode("utf-8")
|
||||
footer = f"\r\n--{boundary}--\r\n".encode("utf-8")
|
||||
body = header + apk_path.read_bytes() + footer
|
||||
asset_name = urllib.parse.quote(apk_path.name)
|
||||
path = (
|
||||
f"/api/v1/repos/{config.gitea_owner}/{config.gitea_repo}"
|
||||
f"/releases/{release_id}/assets?name={asset_name}"
|
||||
)
|
||||
status, data = gitea_request(
|
||||
config,
|
||||
"POST",
|
||||
path,
|
||||
body=body,
|
||||
content_type=f"multipart/form-data; boundary={boundary}",
|
||||
)
|
||||
status, data = gitea_upload_asset(config, path, apk_path)
|
||||
if status == 409:
|
||||
raise ReleaseError(f"Release asset already exists: {apk_path.name}")
|
||||
parse_json_response(status, data, "Upload release asset")
|
||||
|
||||
Reference in New Issue
Block a user