ci: handle missing Gitea release when syncing release body

This commit is contained in:
2026-05-02 22:07:13 +02:00
parent 576706dc17
commit c10249d171
+50 -13
View File
@@ -156,16 +156,53 @@ jobs:
env: env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
run: | run: |
tag="${{ github.ref_name }}" python3 - <<'PY'
body=$(cat release_body.md) import json
# Get release ID by tag import os
release_id=$(curl -s \ import urllib.error
-H "Authorization: token ${GITEA_TOKEN}" \ import urllib.request
"https://gitea.emulab.it/api/v1/repos/Simone/nsis-plugin-ns7zip/releases/tags/${tag}" \
| python3 -c "import sys,json; print(json.load(sys.stdin)['id'])") base = "https://gitea.emulab.it/api/v1"
# Update release body repo = "Simone/nsis-plugin-ns7zip"
curl -s -X PATCH \ tag = "${{ github.ref_name }}"
-H "Authorization: token ${GITEA_TOKEN}" \ token = os.environ["GITEA_TOKEN"]
-H "Content-Type: application/json" \
"https://gitea.emulab.it/api/v1/repos/Simone/nsis-plugin-ns7zip/releases/${release_id}" \ with open("release_body.md", "r", encoding="utf-8") as f:
-d "{\"body\": $(echo "$body" | python3 -c "import sys,json; print(json.dumps(sys.stdin.read()))")}" body = f.read()
def request(method, path, payload=None):
data = json.dumps(payload).encode("utf-8") if payload is not None else None
req = urllib.request.Request(
f"{base}{path}",
data=data,
method=method,
headers={
"Authorization": f"token {token}",
"Content-Type": "application/json",
"Accept": "application/json",
},
)
with urllib.request.urlopen(req) as resp:
return json.loads(resp.read().decode("utf-8"))
try:
release = request("GET", f"/repos/{repo}/releases/tags/{tag}")
rid = release["id"]
request("PATCH", f"/repos/{repo}/releases/{rid}", {"body": body})
print(f"Updated existing Gitea release id={rid} for tag {tag}")
except urllib.error.HTTPError as e:
if e.code != 404:
raise
created = request(
"POST",
f"/repos/{repo}/releases",
{
"tag_name": tag,
"name": tag,
"body": body,
"draft": False,
"prerelease": False,
},
)
print(f"Created Gitea release id={created['id']} for tag {tag}")
PY