From 16981c892d19fee6f7c3393f3020b6ff1197a548 Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Tue, 7 Jun 2022 12:00:58 +0100 Subject: [PATCH 1/6] Expect a SyTest repository adjacent to Synapse --- scripts-dev/release.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/scripts-dev/release.py b/scripts-dev/release.py index 0031ba3e4b2f..26036fe99479 100755 --- a/scripts-dev/release.py +++ b/scripts-dev/release.py @@ -55,9 +55,12 @@ def run_until_successful( def cli() -> None: """An interactive script to walk through the parts of creating a release. - Requires the dev dependencies be installed, which can be done via: + Requirements: + - The dev dependencies be installed, which can be done via: - pip install -e .[dev] + pip install -e .[dev] + + - A checkout of the sytest repository at ../sytest Then to use: @@ -90,9 +93,11 @@ def prepare() -> None: # Make sure we're in a git repo. repo = get_repo_and_check_clean_checkout() + sytest_repo = get_repo_and_check_clean_checkout("../sytest", "sytest") click.secho("Updating git repo...") repo.remote().fetch() + sytest_repo.remote().fetch() # Get the current version and AST from root Synapse module. current_version = get_package_version() @@ -469,14 +474,18 @@ def get_release_branch_name(version_number: version.Version) -> str: return f"release-v{version_number.major}.{version_number.minor}" -def get_repo_and_check_clean_checkout() -> git.Repo: +def get_repo_and_check_clean_checkout( + path: str = ".", name: str = "synapse" +) -> git.Repo: """Get the project repo and check it's not got any uncommitted changes.""" try: - repo = git.Repo() + repo = git.Repo(path=path) except git.InvalidGitRepositoryError: - raise click.ClickException("Not in Synapse repo.") + raise click.ClickException( + f"{path} is not a git repository (expecting a {name} repository)." + ) if repo.is_dirty(): - raise click.ClickException("Uncommitted changes exist.") + raise click.ClickException(f"Uncommitted changes exist in {path}.") return repo From c436867f69a047aa701f08ba93a614903bd3ca65 Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Tue, 7 Jun 2022 12:03:52 +0100 Subject: [PATCH 2/6] Rename repo to synapse_repo --- scripts-dev/release.py | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/scripts-dev/release.py b/scripts-dev/release.py index 26036fe99479..2670badc135f 100755 --- a/scripts-dev/release.py +++ b/scripts-dev/release.py @@ -92,11 +92,11 @@ def prepare() -> None: """ # Make sure we're in a git repo. - repo = get_repo_and_check_clean_checkout() + synapse_repo = get_repo_and_check_clean_checkout() sytest_repo = get_repo_and_check_clean_checkout("../sytest", "sytest") click.secho("Updating git repo...") - repo.remote().fetch() + synapse_repo.remote().fetch() sytest_repo.remote().fetch() # Get the current version and AST from root Synapse module. @@ -171,12 +171,12 @@ def prepare() -> None: assert not parsed_new_version.is_postrelease release_branch_name = get_release_branch_name(parsed_new_version) - release_branch = find_ref(repo, release_branch_name) + release_branch = find_ref(synapse_repo, release_branch_name) if release_branch: if release_branch.is_remote(): # If the release branch only exists on the remote we check it out # locally. - repo.git.checkout(release_branch_name) + synapse_repo.git.checkout(release_branch_name) else: # If a branch doesn't exist we create one. We ask which one branch it # should be based off, defaulting to sensible values depending on the @@ -192,25 +192,25 @@ def prepare() -> None: "Which branch should the release be based on?", default=default ) - base_branch = find_ref(repo, branch_name) + base_branch = find_ref(synapse_repo, branch_name) if not base_branch: print(f"Could not find base branch {branch_name}!") click.get_current_context().abort() # Check out the base branch and ensure it's up to date - repo.head.set_reference(base_branch, "check out the base branch") - repo.head.reset(index=True, working_tree=True) + synapse_repo.head.set_reference(base_branch, "check out the base branch") + synapse_repo.head.reset(index=True, working_tree=True) if not base_branch.is_remote(): - update_branch(repo) + update_branch(synapse_repo) # Create the new release branch # Type ignore will no longer be needed after GitPython 3.1.28. # See https://github.com/gitpython-developers/GitPython/pull/1419 - repo.create_head(release_branch_name, commit=base_branch) # type: ignore[arg-type] + synapse_repo.create_head(release_branch_name, commit=base_branch) # type: ignore[arg-type] # Switch to the release branch and ensure it's up to date. - repo.git.checkout(release_branch_name) - update_branch(repo) + synapse_repo.git.checkout(release_branch_name) + update_branch(synapse_repo) # Update the version specified in pyproject.toml. subprocess.check_output(["poetry", "version", new_version]) @@ -235,15 +235,15 @@ def prepare() -> None: run_until_successful('dch -M -r -D stable ""', shell=True) # Show the user the changes and ask if they want to edit the change log. - repo.git.add("-u") + synapse_repo.git.add("-u") subprocess.run("git diff --cached", shell=True) if click.confirm("Edit changelog?", default=False): click.edit(filename="CHANGES.md") # Commit the changes. - repo.git.add("-u") - repo.git.commit("-m", new_version) + synapse_repo.git.add("-u") + synapse_repo.git.commit("-m", new_version) # We give the option to bail here in case the user wants to make sure things # are OK before pushing. @@ -251,17 +251,21 @@ def prepare() -> None: print("") print("Run when ready to push:") print("") - print(f"\tgit push -u {repo.remote().name} {repo.active_branch.name}") + print( + f"\tgit push -u {synapse_repo.remote().name} {synapse_repo.active_branch.name}" + ) print("") sys.exit(0) # Otherwise, push and open the changelog in the browser. - repo.git.push("-u", repo.remote().name, repo.active_branch.name) + synapse_repo.git.push( + "-u", synapse_repo.remote().name, synapse_repo.active_branch.name + ) print("Opening the changelog in your browser...") print("Please ask others to give it a check.") click.launch( - f"https://github.com/matrix-org/synapse/blob/{repo.active_branch.name}/CHANGES.md" + f"https://github.com/matrix-org/synapse/blob/{synapse_repo.active_branch.name}/CHANGES.md" ) From b69b456b08f4e656fdd307ff2777d4134a4813fc Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Tue, 7 Jun 2022 12:14:06 +0100 Subject: [PATCH 3/6] Create and push a SyTest branch --- scripts-dev/release.py | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/scripts-dev/release.py b/scripts-dev/release.py index 2670badc135f..ba1f1e418c0e 100755 --- a/scripts-dev/release.py +++ b/scripts-dev/release.py @@ -192,21 +192,32 @@ def prepare() -> None: "Which branch should the release be based on?", default=default ) - base_branch = find_ref(synapse_repo, branch_name) - if not base_branch: - print(f"Could not find base branch {branch_name}!") - click.get_current_context().abort() - - # Check out the base branch and ensure it's up to date - synapse_repo.head.set_reference(base_branch, "check out the base branch") - synapse_repo.head.reset(index=True, working_tree=True) - if not base_branch.is_remote(): - update_branch(synapse_repo) - - # Create the new release branch - # Type ignore will no longer be needed after GitPython 3.1.28. - # See https://github.com/gitpython-developers/GitPython/pull/1419 - synapse_repo.create_head(release_branch_name, commit=base_branch) # type: ignore[arg-type] + for repo_name, repo in {"synapse": synapse_repo, "sytest": sytest_repo}.items(): + base_branch = find_ref(repo, branch_name) + if not base_branch: + print(f"Could not find base branch {branch_name} for {repo_name}!") + click.get_current_context().abort() + + # Check out the base branch and ensure it's up to date + repo.head.set_reference( + base_branch, f"check out the base branch for {repo_name}" + ) + repo.head.reset(index=True, working_tree=True) + if not base_branch.is_remote(): + update_branch(repo) + + # Create the new release branch + # Type ignore will no longer be needed after GitPython 3.1.28. + # See https://github.com/gitpython-developers/GitPython/pull/1419 + repo.create_head(release_branch_name, commit=base_branch) # type: ignore[arg-type] + + # Special-case SyTest: we don't actually prepare any files so we may + # as well push it now (and only when we create a release branch; + # not on subsequent RCs or full releases). + if click.confirm("Push new SyTest branch?", default=True): + sytest_repo.git.push( + "-u", sytest_repo.remote().name, sytest_repo.active_branch.name + ) # Switch to the release branch and ensure it's up to date. synapse_repo.git.checkout(release_branch_name) From ea56689051508cf99b0e42f88471f6abbaee7dbf Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Tue, 7 Jun 2022 12:15:25 +0100 Subject: [PATCH 4/6] Newsfile Signed-off-by: Olivier Wilkinson (reivilibre) --- changelog.d/12978.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/12978.misc diff --git a/changelog.d/12978.misc b/changelog.d/12978.misc new file mode 100644 index 000000000000..050c9047fc23 --- /dev/null +++ b/changelog.d/12978.misc @@ -0,0 +1 @@ +Extend the release script to automatically push a new SyTest branch, rather than having that be a manual process. \ No newline at end of file From 14faf39ddec4adb4137a3eb37c17550938f85001 Mon Sep 17 00:00:00 2001 From: reivilibre Date: Wed, 29 Jun 2022 11:02:50 +0100 Subject: [PATCH 5/6] Update scripts-dev/release.py Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> --- scripts-dev/release.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts-dev/release.py b/scripts-dev/release.py index ba1f1e418c0e..0ceb319b5475 100755 --- a/scripts-dev/release.py +++ b/scripts-dev/release.py @@ -95,7 +95,7 @@ def prepare() -> None: synapse_repo = get_repo_and_check_clean_checkout() sytest_repo = get_repo_and_check_clean_checkout("../sytest", "sytest") - click.secho("Updating git repo...") + click.secho("Updating Synapse and Sytest git repos...") synapse_repo.remote().fetch() sytest_repo.remote().fetch() From 733ef7ac695f3162f88c018c28beb3241cf8bb39 Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Tue, 26 Jul 2022 12:13:57 +0100 Subject: [PATCH 6/6] Fix not pushing the right branch to the remote --- scripts-dev/release.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts-dev/release.py b/scripts-dev/release.py index 0ceb319b5475..5bfd750118dc 100755 --- a/scripts-dev/release.py +++ b/scripts-dev/release.py @@ -215,9 +215,7 @@ def prepare() -> None: # as well push it now (and only when we create a release branch; # not on subsequent RCs or full releases). if click.confirm("Push new SyTest branch?", default=True): - sytest_repo.git.push( - "-u", sytest_repo.remote().name, sytest_repo.active_branch.name - ) + sytest_repo.git.push("-u", sytest_repo.remote().name, release_branch_name) # Switch to the release branch and ensure it's up to date. synapse_repo.git.checkout(release_branch_name)