1 Commits

+22 -16
View File
@@ -103,24 +103,24 @@ def _gitea_api(base: str, token: str, method: str, path: str, payload: dict | No
def _upload_asset(base: str, token: str, repo: str, release_id: int, path: Path) -> None:
boundary = "----evosci-release"
data = path.read_bytes()
body = (
f"--{boundary}\r\n"
f'Content-Disposition: form-data; name="attachment"; filename="{path.name}"\r\n'
f"Content-Type: application/octet-stream\r\n\r\n"
).encode() + data + f"\r\n--{boundary}--\r\n".encode()
req = urllib.request.Request(
# curl -F: urllib's hand-rolled multipart gets a 403 from Gitea
subprocess.run(
[
"curl",
"-sS",
"-f",
"-X",
"POST",
"-H",
f"Authorization: token {token}",
"-F",
f"attachment=@{path}",
f"{base}/api/v1/repos/{repo}/releases/{release_id}/assets?name={path.name}",
data=body,
method="POST",
headers={
"Authorization": f"token {token}",
"Content-Type": f"multipart/form-data; boundary={boundary}",
},
],
check=True,
capture_output=True,
text=True,
)
with urllib.request.urlopen(req, timeout=300):
pass
def main(argv=None, *, run=subprocess.run, repo_root: Path | None = None) -> int:
@@ -269,6 +269,12 @@ def main(argv=None, *, run=subprocess.run, repo_root: Path | None = None) -> int
body = "\n\n".join(notes) or f"Release v{target}"
if args.breaking_db:
body = "BREAKING-DB\n\n" + body
try:
rel = _gitea_api(base, token, "GET", f"/repos/{repo}/releases/tags/v{target}")
print(f" reusing existing release v{target} (id {rel['id']})")
except urllib.error.HTTPError as e:
if e.code != 404:
raise
rel = _gitea_api(
base,
token,