| 1 | #!/usr/bin/env python3 |
| 2 | """Pin the release/PR storage boundaries used by the rollback compatibility gate.""" |
| 3 | import json |
| 4 | import pathlib |
| 5 | import re |
| 6 | import subprocess |
| 7 | |
| 8 | ROOT = pathlib.Path(__file__).resolve().parents[1] |
| 9 | |
| 10 | |
| 11 | def git(*args): |
| 12 | return subprocess.check_output(["git", *args], cwd=ROOT, text=True).strip() |
| 13 | |
| 14 | |
| 15 | def source(ref, path): |
| 16 | result = subprocess.run(["git", "show", f"{ref}:{path}"], cwd=ROOT, capture_output=True, text=True) |
| 17 | return result.stdout if result.returncode == 0 else "" |
| 18 | |
| 19 | |
| 20 | def areas(paths): |
| 21 | groups = { |
| 22 | "session-storage": r"^internal/(session/|sessioncontent/|agent/(session|save|branch))", |
| 23 | "workspace-and-lifecycle": r"^desktop/(internal/workspacestate/|session_|historical_|tab_|topic_|legacy_)", |
| 24 | "drafts-and-input": r"^desktop/(internal/draftstate/|draft_|frontend/src/.*(?:[Dd]raft|[Cc]omposer|[Ss]ubmission|[Ss]ession[Nn]avigation))", |
| 25 | "inbox-and-receipts": r"^internal/(sessioninbox/|control/.*(?:submission|inbox|maintenance))", |
| 26 | "attachments-and-identity": r"^internal/(attachment/|sqliteuri/|fileidentity/)|^desktop/attachments", |
| 27 | "history-and-transcript": r"^internal/transcript/|^desktop/(history_|frontend/src/.*(?:[Hh]istory|[Tt]ranscript|[Ss]ubmission))", |
| 28 | "native-shell": r"^desktop/electron/src/main/(lifecycle|graphics|window|index|icons)", |
| 29 | } |
| 30 | return [name for name, pattern in groups.items() if any(re.search(pattern, path) for path in paths)] |
| 31 | |
| 32 | |
| 33 | def main(): |
| 34 | baseline, main_tip = git("rev-parse", "HEAD"), git("rev-parse", "origin/main-v2") |
| 35 | releases = [] |
| 36 | for patch in range(3, 12): |
| 37 | tag = f"desktop-v1.38.{patch}" |
| 38 | session = source(tag, "internal/session/store.go") |
| 39 | revision = re.search(r"StorageRevision\s*=\s*(\d+)", session) |
| 40 | registry = source(tag, "desktop/internal/workspacestate/store.go") |
| 41 | draft = source(tag, "desktop/internal/draftstate/store.go") |
| 42 | releases.append({"tag": tag, "commit": git("rev-parse", tag + "^{commit}"), |
| 43 | "framedStorageRevision": int(revision[1]) if revision else None, |
| 44 | "workspaceRegistry": bool(registry), "durableDrafts": bool(draft)}) |
| 45 | prs = [] |
| 46 | for line in git("log", "--first-parent", "--reverse", "--format=%H %s", "desktop-v1.38.3.." + main_tip).splitlines(): |
| 47 | commit, title = line.split(" ", 1) |
| 48 | paths = git("diff", "--name-only", commit + "^1", commit).splitlines() |
| 49 | domains = areas(paths) |
| 50 | if not domains: |
| 51 | continue |
| 52 | number = re.search(r"#(\d+)", title) |
| 53 | covered_by = next((release["tag"] for release in releases |
| 54 | if subprocess.run(["git", "merge-base", "--is-ancestor", commit, release["commit"]], cwd=ROOT).returncode == 0), "main-v2 after 1.38.11") |
| 55 | prs.append({"commit": commit, "pr": int(number[1]) if number else None, "title": title, |
| 56 | "areas": domains, "firstRelease": covered_by, |
| 57 | "inRollbackBaseline": subprocess.run(["git", "merge-base", "--is-ancestor", commit, baseline], cwd=ROOT).returncode == 0}) |
| 58 | output = ROOT / "docs/testing/manual-session-compatibility-sources.json" |
| 59 | output.parent.mkdir(parents=True, exist_ok=True) |
| 60 | output.write_text(json.dumps({"rollbackBaseline": baseline, "testedMainV2": main_tip, |
| 61 | "releases": releases, "relevantChanges": prs}, ensure_ascii=False, indent=2) + "\n") |
| 62 | print(f"Pinned {len(releases)} releases and {len(prs)} relevant first-parent changes: {output}") |
| 63 | |
| 64 | |
| 65 | if __name__ == "__main__": |
| 66 | main() |
| 67 |