44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Create a scoped Gitea release for validated site configuration."""
|
|
|
|
import json
|
|
import os
|
|
import sys
|
|
import urllib.error
|
|
import urllib.request
|
|
|
|
|
|
def main() -> int:
|
|
if len(sys.argv) != 3:
|
|
raise SystemExit("usage: release.py TAG main|next")
|
|
tag, branch = sys.argv[1:]
|
|
if branch not in {"main", "next"}:
|
|
raise SystemExit("invalid branch")
|
|
token = os.environ["GITEA_TOKEN"]
|
|
api = os.environ.get("GITHUB_API_URL", "https://gitea.bluefla.re/api/v1").rstrip("/")
|
|
repo = os.environ["GITHUB_REPOSITORY"]
|
|
sha = os.environ["GITHUB_SHA"]
|
|
payload = json.dumps({
|
|
"tag_name": tag,
|
|
"target_commitish": sha,
|
|
"name": tag,
|
|
"body": f"Validated public benchmark site configuration from {sha}.",
|
|
"prerelease": branch == "next",
|
|
}).encode()
|
|
request = urllib.request.Request(
|
|
f"{api}/repos/{repo}/releases", data=payload, method="POST",
|
|
headers={"Authorization": "token " + token, "Content-Type": "application/json"},
|
|
)
|
|
try:
|
|
with urllib.request.urlopen(request, timeout=60) as response:
|
|
result = json.load(response)
|
|
except urllib.error.HTTPError as error:
|
|
print(f"release creation failed: HTTP {error.code}", file=sys.stderr)
|
|
return 1
|
|
print(f"Created {result['tag_name']}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|