diff --git a/dev/releases/make_archives.py b/dev/releases/make_archives.py index 7a8252e319e..29c43acca87 100755 --- a/dev/releases/make_archives.py +++ b/dev/releases/make_archives.py @@ -25,14 +25,13 @@ import sys import tarfile +from typing import List, Optional + from utils import ( download_with_sha256, error, - get_makefile_var, notice, patchfile, - run_with_log, - safe_git_fetch_tags, verify_command_available, verify_git_clean, verify_git_repo, @@ -43,6 +42,27 @@ if sys.version_info < (3, 6): error("Python 3.6 or newer is required") + +# helper for extracting values of variables set in the GAP Makefiles.rules +def get_makefile_var(var: str) -> str: + res = subprocess.run(["make", f"print-{var}"], check=True, capture_output=True) + kv = res.stdout.decode("ascii").strip().split("=") + assert len(kv) == 2 + assert kv[0] == var + return kv[1] + + +# Run what ever command and create appropriate log file +def run_with_log(args: List[str], name: str, msg: Optional[str] = None) -> None: + if not msg: + msg = name + with open("../" + name + ".log", "w", encoding="utf-8") as fp: + try: + subprocess.run(args, check=True, stdout=fp, stderr=fp) + except subprocess.CalledProcessError: + error(msg + " failed. See " + name + ".log.") + + notice("Checking prerequisites") verify_command_available("curl") verify_command_available("git") @@ -52,7 +72,11 @@ verify_git_clean() # fetch tags, so we can properly detect -safe_git_fetch_tags() +try: + subprocess.run(["git", "fetch", "--tags"], check=True) +except subprocess.CalledProcessError: + error("failed to fetch tags, you may have to do \n" + "git fetch --tags -f") + # Creating tmp directory tmpdir = os.getcwd() + "/tmp" diff --git a/dev/releases/make_github_release.py b/dev/releases/make_github_release.py index 48d1003543d..a3a598b1d46 100755 --- a/dev/releases/make_github_release.py +++ b/dev/releases/make_github_release.py @@ -11,6 +11,8 @@ ## This script makes a github release and uploads all tarballs as assets. ## import sys +import re +import subprocess import utils import utils_github @@ -19,12 +21,51 @@ if len(sys.argv) != 3: error("usage: " + sys.argv[0] + " ") + +def is_possible_gap_release_tag(tag: str) -> bool: + return re.fullmatch(r"v[1-9]+\.[0-9]+\.[0-9]+(-.+)?", tag) is not None + + +def verify_is_possible_gap_release_tag(tag: str) -> None: + if not is_possible_gap_release_tag(tag): + error(f"{tag} does not look like the tag of a GAP release version") + + +# lightweight vs annotated +# https://stackoverflow.com/questions/40479712/how-can-i-tell-if-a-given-git-tag-is-annotated-or-lightweight#40499437 +def is_annotated_git_tag(tag: str) -> bool: + res = subprocess.run( + ["git", "for-each-ref", "refs/tags/" + tag], + capture_output=True, + text=True, + check=False, + ) + return res.returncode == 0 and res.stdout.split()[1] == "tag" + + +def check_git_tag_for_release(tag: str) -> None: + if not is_annotated_git_tag(tag): + error(f"There is no annotated tag {tag}") + # check that tag points to HEAD + tag_commit = subprocess.run( + ["git", "rev-parse", tag + "^{}"], check=True, capture_output=True, text=True + ).stdout.strip() + head = subprocess.run( + ["git", "rev-parse", "HEAD"], check=True, capture_output=True, text=True + ).stdout.strip() + if tag_commit != head: + error( + f"The tag {tag} does not point to the current commit {head} but" + + f" instead points to {tag_commit}" + ) + + TAG_NAME = sys.argv[1] PATH_TO_RELEASE = sys.argv[2] VERSION = TAG_NAME[1:] # strip 'v' prefix utils.verify_git_clean() -utils.verify_is_possible_gap_release_tag(TAG_NAME) +verify_is_possible_gap_release_tag(TAG_NAME) repo = utils_github.initialize_github() # Error if the tag TAG_NAME hasn't been pushed out yet. @@ -35,7 +76,7 @@ # - exists # - is an annotated tag # - points to current HEAD -utils.check_git_tag_for_release(TAG_NAME) +check_git_tag_for_release(TAG_NAME) # Error if this release has been already created on GitHub if any(r.tag_name == TAG_NAME for r in repo.get_releases()): diff --git a/dev/releases/release_notes.py b/dev/releases/release_notes.py index 309a66c6b13..2bc47af2431 100755 --- a/dev/releases/release_notes.py +++ b/dev/releases/release_notes.py @@ -29,7 +29,7 @@ from typing import Any, Dict, List, TextIO import requests -from utils import download_with_sha256, error, is_existing_tag, notice, warning +from utils import download_with_sha256, error, notice, warning def usage(name: str) -> None: @@ -37,6 +37,13 @@ def usage(name: str) -> None: sys.exit(1) +def is_existing_tag(tag: str) -> bool: + res = subprocess.run( + ["git", "show-ref", "--quiet", "--verify", "refs/tags/" + tag], check=False + ) + return res.returncode == 0 + + def find_previous_version(version: str) -> str: major, minor, patchlevel = map(int, version.split(".")) if major != 4: diff --git a/dev/releases/utils.py b/dev/releases/utils.py index 2ddbef83ce3..e38c0ba72f2 100644 --- a/dev/releases/utils.py +++ b/dev/releases/utils.py @@ -14,7 +14,7 @@ import shutil import subprocess import sys -from typing import Iterator, List, NoReturn, Optional +from typing import Iterator, NoReturn import requests @@ -38,9 +38,6 @@ def error(msg: str) -> NoReturn: def verify_command_available(cmd: str) -> None: if shutil.which(cmd) is None: error(f"the '{cmd}' command was not found, please install it") - # TODO: do the analog of this in ReleaseTools bash script: - # command -v curl >/dev/null 2>&1 || - # error "the 'curl' command was not found, please install it" def verify_git_repo() -> None: @@ -77,15 +74,6 @@ def working_directory(path: str) -> Iterator[None]: os.chdir(prev_cwd) -# helper for extracting values of variables set in the GAP Makefiles.rules -def get_makefile_var(var: str) -> str: - res = subprocess.run(["make", f"print-{var}"], check=True, capture_output=True) - kv = res.stdout.decode("ascii").strip().split("=") - assert len(kv) == 2 - assert kv[0] == var - return kv[1] - - # compute the sha256 checksum of a file def sha256file(path: str) -> str: h = hashlib.sha256() @@ -138,67 +126,3 @@ def download_with_sha256(url: str, dst: str) -> None: error( f"checksum for '{dst}' expected to be {expected_checksum} but got {actual_checksum}" ) - - -# Run what ever command and create appropriate log file -def run_with_log(args: List[str], name: str, msg: Optional[str] = None) -> None: - if not msg: - msg = name - with open("../" + name + ".log", "w", encoding="utf-8") as fp: - try: - subprocess.run(args, check=True, stdout=fp, stderr=fp) - except subprocess.CalledProcessError: - error(msg + " failed. See " + name + ".log.") - - -def is_possible_gap_release_tag(tag: str) -> bool: - return re.fullmatch(r"v[1-9]+\.[0-9]+\.[0-9]+(-.+)?", tag) is not None - - -def verify_is_possible_gap_release_tag(tag: str) -> None: - if not is_possible_gap_release_tag(tag): - error(f"{tag} does not look like the tag of a GAP release version") - - -def is_existing_tag(tag: str) -> bool: - res = subprocess.run( - ["git", "show-ref", "--quiet", "--verify", "refs/tags/" + tag], check=False - ) - return res.returncode == 0 - - -# Error checked git fetch of tags -def safe_git_fetch_tags() -> None: - try: - subprocess.run(["git", "fetch", "--tags"], check=True) - except subprocess.CalledProcessError: - error("failed to fetch tags, you may have to do \n" + "git fetch --tags -f") - - -# lightweight vs annotated -# https://stackoverflow.com/questions/40479712/how-can-i-tell-if-a-given-git-tag-is-annotated-or-lightweight#40499437 -def is_annotated_git_tag(tag: str) -> bool: - res = subprocess.run( - ["git", "for-each-ref", "refs/tags/" + tag], - capture_output=True, - text=True, - check=False, - ) - return res.returncode == 0 and res.stdout.split()[1] == "tag" - - -def check_git_tag_for_release(tag: str) -> None: - if not is_annotated_git_tag(tag): - error(f"There is no annotated tag {tag}") - # check that tag points to HEAD - tag_commit = subprocess.run( - ["git", "rev-parse", tag + "^{}"], check=True, capture_output=True, text=True - ).stdout.strip() - head = subprocess.run( - ["git", "rev-parse", "HEAD"], check=True, capture_output=True, text=True - ).stdout.strip() - if tag_commit != head: - error( - f"The tag {tag} does not point to the current commit {head} but" - + f" instead points to {tag_commit}" - )