mirror of
https://github.com/debpalash/VoiceStudio.git
synced 2026-12-04 09:28:22 +00:00
The absent legs and installers are now found before any check can fail, and --missing-report is written in a finally block. A leg with an incomplete feed still fails the step, but the rehearsal's final step lists every leg that built nothing (review).
215 lines
11 KiB
Python
215 lines
11 KiB
Python
#!/usr/bin/env python3
|
|
"""Validate Electron artifacts and immutable Tauri sunset feeds."""
|
|
import base64
|
|
import argparse
|
|
import hashlib
|
|
import importlib.util
|
|
import json
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
from collections import Counter
|
|
from pathlib import Path
|
|
from urllib.parse import urlparse
|
|
from check_electron_release_assets import verify_release
|
|
|
|
def validate_sunset(manifest, tag):
|
|
if manifest.get("version") != tag.removeprefix("v"):
|
|
raise ValueError("Tauri version must match sunset tag")
|
|
if not manifest.get("platforms"):
|
|
raise ValueError("Missing Tauri platforms")
|
|
for entry in manifest["platforms"].values():
|
|
url = urlparse(entry.get("url", ""))
|
|
prefix = f"/debpalash/VoiceStudio/releases/download/{tag}/"
|
|
if url.scheme != "https" or url.netloc != "github.com" or not url.path.startswith(prefix):
|
|
raise ValueError("Tauri URLs must point to immutable sunset assets")
|
|
if not entry.get("signature"):
|
|
raise ValueError("Missing Tauri signature")
|
|
|
|
def channel_for(version):
|
|
"""`X.Y.Z` is Stable, `X.Y.Z-beta.N` is Beta; any other shape is not a release."""
|
|
if re.fullmatch(r"\d+\.\d+\.\d+", version):
|
|
return "stable"
|
|
if re.fullmatch(r"\d+\.\d+\.\d+-beta\.\d+", version):
|
|
return "beta"
|
|
raise ValueError(f"Not a stable or beta release version: {version}")
|
|
|
|
def _gh(*args):
|
|
return subprocess.run(["gh", *args], capture_output=True, text=True, check=True).stdout
|
|
|
|
|
|
# The same agent list the commit-identity gate uses: agents are never credited.
|
|
_spec = importlib.util.spec_from_file_location(
|
|
"agent_identities", Path(__file__).resolve().parents[1] / ".github" / "scripts" / "agent_identities.py")
|
|
agents = importlib.util.module_from_spec(_spec)
|
|
_spec.loader.exec_module(agents)
|
|
# GitHub's login for commits whose author email is not linked to any account.
|
|
UNLINKED_LOGIN = "invalid-email-address"
|
|
|
|
|
|
def is_credit_worthy(login):
|
|
"""People only: no bots, no AI agents, no unlinked-commit placeholder."""
|
|
name = login.removeprefix("app/").lower()
|
|
return not (login.startswith("app/") or name.endswith("[bot]")
|
|
or name in agents.AGENT_LOGINS or name == UNLINKED_LOGIN)
|
|
|
|
|
|
def contributors_section(repo, tag, gh=_gh, head=None):
|
|
"""A `### Contributors` block for everyone who contributed since the last stable release.
|
|
|
|
Two sources, because either alone misses people: commit authors in the tag
|
|
comparison (ranked by commit count), then authors of PRs merged since that
|
|
release whose commits are not linked to their GitHub account. The base is the
|
|
latest published stable release, so a beta and a stable release both cover the
|
|
whole span since the previous stable. Bots, AI agents and unlinked placeholders
|
|
are left out. Returns "" when there is nobody to thank. `head` replaces the
|
|
tag as the end of the comparison when the tag does not exist yet (a rehearsal).
|
|
"""
|
|
latest = gh("api", f"repos/{repo}/releases/latest", "--jq", ".tag_name + \" \" + .published_at").split()
|
|
base, since = latest[0], latest[1][:10]
|
|
ordered = _ranked_contributors(repo, base, since, head or tag, gh)
|
|
if not ordered:
|
|
return ""
|
|
mentions = ", ".join(f"@{login}" for login in ordered)
|
|
previous = _previous_beta(repo, tag, gh)
|
|
if not previous:
|
|
return f"### Contributors\n\nThanks to everyone who contributed to this release: {mentions}\n"
|
|
# A beta's notes span everything since the last stable, so its full list repeats
|
|
# from beta to beta; name who is new since the previous beta first.
|
|
new = _ranked_contributors(repo, previous[0], previous[1], head or tag, gh)
|
|
new_line = ", ".join(f"@{login}" for login in new) if new else "no new contributors"
|
|
return (f"### Contributors\n\nNew since {previous[0]}: {new_line}\n\n"
|
|
f"Everyone who contributed since {base}: {mentions}\n")
|
|
|
|
|
|
def _ranked_contributors(repo, base, since, head, gh):
|
|
commit_authors = gh("api", f"repos/{repo}/compare/{base}...{head}", "--paginate",
|
|
"--jq", ".commits[].author.login // empty").split()
|
|
pr_authors = gh("pr", "list", "--repo", repo, "--state", "merged", "--search", f"merged:>={since}",
|
|
"--limit", "1000", "--json", "author", "--jq", ".[].author.login").split()
|
|
counts = Counter(login for login in commit_authors if is_credit_worthy(login))
|
|
ordered = sorted(counts, key=lambda login: (-counts[login], login.lower()))
|
|
seen = {login.lower() for login in ordered}
|
|
for login in sorted({p for p in pr_authors if is_credit_worthy(p)}, key=str.lower):
|
|
if login.lower() not in seen:
|
|
ordered.append(login)
|
|
seen.add(login.lower())
|
|
return ordered
|
|
|
|
|
|
def _previous_beta(repo, tag, gh):
|
|
"""`(tag, publish date)` of the newest published earlier beta of this version, or None."""
|
|
match = re.fullmatch(r"(v\d+\.\d+\.\d+)-beta\.(\d+)", tag)
|
|
if not match:
|
|
return None
|
|
best = None
|
|
for line in gh("api", f"repos/{repo}/releases", "--paginate", "--jq",
|
|
'.[] | select(.draft | not) | .tag_name + " " + .published_at').splitlines():
|
|
parts = line.split()
|
|
other = re.fullmatch(rf"{re.escape(match[1])}-beta\.(\d+)", parts[0]) if len(parts) == 2 else None
|
|
if other and int(other[1]) < int(match[2]) and (best is None or int(other[1]) > best[0]):
|
|
best = (int(other[1]), parts[0], parts[1][:10])
|
|
return best and (best[1], best[2])
|
|
|
|
|
|
def prepare(assets, tag, sunset_tag=None, repo=None, gh=_gh, head=None, missing=None):
|
|
"""Verify the assets as release `tag` and write its notes and SHA256SUMS.txt.
|
|
|
|
`head` marks a rehearsal: `tag` is the one the package version would get and
|
|
does not exist, so the Contributors comparison ends at that commit instead.
|
|
`missing` (rehearsals only) collects build legs that produced nothing instead
|
|
of stopping at the first, so the legs that did build are still verified; the
|
|
caller must fail on a non-empty list.
|
|
"""
|
|
version = json.loads(Path("package.json").read_text(encoding="utf-8"))["version"]
|
|
if tag != f"v{version}":
|
|
raise ValueError("Tag must match package version")
|
|
channel = channel_for(version)
|
|
files = [p for p in assets.iterdir() if p.is_file()]
|
|
release = {"tagName": tag, "isPrerelease": channel == "beta", "assets": [
|
|
{"name": p.name, "size": p.stat().st_size,
|
|
"digest": "sha256:" + hashlib.sha256(p.read_bytes()).hexdigest()}
|
|
for p in files]}
|
|
installers = ("mac-arm64.dmg", "mac-x64.dmg", "linux-x64.deb")
|
|
absent_installers = [s for s in installers if not (assets / f"VoiceStudio-{version}-{s}").is_file()]
|
|
if missing is not None:
|
|
# Recorded before any check can fail (the caller writes the list even then).
|
|
missing.extend(f"installer {suffix}" for suffix in absent_installers)
|
|
verify_release(release, assets, channel=channel, version=version, missing=missing)
|
|
for manifest in assets.glob(f"electron-{channel}-*.yml"):
|
|
text = manifest.read_text(encoding="utf-8")
|
|
artifact = re.search(r"^\s+- url:\s*(.+)$", text, re.M)[1].strip().strip("'\"")
|
|
expected = re.search(r"^\s{4}sha512:\s*(.+)$", text, re.M)[1].strip().strip("'\"")
|
|
actual = base64.b64encode(hashlib.sha512((assets / artifact).read_bytes()).digest()).decode()
|
|
if actual != expected:
|
|
raise ValueError("Updater payload checksum mismatch")
|
|
if absent_installers and missing is None:
|
|
raise ValueError(f"Missing installer: {absent_installers[0]}")
|
|
# Archived Tauri clients read `latest/download`, which never serves a
|
|
# prerelease, so betas carry no sunset feeds.
|
|
if sunset_tag and channel == "stable":
|
|
for name in ("latest.json", "latest-user.json"):
|
|
validate_sunset(json.loads((assets / name).read_text(encoding="utf-8")), sunset_tag)
|
|
section = re.search(rf"^## \[{re.escape(version)}\][^\n]*\n(.*?)(?=^## |\Z)",
|
|
Path("CHANGELOG.md").read_text(encoding="utf-8"), re.M | re.S)
|
|
if not section or not section[1].strip():
|
|
raise ValueError("Write versioned CHANGELOG notes before release")
|
|
notes = section[1].strip() + "\n"
|
|
# A hand-written Contributors block (with roles, reporters) always wins.
|
|
if repo and not re.search(r"^#{2,4} Contributors", notes, re.M):
|
|
try:
|
|
block = contributors_section(repo, tag, gh, head=head)
|
|
except (subprocess.CalledProcessError, OSError) as error:
|
|
# Credits must never block a release; say so loudly instead.
|
|
print(f"::warning::Contributors section skipped: {error}", file=sys.stderr)
|
|
block = ""
|
|
if block:
|
|
notes += "\n" + block
|
|
(assets / "RELEASE_NOTES.md").write_text(notes, encoding="utf-8")
|
|
(assets / "SHA256SUMS.txt").write_text("\n".join(
|
|
f"{hashlib.sha256(p.read_bytes()).hexdigest()} {p.name}" for p in sorted(files)
|
|
if p.name not in {"SHA256SUMS.txt", "RELEASE_NOTES.md"}) + "\n", encoding="utf-8")
|
|
|
|
def rehearsal_target():
|
|
"""`(tag, commit)` for a rehearsal: the tag package.json's version would get, and HEAD."""
|
|
version = json.loads(Path("package.json").read_text(encoding="utf-8"))["version"]
|
|
channel_for(version) # a rehearsal needs a releasable version shape too
|
|
head = subprocess.run(["git", "rev-parse", "HEAD"], capture_output=True, text=True, check=True).stdout.strip()
|
|
return f"v{version}", head
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--assets", type=Path)
|
|
selector = parser.add_mutually_exclusive_group()
|
|
selector.add_argument("--tag")
|
|
selector.add_argument("--rehearsal", action="store_true",
|
|
help="No tag exists yet: verify as the tag package.json's version would get")
|
|
parser.add_argument("--missing-report", type=Path,
|
|
help="With --rehearsal: verify the legs that built, list the ones that did not here")
|
|
parser.add_argument("--sunset-tag")
|
|
parser.add_argument("--repo", help="owner/name; adds a Contributors section from the tag comparison")
|
|
parser.add_argument("--print-channel", action="store_true",
|
|
help="Print stable or beta for the package version and exit")
|
|
args = parser.parse_args()
|
|
if args.print_channel:
|
|
print(channel_for(json.loads(Path("package.json").read_text(encoding="utf-8"))["version"]))
|
|
elif args.missing_report and not args.rehearsal:
|
|
parser.error("--missing-report is only for --rehearsal; a release needs every leg")
|
|
elif args.assets and args.rehearsal:
|
|
tag, head = rehearsal_target()
|
|
missing = [] if args.missing_report else None
|
|
try:
|
|
prepare(args.assets, tag, args.sunset_tag, repo=args.repo, head=head, missing=missing)
|
|
finally:
|
|
# Also when another leg is broken: the absent legs are already known
|
|
# and the rehearsal's last step lists them; the error still fails this step.
|
|
if args.missing_report:
|
|
args.missing_report.write_text("".join(f"{item}\n" for item in missing), encoding="utf-8")
|
|
for item in missing:
|
|
print(f"::error::Rehearsal is missing {item}: its build leg failed", file=sys.stderr)
|
|
elif args.assets and args.tag:
|
|
prepare(args.assets, args.tag, args.sunset_tag, repo=args.repo)
|
|
else:
|
|
parser.error("--assets and --tag (or --rehearsal) are required")
|