| import time | |
| from argparse import ArgumentParser | |
| from dataclasses import dataclass | |
| from pathlib import Path | |
| import repos | |
| from github import Github, UnknownObjectException | |
| from github.GitRef import GitRef | |
| from rich import print | |
| from rich.markup import escape as e | |
| import util | |
| from util import Checklist, CMakeVersion, ReleaseRepo, Version | |
| @dataclass | |
| class Config: | |
| version: Version | |
| repos_dir: Path | |
| interactive: bool | |
| skip_weak_deps: bool | |
| github: Github | |
| class RepoChecker: | |
| def __init__(self, config: Config, rrepo: ReleaseRepo) -> None: | |
| self.config = config | |
| self.cl = Checklist() | |
| self.rrepo = rrepo | |
| self.grepo = self.github.get_repo(self.rrepo.gh_full_name) | |
| self.lrepo = self.rrepo.local(self.config.repos_dir) | |
| @property | |
| def github(self) -> Github: | |
| return self.config.github | |
| @property | |
| def version(self) -> Version: | |
| return self.config.version | |
| def prompt(self, message: str) -> bool: | |
| if not self.config.interactive: | |
| return False | |
| return util.prompt(message) == "y" | |
| def check_pr(self, base: str, head: str, title: str) -> bool: | |
| pr = util.find_pr(self.grepo, head=head, base=base, title=title) | |
| if not pr: | |
| if not self.prompt("PR not found. Create?"): | |
| self.cl.fatal("PR not found") | |
| return False | |
| if pr.state == "open": | |
| self.cl.blocked(f"PR open: {util.fmt_pr(pr)}") | |
| if pr.merged: | |
| self.cl.success(f"PR merged: {util.fmt_pr(pr)}") | |
| return True | |
| return False | |
| def create_pr( | |
| self, | |
| *, | |
| base: str, | |
| head: str, | |
| title: str, | |
| body: str | None = None, | |
| ) -> None: | |
| if not self.prompt(f"Push branch [b]{e(head)}[/b]?"): | |
| self.cl.fatal("Branch not pushed") | |
| self.lrepo.push(head) | |
| if not self.prompt(f"Create PR for branch [b]{e(head)}[/b]?"): | |
| self.cl.fatal("PR not created") | |
| pr = util.create_pr( | |
| self.grepo, | |
| title=title, | |
| body=body, | |
| base=base, | |
| head=head, | |
| ) | |
| self.cl.blocked(f"PR created: {util.fmt_pr(pr)}") | |
| class DownstreamChecker(RepoChecker): | |
| def check_dependencies_completed(self) -> None: | |
| deps = list(self.rrepo.strong_deps) | |
| if not self.config.skip_weak_deps: | |
| deps += self.rrepo.weak_deps | |
| for dep in deps: | |
| if not dep.completed: | |
| self.cl.wait( | |
| f"Awaiting completion of dependency [b]{e(dep.gh_full_name)}[/b]" | |
| ) | |
| self.cl.ensure_success() | |
| def check_toolchain(self) -> bool: | |
| expected = util.get_toolchain_for(self.version) | |
| actual = util.get_toolchain( | |
| self.grepo, self.grepo.default_branch, self.rrepo.toolchain_file | |
| ) | |
| if expected == actual: | |
| self.cl.success(f"Toolchain is [b]{e(actual)}[/b]") | |
| return True | |
| else: | |
| self.cl.fail(f"Toolchain is [b]{e(actual)}[/b]") | |
| return False | |
| def _bump_toolchain(self, path: Path) -> None: | |
| util.set_toolchain(path, self.version.tag) | |
| def _bump_toolchain_deps(self, path: Path) -> None: | |
| if (path / "lakefile.toml").exists(): | |
| util.edit( | |
| path / "lakefile.toml", | |
| r'rev = "v4\.[0-9]+(\.[0-9]+)?(-rc[0-9]+)?"', | |
| f'rev = "{self.version}"', | |
| ) | |
| else: | |
| util.edit( | |
| path / "lakefile.lean", | |
| r'git "v4\.[0-9]+(\.[0-9]+)?(-rc[0-9]+)?"', | |
| f'git "{self.version}"', | |
| ) | |
| util.run("lake", "update", cwd=path) | |
| def _bump_toolchain_mathlib4(self) -> None: | |
| self._bump_toolchain(self.lrepo.path) | |
| if self.version.rc == 1: | |
| lakefile = self.lrepo.path / "lakefile.lean" | |
| util.edit( | |
| lakefile, | |
| '"batteries" @ git "nightly-testing"', | |
| '"batteries" @ git "main"', | |
| ) | |
| util.edit(lakefile, '"Qq" @ git "nightly-testing"', '"Qq" @ git "master"') | |
| util.edit( | |
| lakefile, '"aesop" @ git "nightly-testing"', '"aesop" @ git "master"' | |
| ) | |
| util.edit( | |
| lakefile, | |
| '"proofwidgets" @ git "nightly-testing"', | |
| '"proofwidgets" @ git "main"', | |
| ) | |
| util.edit( | |
| lakefile, | |
| '"plausible" @ git "nightly-testing"', | |
| '"plausible" @ git "main"', | |
| ) | |
| self._bump_toolchain_deps(self.lrepo.path) | |
| def _bump_cslib_mathlib_rev(self, path: Path) -> None: | |
| util.edit( | |
| path / "lakefile.toml", | |
| r'(name = "mathlib"\nscope = "leanprover-community"\nrev =) ".+?"', | |
| rf'\1 "{self.version}"', | |
| ) | |
| def _bump_toolchain_cslib(self) -> None: | |
| self._bump_toolchain(self.lrepo.path) | |
| self._bump_cslib_mathlib_rev(self.lrepo.path) | |
| # For rc1 PRs | |
| util.edit( | |
| self.lrepo.path / "lakefile.toml", | |
| r'name = "mathlib"\ngit = ".*"\nrev = ".+?"', | |
| f'name = "mathlib"\nscope = "leanprover-community"\nrev = "{self.version}"', | |
| ) | |
| self._bump_toolchain_deps(self.lrepo.path) | |
| def _bump_toolchain_repl(self) -> None: | |
| self._bump_toolchain(self.lrepo.path) | |
| self._bump_toolchain_deps(self.lrepo.path) | |
| mathlib = self.lrepo.path / "test" / "Mathlib" | |
| self._bump_toolchain(mathlib) | |
| self._bump_toolchain_deps(mathlib) | |
| def _bump_toolchain_verso(self) -> None: | |
| self._bump_toolchain(self.lrepo.path) | |
| self._bump_toolchain_deps(self.lrepo.path) | |
| util.run("./update-subverso.sh", cwd=self.lrepo.path) | |
| def _bump_toolchain_verso_templates(self) -> None: | |
| util.run("./update-lean-version.sh", self.version.raw, cwd=self.lrepo.path) | |
| def _bump_toolchain_reference_manual(self) -> None: | |
| self._bump_toolchain(self.lrepo.path) | |
| self._bump_toolchain_deps(self.lrepo.path) | |
| if not self.prompt("Run release notes update script"): | |
| self.cl.fatal("Release notes update script not run") | |
| here = Path(__file__).parent | |
| util.run( | |
| "uv", "run", "release_notes.py", self.version.tag, self.lrepo.path, cwd=here | |
| ) | |
| if self.version.rc == 1: | |
| module = util.get_release_notes_module_for(self.version) | |
| index = self.lrepo.path / util.get_release_notes_index_path() | |
| util.edit( | |
| index, | |
| r"(?m)^(import Manual\.Releases\..*)$", | |
| f"import {module}\n\\1", | |
| count=1, | |
| ) | |
| util.edit( | |
| index, | |
| r"(?m)^(\{include 0 Manual\.Releases\..*\})$", | |
| f"{{include 0 {module}}}\n\n\\1", | |
| count=1, | |
| ) | |
| self.prompt("Check release notes before commit") | |
| def _bump_toolchain_lean_fro_org(self) -> None: | |
| self._bump_toolchain(self.lrepo.path) | |
| self._bump_toolchain_deps(self.lrepo.path) | |
| util.run("scripts/update.sh", cwd=self.lrepo.path) | |
| def _bump_toolchain_bibtex_query(self) -> None: | |
| self._bump_toolchain(self.lrepo.path) | |
| lub = self.github.get_repo(repos.LEAN4_UNICODE_BASIC.gh_full_name) | |
| tag = util.get_lean_unicode_basic_release_for(lub, self.version) | |
| rev = tag.name if tag else "main" | |
| util.edit( | |
| self.lrepo.path / "lakefile.toml", | |
| r'(name = "UnicodeBasic"[\s\S]*?rev =) ".+?"', | |
| rf'\1 "{rev}"', | |
| ) | |
| self._bump_toolchain_deps(self.lrepo.path) | |
| def _bump_toolchain_leansqlite(self) -> None: | |
| self._bump_toolchain(self.lrepo.path) | |
| self._bump_toolchain_deps(self.lrepo.path) | |
| tests = self.lrepo.path / "tests" | |
| self._bump_toolchain(tests) | |
| self._bump_toolchain_deps(tests) | |
| def _bump_toolchain_in_worktree(self) -> None: | |
| if self.rrepo.gh_full_name == repos.MATHLIB4.gh_full_name: | |
| self._bump_toolchain_mathlib4() | |
| elif self.rrepo.gh_full_name == repos.CSLIB.gh_full_name: | |
| self._bump_toolchain_cslib() | |
| elif self.rrepo.gh_full_name == repos.REPL.gh_full_name: | |
| self._bump_toolchain_repl() | |
| elif self.rrepo.gh_full_name == repos.VERSO.gh_full_name: | |
| self._bump_toolchain_verso() | |
| elif self.rrepo.gh_full_name == repos.VERSO_TEMPLATES.gh_full_name: | |
| self._bump_toolchain_verso_templates() | |
| elif self.rrepo.gh_full_name == repos.REFERENCE_MANUAL.gh_full_name: | |
| self._bump_toolchain_reference_manual() | |
| elif self.rrepo.gh_full_name == repos.LEAN_FRO_ORG.gh_full_name: | |
| self._bump_toolchain_lean_fro_org() | |
| elif self.rrepo.gh_full_name == repos.BIBTEX_QUERY.gh_full_name: | |
| self._bump_toolchain_bibtex_query() | |
| elif self.rrepo.gh_full_name == repos.LEANSQLITE.gh_full_name: | |
| self._bump_toolchain_leansqlite() | |
| elif self.rrepo.strong_deps: | |
| self._bump_toolchain(self.lrepo.path) | |
| self._bump_toolchain_deps(self.lrepo.path) | |
| else: | |
| self._bump_toolchain(self.lrepo.path) | |
| def _bump_toolchain_unicode_basic(self) -> None: | |
| base = self.grepo.default_branch | |
| head = f"update-toolchain-{self.version}" | |
| title = f"chore: update toolchain {self.version}" | |
| if self.check_pr(base=base, head=head, title=title): | |
| return | |
| workflow = self.grepo.get_workflow("update-toolchain.yml") | |
| for run in workflow.get_runs(branch=base).get_page(0): | |
| if not run.conclusion: | |
| what = f"[b u link={run.html_url}]Bump workflow run {run.id}[/]" | |
| self.cl.blocked(f"{what} is still running") | |
| if not self.prompt("No PR or running bump workflow run found. Trigger?"): | |
| self.cl.fatal("No PR or running bump workflow run found") | |
| workflow.create_dispatch(ref=base) | |
| self.cl.blocked("Triggered bump workflow run") | |
| def check_bump_pr(self) -> None: | |
| if self.rrepo.gh_full_name == repos.LEAN4_UNICODE_BASIC.gh_full_name: | |
| self._bump_toolchain_unicode_basic() | |
| return | |
| # Normally; also RC1, rc1_pr_base == "default": | |
| # 1. Create bump branch from origin/main | |
| # 2. Create bump commit | |
| # 3. Push branch to origin | |
| # 4. Create bump PR to origin/main | |
| # RC1, rc1_pr_base == "bump": | |
| # 1. Create bump branch from origin/bump/v* | |
| # 2. Create bump commit | |
| # 3. Push branch to origin | |
| # 4. Create bump PR to origin/main | |
| # RC1, rc1_pr_base == "downstream": | |
| # 1. Create bump branch in downstream-lean4, based off of downstream's origin/master | |
| # 1.1. Fetch that branch into the local repo, so the remaining steps stay normal | |
| # 2. Create bump commit | |
| # 3. Push branch to origin | |
| # 4. Create bump PR to origin/main | |
| # Determine bump PR info | |
| base = self.grepo.default_branch | |
| head = f"bump-to-{self.version}" | |
| if self.version.rc == 1 and self.rrepo.rc1_pr_base == "bump": | |
| head = util.get_bump_branch(self.version) | |
| title = util.get_toolchain_bump_message(self.version) | |
| # If a bump PR already exists, we don't have to do any actual work. | |
| if self.check_pr(base=base, head=head, title=title): | |
| return | |
| # Get the head branch into self.lrepo from whatever rc1 or non-rc1 source is appropriate | |
| self.lrepo.prepare() | |
| if self.version.rc == 1 and self.rrepo.rc1_pr_base == "bump": | |
| # `head` has already been set to the bump branch name earlier | |
| self.lrepo.switch(head) | |
| elif self.version.rc == 1 and self.rrepo.rc1_pr_base == "downstream": | |
| dsl = repos.DOWNSTREAM_LEAN4.local(self.config.repos_dir) | |
| dsl.prepare() | |
| dsl.switch("master") | |
| dsl.run( | |
| *("python", ".downstream/export.py", ".", self.rrepo.gh_name), | |
| *("-m", "chore: adaptations from downstream-lean4"), | |
| ) | |
| # See also LocalRepo.prepare and LocalRepo.switch | |
| self.lrepo.git("fetch", "--force", dsl.path, "HEAD") | |
| self.lrepo.git("switch", "-C", head, "FETCH_HEAD") | |
| else: | |
| self.lrepo.create_branch(head) | |
| # Create bump commit | |
| self._bump_toolchain_in_worktree() | |
| self.lrepo.commit(title) | |
| # Create bump PR | |
| body = None | |
| if self.rrepo.gh_full_name == repos.VERSO.gh_full_name: | |
| body = f"No-Changelog: toolchain bump for release {self.version.tag}" | |
| self.create_pr(title=title, body=body, base=base, head=head) | |
| def check_next_bump_branch(self) -> None: | |
| if self.rrepo.rc1_pr_base != "bump": | |
| return | |
| branch_name = util.get_bump_branch(self.version.next_minor) | |
| what = f"Bump branch [b]{e(branch_name)}[/b]" | |
| try: | |
| self.grepo.get_branch(branch_name) | |
| self.cl.success(f"{what} exists") | |
| return | |
| except UnknownObjectException: | |
| pass | |
| if not self.prompt(f"{what} not found. Create?"): | |
| self.cl.fail(f"{what} not found") | |
| return | |
| self.lrepo.prepare() | |
| self.lrepo.create_branch(branch_name) | |
| if not self.prompt(f"Push branch [b]{e(branch_name)}[/b]?"): | |
| self.cl.fail(f"{what} not found") | |
| return | |
| self.lrepo.push(branch_name) | |
| self.cl.success(f"{what} created") | |
| def _check_lean_release_tag(self) -> GitRef | None: | |
| tag_name = self.version.tag | |
| what = f"Toolchain tag [b]{tag_name}[/b]" | |
| try: | |
| tag = self.grepo.get_git_ref(f"tags/{tag_name}") | |
| self.cl.success(f"{what} exists") | |
| return tag | |
| except UnknownObjectException: | |
| pass | |
| if not self.prompt(f"{what} not found. Create?"): | |
| self.cl.fail(f"{what} not found") | |
| return | |
| self.lrepo.prepare() | |
| bump_sha = util.find_merged_toolchain_bump_sha(self.lrepo, self.version) | |
| self.lrepo.create_tag(tag_name, bump_sha) | |
| if not self.prompt(f"Push tag [b]{tag_name}[/b]?"): | |
| self.cl.fatal(f"{what} does not exist") | |
| self.lrepo.push(tag_name, upstream=False) | |
| time.sleep(5) # Sometimes it takes GitHub a while to update | |
| tag = self.grepo.get_git_ref(f"tags/{tag_name}") | |
| self.cl.success(f"{what} created") | |
| return tag | |
| def _check_patch_release_tag(self) -> GitRef | None: | |
| # Patch releases (v4.X.Y with Y>0) skip the usual bump-PR flow: the | |
| # new tag's commit is created directly from the previous patch's tag, | |
| # bumping only the toolchain file, and pushed straight to the repo. | |
| tag_name = self.version.tag | |
| what = f"Toolchain tag [b]{tag_name}[/b]" | |
| try: | |
| tag = self.grepo.get_git_ref(f"tags/{tag_name}") | |
| self.cl.success(f"{what} exists") | |
| return tag | |
| except UnknownObjectException: | |
| pass | |
| if not self.prompt(f"{what} not found. Create?"): | |
| self.cl.fail(f"{what} not found") | |
| return | |
| self.lrepo.prepare() | |
| self.lrepo.git("checkout", "--detach", self.version.prev.tag) | |
| util.set_toolchain(self.lrepo.path, self.version.tag) | |
| if self.rrepo.gh_full_name == repos.CSLIB.gh_full_name: | |
| self._bump_cslib_mathlib_rev(self.lrepo.path) | |
| util.run("lake", "update", "mathlib", cwd=self.lrepo.path) | |
| self.lrepo.commit(util.get_toolchain_bump_message(self.version)) | |
| sha = self.lrepo.git_stdout("rev-parse", "HEAD").strip() | |
| self.lrepo.create_tag(tag_name, sha) | |
| if not self.prompt(f"Push tag [b]{tag_name}[/b]?"): | |
| self.cl.fatal(f"{what} does not exist") | |
| self.lrepo.push(tag_name, upstream=False) | |
| tag = self.grepo.get_git_ref(f"tags/{tag_name}") | |
| self.cl.success(f"{what} created") | |
| return tag | |
| def _check_proofwidgets_release_tag(self) -> GitRef | None: | |
| what = f"Proofwidgets release with toolchain {self.version}" | |
| tag = util.get_proofwidgets_release_for(self.grepo, self.version) | |
| if tag: | |
| self.cl.success(f"{what} found: [b]{e(tag.name)}[/b]") | |
| return | |
| tag_name = util.get_next_proofwidgets_release(self.grepo) | |
| if not self.prompt(f"{what} not found. Create [b]{e(tag_name)}[/b]?"): | |
| self.cl.fail(f"{what} not found") | |
| return | |
| self.lrepo.prepare() | |
| bump_sha = util.find_merged_toolchain_bump_sha(self.lrepo, self.version) | |
| self.lrepo.create_tag(tag_name, bump_sha) | |
| if not self.prompt(f"Push tag [b]{tag_name}[/b]?"): | |
| self.cl.fatal(f"{what} does not exist") | |
| self.lrepo.push(tag_name, upstream=False) | |
| tag = self.grepo.get_git_ref(f"tags/{tag_name}") | |
| self.cl.success(f"{what} created") | |
| return tag | |
| def check_release_tag(self) -> GitRef | None: | |
| match self.rrepo.release_tag: | |
| case "lean": | |
| return self._check_lean_release_tag() | |
| case "proofwidgets": | |
| return self._check_proofwidgets_release_tag() | |
| case None: | |
| pass | |
| def check_stable_branch_points_to_release_tag(self, tag: GitRef) -> None: | |
| if not self.rrepo.stable_branch: | |
| return | |
| if not self.version.is_stable: | |
| return | |
| what = "Stable branch" | |
| branch = self.grepo.get_branch("stable") | |
| if branch.commit.sha == tag.object.sha: | |
| self.cl.success(f"{what} points to toolchain tag") | |
| return | |
| # Patch releases may be on older stable releases, so we have to be a bit | |
| # careful here | |
| if self.version.patch > 0 and not self.prompt( | |
| f"Is [b]{e(self.version.tag)}[/b] the latest stable release?" | |
| ): | |
| self.cl.success( | |
| f"{what} not updated, {e(self.version.tag)} is not the latest" | |
| ) | |
| return | |
| if not self.prompt(f"{what} does not point to toolchain tag. Update?"): | |
| self.cl.fail(f"{what} does not point to toolchain tag") | |
| return | |
| self.lrepo.prepare() | |
| self.lrepo.switch("stable") | |
| self.lrepo.git("reset", "--hard", self.version.tag) | |
| if not self.prompt("Push branch [b]stable[/b] to origin?"): | |
| self.cl.fail(f"{what} does not point to toolchain tag") | |
| return | |
| self.lrepo.push("stable", force=True) | |
| self.cl.success(f"{what} updated to point to toolchain tag") | |
| def check(self) -> None: | |
| self.check_dependencies_completed() | |
| self.rrepo.completed = False | |
| # Patch releases are a bit special | |
| if self.version.patch > 0: | |
| # They only apply to some repos | |
| if not self.rrepo.patch_release: | |
| self.cl.success("Nothing to do, this is a patch release") | |
| self.rrepo.completed = True | |
| return | |
| # They work differently from normal toolchain bumps | |
| release_tag = self._check_patch_release_tag() | |
| if release_tag: | |
| self.check_stable_branch_points_to_release_tag(release_tag) | |
| self.cl.ensure_success() | |
| self.rrepo.completed = True | |
| return | |
| toolchain = self.check_toolchain() | |
| if not toolchain: | |
| self.check_bump_pr() | |
| self.cl.ensure_success() | |
| self.check_next_bump_branch() | |
| release_tag = self.check_release_tag() | |
| if release_tag: | |
| self.check_stable_branch_points_to_release_tag(release_tag) | |
| self.cl.ensure_success() | |
| self.rrepo.completed = True | |
| class LeanChecker(RepoChecker): | |
| def __init__(self, config: Config) -> None: | |
| super().__init__(config=config, rrepo=repos.LEAN4) | |
| def _check_label_exists( | |
| self, name: str, color: str, description: str | None = None | |
| ) -> None: | |
| what = f"Label [b]{e(name)}[/b]" | |
| try: | |
| self.grepo.get_label(name) | |
| self.cl.success(f"{what} exists") | |
| return | |
| except UnknownObjectException: | |
| pass | |
| if not self.prompt(f"{what} does not exist. Create?"): | |
| self.cl.fail(f"{what} does not exist") | |
| return | |
| if description is None: | |
| self.grepo.create_label(name=name, color=color) | |
| else: | |
| self.grepo.create_label(name=name, color=color, description=description) | |
| self.cl.success(f"{what} created") | |
| def check_backport_label_exists(self, version: Version) -> None: | |
| self._check_label_exists( | |
| name=util.get_backport_label(version), | |
| color="1d76db", | |
| ) | |
| def check_blocking_label_exists(self, version: Version) -> None: | |
| self._check_label_exists( | |
| name=util.get_blocking_label(version), | |
| color="b60205", | |
| description=f"Blocks the next {version.base} release candidate or release from being published.", | |
| ) | |
| def check_release_branch_exists(self) -> None: | |
| branch_name = util.get_releases_branch(self.version) | |
| what = f"Release branch [b]{e(branch_name)}[/b]" | |
| try: | |
| self.grepo.get_branch(branch_name) | |
| self.cl.success(f"{what} exists") | |
| return | |
| except UnknownObjectException: | |
| pass | |
| if not self.prompt(f"{what} does not exist. Create?"): | |
| self.cl.fatal(f"{what} does not exist") | |
| self.lrepo.prepare() | |
| self.lrepo.create_branch(branch_name, remote_branch="downstream-green") | |
| if not self.prompt(f"Push branch [b]{e(branch_name)}[/b]?"): | |
| self.cl.fatal(f"{what} does not exist") | |
| self.lrepo.push(branch_name) | |
| self.grepo.get_branch(branch_name) | |
| self.cl.success(f"{what} created") | |
| def check_release_branch_cmake_version(self) -> None: | |
| branch_name = util.get_releases_branch(self.version) | |
| what = f"CMake version settings on [b]{e(branch_name)}[/b]" | |
| target = CMakeVersion(self.version.stable, is_release=True) | |
| cur = util.get_cmake_version(self.grepo, branch_name) | |
| if cur == target: | |
| self.cl.success(f"{what} are correct") | |
| return | |
| if not self.prompt(f"{what} are incorrect. Update?"): | |
| self.cl.fail(f"{what} are incorrect") | |
| return | |
| self.lrepo.prepare() | |
| self.lrepo.switch(branch_name) | |
| util.set_cmake_version(self.lrepo, target) | |
| self.lrepo.commit("chore: prepare release") | |
| if not self.prompt(f"Push branch [b]{e(branch_name)}[/b]?"): | |
| self.cl.fail(f"{what} are incorrect") | |
| return | |
| self.lrepo.push(branch_name) | |
| self.cl.success(f"{what} updated") | |
| def check_master_branch_cmake_version(self) -> None: | |
| branch_name = self.grepo.default_branch | |
| what = f"CMake version settings on [b]{e(branch_name)}[/b]" | |
| target = CMakeVersion(self.version.next_minor, is_release=False) | |
| cur = util.get_cmake_version(self.grepo, branch_name) | |
| if cur == target: | |
| self.cl.success(f"{what} are correct") | |
| return | |
| self.cl.warn(f"{what} are incorrect") | |
| head = f"dev-cycle-{self.version.next_minor}" | |
| title = f"chore: prepare development cycle for {self.version.next_minor}" | |
| try: | |
| if self.check_pr(base=branch_name, head=head, title=title): | |
| return | |
| except SystemExit: | |
| return # Not fatal | |
| self.lrepo.prepare() | |
| self.lrepo.create_branch(head, remote_branch=branch_name) | |
| util.set_cmake_version(self.lrepo, target) | |
| self.lrepo.commit(title) | |
| self.create_pr(base=branch_name, head=head, title=title) | |
| def _check_no_open_prs_labeled(self, label: str) -> None: | |
| success = True | |
| for issue in self.grepo.get_issues(state="open", labels=[label]): | |
| kind = "PR" if issue.pull_request else "issue" | |
| self.cl.fail(f"Found {kind} {util.fmt_pr(issue)} labeled [b]{e(label)}[/b]") | |
| success = False | |
| if success: | |
| self.cl.success(f"Found no open PRs labeled [b]{e(label)}[/b]") | |
| def check_no_open_prs_labeled_backport(self) -> None: | |
| self._check_no_open_prs_labeled(util.get_backport_label(self.version)) | |
| def check_no_open_prs_labeled_blocking(self) -> None: | |
| self._check_no_open_prs_labeled(util.get_blocking_label(self.version)) | |
| def check_no_open_backport_prs(self) -> None: | |
| base = util.get_releases_branch(self.version) | |
| success = True | |
| for pr in self.grepo.get_pulls(state="open", base=base): | |
| if "backport" in pr.title.lower(): | |
| self.cl.fail(f"Found backport PR #{pr.number} {util.fmt_pr(pr)}") | |
| success = False | |
| if success: | |
| self.cl.success("Found no open backport PRs") | |
| def check_release_tag(self) -> GitRef: | |
| tag_name = self.version.tag | |
| what = f"Tag [b]{tag_name}[/b]" | |
| try: | |
| ref = self.grepo.get_git_ref(f"tags/{tag_name}") | |
| self.cl.success(f"{what} exists") | |
| return ref | |
| except UnknownObjectException: | |
| pass | |
| if not self.prompt(f"{what} does not exist. Create?"): | |
| self.cl.fatal(f"{what} does not exist") | |
| branch_name = util.get_releases_branch(self.version) | |
| self.lrepo.prepare() | |
| self.lrepo.switch(branch_name) | |
| self.lrepo.create_tag(tag_name, branch_name) | |
| if not self.prompt(f"Push tag [b]{tag_name}[/b]?"): | |
| self.cl.fatal(f"{what} does not exist") | |
| self.lrepo.push(tag_name, upstream=False) | |
| tag = self.grepo.get_git_ref(f"tags/{tag_name}") | |
| self.cl.success(f"{what} created, waiting a few seconds for release CI...") | |
| time.sleep(10) | |
| return tag | |
| def check_release_ci(self, release_tag: GitRef) -> None: | |
| tag_sha = release_tag.object.sha | |
| runs = self.grepo.get_workflow_runs(event="push", head_sha=tag_sha).get_page(0) | |
| if len(runs) == 0: | |
| self.cl.fatal("Release workflow run not found") | |
| run = runs[0] | |
| what = f"[b u link={run.html_url}]Release workflow run {run.id}[/]" | |
| if not run.conclusion: | |
| self.cl.blocked(f"{what} is still running") | |
| if run.conclusion != "success": | |
| self.cl.fatal(f"{what} failed") | |
| self.cl.success(f"{what} finished") | |
| def check_release_page(self) -> None: | |
| url = f"https://github.com/leanprover/lean4/releases/tag/{self.version}" | |
| what = f"[b u link={url}]Release page for {self.version.tag}[/]" | |
| try: | |
| release = self.grepo.get_release(self.version.tag) | |
| except UnknownObjectException: | |
| self.cl.blocked(f"{what} not found") | |
| target = "This is" | |
| if not self.version.is_stable: | |
| target += f" release candidate {self.version.rc} for" | |
| target += f" the {self.version.stable} release of Lean." | |
| relnotes = f"https://lean-lang.org/doc/reference/latest/releases/{self.version.stable}/" | |
| target += f" View the [release notes]({relnotes}) for more information." | |
| incorrect = [] | |
| if release.name != str(self.version): | |
| incorrect.append("name") | |
| if release.body is None or release.body.strip() != target: | |
| incorrect.append("message") | |
| if not incorrect: | |
| self.cl.success(f"{what} exists") | |
| return | |
| if not self.prompt(f"{what} has incorrect {'/'.join(incorrect)}. Update?"): | |
| self.cl.fail(f"{what} has incorrect {'/'.join(incorrect)}") | |
| return | |
| release.update_release( | |
| name=str(self.version), | |
| message=target, | |
| prerelease=not self.version.is_stable, | |
| ) | |
| self.cl.success(f"{what} updated") | |
| def check_api_docs_workflow(self) -> None: | |
| grepo = self.github.get_repo(repos.LEAN4_API_DOCS.gh_full_name) | |
| workflow = grepo.get_workflow("docs.yaml") | |
| url = "https://github.com/leanprover/lean4-api-docs/actions/workflows/docs.yaml" | |
| what = f"[u link={url}]docs.yaml workflow[/u link] on [b]{e(repos.LEAN4_API_DOCS.gh_full_name)}[/b]" | |
| if not self.prompt(f"Trigger {what}?"): | |
| self.cl.fail(f"{what} not triggered") | |
| return | |
| workflow.create_dispatch(ref=grepo.default_branch) | |
| self.cl.success(f"{what} triggered") | |
| def check_zulip_post(self) -> None: | |
| what = "Zulip release announcement" | |
| if not self.prompt(f"Post {what}?"): | |
| self.cl.fail(f"{what} not posted") | |
| return | |
| release_notes_url = f"https://lean-lang.org/doc/reference/latest/releases/{self.version.stable}/" | |
| msg = "" | |
| if self.version.is_stable: | |
| msg += f"We have a new stable release of Lean, `{self.version.tag}`! " | |
| else: | |
| msg += f"We have a new release candidate of Lean, `{self.version.tag}`. " | |
| msg += f"See the [release notes]({release_notes_url}) for more information." | |
| msg += "\n\n" | |
| if self.version.patch > 0: | |
| # Patch releases only update the repos marked `patch_release`, and | |
| # ProofWidgets is not one of them. | |
| names = [f"`{r.gh_name}`" for r in repos.ALL if r.patch_release] | |
| msg += f"{util.join_and(names)} are available with the new toolchain " | |
| msg += f"at their respective `{self.version.tag}` tags. " | |
| else: | |
| proofwidgets = self.github.get_repo(repos.PROOFWIDGETS4.gh_full_name) | |
| proofwidgets_tag = util.get_proofwidgets_release_for( | |
| proofwidgets, self.version | |
| ) | |
| if proofwidgets_tag is None: | |
| self.cl.fail("ProofWidgets release tag not found") | |
| return | |
| msg += "The usual repos are all available with the new toolchain " | |
| msg += f"at their respective `{self.version.tag}` tags " | |
| msg += f"(and ProofWidgets at `{proofwidgets_tag.name}`). " | |
| msg += "We encourage all projects downstream " | |
| msg += f"to update to `{self.version.tag}` when possible, and " | |
| msg += "to release their own corresponding toolchain tags after updating." | |
| print() | |
| print(e(msg)) | |
| print() | |
| if not self.prompt(f"Posted {what}?"): | |
| self.cl.fail(f"{what} not posted") | |
| return | |
| self.cl.success(f"{what} posted") | |
| def check_release_notes_updated(self) -> None: | |
| # This is only applicable to patch releases, otherwise the release notes | |
| # are already updated in the reference manual bump PR. | |
| if self.version.patch == 0: | |
| return | |
| if self.prompt("Update release notes manually."): | |
| self.cl.success("Release notes updated") | |
| else: | |
| self.cl.fail("Release notes not updated") | |
| def check_notify_ashley(self) -> None: | |
| # Only v4.X.0 releases | |
| if not (self.version.patch == 0 and self.version.rc is None): | |
| return | |
| if self.prompt("Tell Ashley that the release is finished."): | |
| self.cl.success("Ashley notified") | |
| else: | |
| self.cl.fail("Ashley not notified") | |
| def check(self) -> None: | |
| self.cl.section("Prepare release cycle") | |
| self.check_backport_label_exists(self.version) | |
| self.check_blocking_label_exists(self.version) | |
| self.check_blocking_label_exists(self.version.next_minor) | |
| self.check_release_branch_exists() | |
| self.check_release_branch_cmake_version() | |
| self.check_master_branch_cmake_version() | |
| self.cl.section("Release") | |
| self.check_no_open_prs_labeled_backport() | |
| self.check_no_open_prs_labeled_blocking() | |
| self.check_no_open_backport_prs() | |
| release_tag = self.check_release_tag() | |
| self.check_release_ci(release_tag) | |
| self.check_release_page() | |
| for drepo in repos.ALL: | |
| self.cl.section(f"[u link={drepo.gh_url}]{e(drepo.gh_full_name)}[/u link]") | |
| try: | |
| DownstreamChecker(config=self.config, rrepo=drepo).check() | |
| except SystemExit: | |
| self.cl.failed = True | |
| self.cl.ensure_success() | |
| self.cl.section("Post release") | |
| self.check_api_docs_workflow() | |
| self.check_release_notes_updated() | |
| self.check_zulip_post() | |
| self.check_notify_ashley() | |
| self.cl.ensure_success() | |
| class Args: | |
| version: Version | |
| repos_dir: Path | None | |
| interactive: bool | |
| skip_weak_deps: bool | |
| graph: bool | |
| if __name__ == "__main__": | |
| parser = ArgumentParser() | |
| parser.add_argument("version", type=Version.parse) | |
| parser.add_argument("-d", "--repos-dir", type=Path) | |
| parser.add_argument("-i", "--interactive", action="store_true") | |
| parser.add_argument("-W", "--skip-weak-deps", action="store_true") | |
| parser.add_argument("-g", "--graph", action="store_true") | |
| args = parser.parse_args(namespace=Args()) | |
| util.initialize_rich() | |
| github = util.get_github_instance() | |
| config = Config( | |
| version=args.version, | |
| repos_dir=util.get_repos_dir(args.repos_dir), | |
| interactive=args.interactive, | |
| skip_weak_deps=args.skip_weak_deps, | |
| github=github, | |
| ) | |
| try: | |
| LeanChecker(config=config).check() | |
| finally: | |
| if args.graph: | |
| print() | |
| repos.print_graphviz_dot() |