chore: simplify workflows and unify tool logging and mail presentation
Release / Validate Templates (push) Successful in 2m55s
Release / Package & Release (push) Skipped
Release / Remind to Update Release Documentation (push) Skipped

This commit is contained in:
KenanZhu committed 2026-10-10 14:54:40 +08:00
1 parent f4d96de79e
commit c93f2bf8b2
40 files changed
+523 -1515

No files matched your search

+26 -50
View File
@@ -1,11 +1,10 @@
"""Gitea API operations for the tracker and release workflows (Python stdlib only)."""
"""Gitea API operations for the release workflow (Python stdlib only)."""
import argparse
import json
import os
from pathlib import Path
import re
import subprocess
from urllib.error import HTTPError
from urllib.parse import quote, urlencode, urlsplit
from urllib.request import HTTPRedirectHandler, Request, build_opener
@@ -50,56 +49,33 @@ class GiteaAPI:
raise RuntimeError(f"Gitea API {method} {path}: HTTP {status}") from None
def git(*args):
return subprocess.check_output(["git", *args], text=True).strip()
def create_pull_request(api, version):
if not re.fullmatch(r"\d+\.\d+\.\d+", version):
raise ValueError("Expected a stable X.Y.Z upstream version")
branch = "track/gitea-" + version
title = f"Track Gitea {version} compatibility"
changed = git("diff", "--name-only", "HEAD", "--").splitlines()
if any(not name.endswith(".md") for name in changed):
raise ValueError("Tracker may commit only Markdown changes")
if not changed:
print("[PASS] No tracked documentation changes")
return
# Repeated scheduled runs can find a branch from an earlier pending PR.
# Reuse identical content, but never force-push over a changed branch.
remote = git("ls-remote", "--heads", "origin", "refs/heads/" + branch)
if remote:
git("fetch", "origin", "refs/heads/" + branch)
if git("diff", "--name-only", "FETCH_HEAD", "--"):
raise ValueError(f"Existing {branch} differs; review it before updating the tracking PR")
else:
git("switch", "-c", branch)
git("add", "--", *changed)
git("-c", "user.name=release-bot", "-c", "user.email=release-bot@users.noreply.local",
"commit", "-m", f"docs: track Gitea {version} pending verification")
git("push", "origin", "HEAD:refs/heads/" + branch)
def create_issue(api, version):
if not re.fullmatch(r"v\d+\.\d+\.\d+", version):
raise ValueError("Expected a stable vX.Y.Z release tag")
marker = f"<!-- gitea-mail-templates:template-release:{version} -->"
title = f"Update documentation for template release {version}"
page = 1
while True:
pulls = api.request("GET", f"/pulls?state=open&base_branch=main&limit=50&page={page}")
for pull in pulls:
if (pull["head"]["ref"] == branch and pull["base"]["ref"] == "main"
and pull["head"]["repo"]["full_name"] == pull["base"]["repo"]["full_name"]):
print(f"[PASS] Tracking PR already exists: {pull['html_url']}")
return
if not pulls:
issues = api.request("GET", f"/issues?state=all&type=issues&limit=50&page={page}")
for issue in issues:
if issue.get("pull_request") is None and (marker in (issue.get("body") or "") or issue.get("title") == title):
print(f"[PASS] Reminder issue already exists: {issue['html_url']}")
return issue
if not issues:
break
page += 1
body = f"""Gitea **{version}** is recorded as [PENDING]. Verified/tested versions remain unchanged.
body = f"""{marker}
Template release **{version}** has been published. Documentation is maintained manually.
- [ ] Review upstream mail templates, mailer data, functions and translation keys.
- [ ] Run `go test ./...` and `go run . preview all` from `tools/`.
- [ ] Record results in `COMPATIBILITY.md`; update verified status only after testing.
- [ ] Release template changes separately with reviewed notes and assets.
- [ ] Update the release version in the English and Chinese READMEs.
- [ ] Review compatibility records and mark versions verified only according to test results.
- [ ] Check release links, release notes and remaining version references.
This reminder does not change repository files, branches or existing release assets.
"""
pull = api.request("POST", "/pulls", {"title": title, "head": branch, "base": "main", "body": body})
print(f"[PASS] Created tracking PR: {pull['html_url']}")
issue = api.request("POST", "/issues", {"title": title, "body": body})
print(f"[PASS] Created reminder issue: {issue['html_url']}")
return issue
def publish_release(api, version, root=Path(".")):
@@ -135,16 +111,16 @@ def publish_release(api, version, root=Path(".")):
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("operation", choices=("create-pull-request", "publish-release"))
parser.add_argument("operation", choices=("create-issue", "publish-release"))
parser.add_argument("--version", required=True)
args = parser.parse_args()
try:
api = GiteaAPI(os.environ.get("GITEA_SERVER_URL", ""), os.environ.get("GITEA_REPOSITORY", ""), os.environ.get("GITEA_TOKEN", ""))
if args.operation == "create-pull-request":
create_pull_request(api, args.version)
if args.operation == "create-issue":
create_issue(api, args.version)
else:
publish_release(api, args.version)
except (ValueError, KeyError, OSError, RuntimeError, subprocess.CalledProcessError) as error:
except (ValueError, KeyError, OSError, RuntimeError) as error:
parser.exit(1, f"[FAIL] {error}\n")