Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 11181c14d5 |
+35
-29
@@ -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(
|
||||
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}",
|
||||
},
|
||||
# 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}",
|
||||
],
|
||||
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,18 +269,24 @@ 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
|
||||
rel = _gitea_api(
|
||||
base,
|
||||
token,
|
||||
"POST",
|
||||
f"/repos/{repo}/releases",
|
||||
{
|
||||
"tag_name": f"v{target}",
|
||||
"name": f"v{target}",
|
||||
"body": body,
|
||||
"prerelease": bool(args.breaking_db),
|
||||
},
|
||||
)
|
||||
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,
|
||||
"POST",
|
||||
f"/repos/{repo}/releases",
|
||||
{
|
||||
"tag_name": f"v{target}",
|
||||
"name": f"v{target}",
|
||||
"body": body,
|
||||
"prerelease": bool(args.breaking_db),
|
||||
},
|
||||
)
|
||||
release_id = rel["id"]
|
||||
for artifact in dist.iterdir():
|
||||
if artifact.name == "checksums.txt" or artifact.suffix in {".whl", ".tgz", ".gz"}:
|
||||
|
||||
Reference in New Issue
Block a user