diff --git a/dev/releases/create_stable_branch.py b/dev/releases/create_stable_branch.py index 78b3b5c7bd..e07b931095 100755 --- a/dev/releases/create_stable_branch.py +++ b/dev/releases/create_stable_branch.py @@ -14,81 +14,107 @@ # TODO: implement parts of the steps described in # -from utils import * +from utils import error, notice, warning, patchfile +import utils import subprocess +import sys # Insist on Python >= 3.6 for f-strings and other goodies -if sys.version_info < (3,6): +if sys.version_info < (3, 6): error("Python 3.6 or newer is required") -notice("Checking prerequisites") -verify_command_available("git") -verify_git_repo() -verify_git_clean() -# TODO: verify that we are on `master`, and that we are up-to-date (`git pull`) +def usage(name: str) -> None: + print(f"Usage: `{name} MINOR` creates the branch `stable-4.MINOR`") + sys.exit(1) -# TODO: verify that `./configure && make` were already run -gap_minor_version = 12 # TODO: this should be an argument or so? -gapversion = f"4.{gap_minor_version}" -nextgapversion = f"4.{gap_minor_version+1}" -stable_branch = "stable-" + gapversion # TODO: how to specify this? probably have the version as argument? +def main(gap_minor_version_str: str) -> None: + gap_minor_version = int(gap_minor_version_str) + gapversion = f"4.{gap_minor_version}" + nextgapversion = f"4.{gap_minor_version+1}" + stable_branch = "stable-" + gapversion -# TODO: error out if the branch already exists + notice("Checking prerequisites") + utils.verify_command_available("git") + utils.verify_git_repo() + utils.verify_git_clean() -# TODO: Create a pair of labels for GitHub issues called backport-to-X.Y and backport-to-X.Y-DONE. + notice(f"Switching to master branch") + subprocess.run(["git", "switch", "master"], check=True) -# TODO: Create a GitHub milestone for GAP X.Y.0 release. + notice(f"Ensure branch is up-to-date") + subprocess.run(["git", "pull", "--ff-only"], check=True) -notice(f"Creating branch {stable_branch}") -subprocess.run(["git", "branch", stable_branch], check=True) + # create the new branch now, before we add a commit to master + notice(f"Creating branch {stable_branch}") + subprocess.run(["git", "branch", stable_branch], check=True) - -# list of files which (potentially) are updated -files = [ + # list of files which (potentially) are updated + files = [ "CITATION", "configure.ac", "doc/versiondata", + ] + + notice("Updating version to {nextgapversion} on master branch") + for f in files: + notice(" patching " + f) + patchfile(f, gapversion + "dev", nextgapversion + "dev") + + notice("Commit master branch updates") + subprocess.run( + ["git", "commit", "-m", f"Start work on GAP {nextgapversion}", *files], + check=True, + ) + + notice(f"Tag master with v{nextgapversion}dev") + subprocess.run( + [ + "git", + "tag", + "-m", + f"Start work on GAP {nextgapversion}", + f"v{nextgapversion}dev", + ], + check=True, + ) + + notice(f"Switching to {stable_branch} branch") + subprocess.run(["git", "switch", stable_branch], check=True) + + notice("Patching files") + patchfile("Makefile.rules", "PKG_BRANCH = master", "PKG_BRANCH = " + stable_branch) + # adjust the CI and code coverage badges in README.md + patchfile("README.md", "master", stable_branch) + + notice(f"Create start commit for {stable_branch} branch") + files = [ "Makefile.rules", "README.md", - ] - -notice("Updating configure.ac on master branch") -patchfile("configure.ac", r"m4_define\(\[gap_version\],[^\n]+", r"m4_define([gap_version], ["+nextgapversion+"dev])") - -notice("Regenerate some files") -run_with_log(["make", "CITATION", "doc/versiondata"], "make") - -notice("Commit master branch updates") -subprocess.run(["git", "commit", "-m", f"Start work on GAP {nextgapversion}", *files], check=True) - -notice(f"Tag master with v{nextgapversion}dev") -subprocess.run(["git", "tag", "-m", f"Start work on GAP {nextgapversion}", f"v{nextgapversion}dev"], check=True) - -# TODO: push tags/commits? actually, we disabled direct pushes to -# master, so perhaps we should have created the above commit on a pull -# request, and create the tag only after it is merged?!? but then the -# sha changes ... so perhaps better is that an admin temporarily -# disables the branch protection rule so they can push -subprocess.run(["git", "push"], check=True) -subprocess.run(["git", "push", "--tags"], check=True) + ] + subprocess.run( + ["git", "commit", "-m", f"Create {stable_branch} branch", *files], check=True + ) + # push to the server + input( + f"Please 'git push master {stable_branch} v{nextgapversion}dev' now (you may have to temporarily change branch protection rules), then press ENTER" + ) -notice(f"Updating {stable_branch} branch") -subprocess.run(["git", "switch", stable_branch], check=True) + input( + f"Please create GitHub labels backport-to-{gapversion} and backport-to-{gapversion}-DONE, then press ENTER" + ) -notice("Patching files") -patchfile("Makefile.rules", r"PKG_BRANCH = master", r"PKG_BRANCH = "+stable_branch) -patchfile("README.md", r"master", r""+stable_branch) + input( + f"Please create a GitHub milestone for GAP {nextgapversion}.0 , then press ENTER" + ) -notice("Regenerate some files") -run_with_log(["make", "CITATION", "doc/versiondata"], "make") -notice(f"Create start commit for {stable_branch} branch") -subprocess.run(["git", "commit", "-m", f"Create {stable_branch} branch", *files], check=True) +if __name__ == "__main__": + # the argument is the new version + if len(sys.argv) != 2: + usage(sys.argv[0]) -# push to the server -# -#subprocess.run(["git", "push", "--set-upstream", "origin", stable_branch], check=True) + main(sys.argv[1])