Skip to content

Commit 3128572

Browse files
authored
rewrite dev/releases/update_website.py, cleanup devtools (#5793)
* rewrite dev/releases/update_website.py to be compatible with new GapWWW * remove global variables in utils_github * move stuff out of utils.py that has only one user
1 parent 0cd14ac commit 3128572

6 files changed

Lines changed: 164 additions & 246 deletions

File tree

dev/releases/make_archives.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@
2424
import subprocess
2525
import sys
2626
import tarfile
27+
from typing import List, Optional
2728

2829
from utils import (
2930
download_with_sha256,
3031
error,
31-
get_makefile_var,
3232
notice,
3333
patchfile,
34-
run_with_log,
35-
safe_git_fetch_tags,
3634
verify_command_available,
3735
verify_git_clean,
3836
verify_git_repo,
@@ -43,6 +41,27 @@
4341
if sys.version_info < (3, 6):
4442
error("Python 3.6 or newer is required")
4543

44+
45+
# helper for extracting values of variables set in the GAP Makefiles.rules
46+
def get_makefile_var(var: str) -> str:
47+
res = subprocess.run(["make", f"print-{var}"], check=True, capture_output=True)
48+
kv = res.stdout.decode("ascii").strip().split("=")
49+
assert len(kv) == 2
50+
assert kv[0] == var
51+
return kv[1]
52+
53+
54+
# Run what ever <args> command and create appropriate log file
55+
def run_with_log(args: List[str], name: str, msg: Optional[str] = None) -> None:
56+
if not msg:
57+
msg = name
58+
with open("../" + name + ".log", "w", encoding="utf-8") as fp:
59+
try:
60+
subprocess.run(args, check=True, stdout=fp, stderr=fp)
61+
except subprocess.CalledProcessError:
62+
error(msg + " failed. See " + name + ".log.")
63+
64+
4665
notice("Checking prerequisites")
4766
verify_command_available("curl")
4867
verify_command_available("git")
@@ -52,7 +71,11 @@
5271
verify_git_clean()
5372

5473
# fetch tags, so we can properly detect
55-
safe_git_fetch_tags()
74+
try:
75+
subprocess.run(["git", "fetch", "--tags"], check=True)
76+
except subprocess.CalledProcessError:
77+
error("failed to fetch tags, you may have to do \n" + "git fetch --tags -f")
78+
5679

5780
# Creating tmp directory
5881
tmpdir = os.getcwd() + "/tmp"

dev/releases/make_github_release.py

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@
88
##
99
## SPDX-License-Identifier: GPL-2.0-or-later
1010
##
11-
## This script makes a github release and uploads all tar balls as assets.
12-
## The name of the target repository CURRENT_REPO_NAME is defined in
13-
## utils.py.
14-
##
15-
## If we do import * from utils, then initialize_github can't overwrite the
16-
## global CURRENT_REPO variables.
11+
## This script makes a github release and uploads all tarballs as assets.
1712
##
13+
import re
14+
import subprocess
1815
import sys
1916

2017
import utils
@@ -24,26 +21,65 @@
2421
if len(sys.argv) != 3:
2522
error("usage: " + sys.argv[0] + " <tag_name> <path_to_release>")
2623

24+
25+
def is_possible_gap_release_tag(tag: str) -> bool:
26+
return re.fullmatch(r"v[1-9]+\.[0-9]+\.[0-9]+(-.+)?", tag) is not None
27+
28+
29+
def verify_is_possible_gap_release_tag(tag: str) -> None:
30+
if not is_possible_gap_release_tag(tag):
31+
error(f"{tag} does not look like the tag of a GAP release version")
32+
33+
34+
# lightweight vs annotated
35+
# https://stackoverflow.com/questions/40479712/how-can-i-tell-if-a-given-git-tag-is-annotated-or-lightweight#40499437
36+
def is_annotated_git_tag(tag: str) -> bool:
37+
res = subprocess.run(
38+
["git", "for-each-ref", "refs/tags/" + tag],
39+
capture_output=True,
40+
text=True,
41+
check=False,
42+
)
43+
return res.returncode == 0 and res.stdout.split()[1] == "tag"
44+
45+
46+
def check_git_tag_for_release(tag: str) -> None:
47+
if not is_annotated_git_tag(tag):
48+
error(f"There is no annotated tag {tag}")
49+
# check that tag points to HEAD
50+
tag_commit = subprocess.run(
51+
["git", "rev-parse", tag + "^{}"], check=True, capture_output=True, text=True
52+
).stdout.strip()
53+
head = subprocess.run(
54+
["git", "rev-parse", "HEAD"], check=True, capture_output=True, text=True
55+
).stdout.strip()
56+
if tag_commit != head:
57+
error(
58+
f"The tag {tag} does not point to the current commit {head} but"
59+
+ f" instead points to {tag_commit}"
60+
)
61+
62+
2763
TAG_NAME = sys.argv[1]
2864
PATH_TO_RELEASE = sys.argv[2]
2965
VERSION = TAG_NAME[1:] # strip 'v' prefix
3066

3167
utils.verify_git_clean()
32-
utils.verify_is_possible_gap_release_tag(TAG_NAME)
33-
utils_github.initialize_github()
68+
verify_is_possible_gap_release_tag(TAG_NAME)
69+
repo = utils_github.initialize_github()
3470

35-
# Error if the tag TAG_NAME hasn't been pushed to CURRENT_REPO yet.
36-
if not any(tag.name == TAG_NAME for tag in utils_github.CURRENT_REPO.get_tags()):
37-
error(f"Repository {utils_github.CURRENT_REPO_NAME} has no tag '{TAG_NAME}'")
71+
# Error if the tag TAG_NAME hasn't been pushed out yet.
72+
if not any(tag.name == TAG_NAME for tag in repo.get_tags()):
73+
error(f"Repository {repo.full_name} has no tag '{TAG_NAME}'")
3874

3975
# make sure that TAG_NAME
4076
# - exists
4177
# - is an annotated tag
4278
# - points to current HEAD
43-
utils.check_git_tag_for_release(TAG_NAME)
79+
check_git_tag_for_release(TAG_NAME)
4480

4581
# Error if this release has been already created on GitHub
46-
if any(r.tag_name == TAG_NAME for r in utils_github.CURRENT_REPO.get_releases()):
82+
if any(r.tag_name == TAG_NAME for r in repo.get_releases()):
4783
error(f"Github release with tag '{TAG_NAME}' already exists!")
4884

4985
# Create release
@@ -52,9 +88,7 @@
5288
+ f"[CHANGES.md](https://github.com/gap-system/gap/blob/{TAG_NAME}/CHANGES.md) file."
5389
)
5490
notice(f"Creating release {TAG_NAME}")
55-
RELEASE = utils_github.CURRENT_REPO.create_git_release(
56-
TAG_NAME, TAG_NAME, RELEASE_NOTE, prerelease=True
57-
)
91+
RELEASE = repo.create_git_release(TAG_NAME, TAG_NAME, RELEASE_NOTE, prerelease=True)
5892

5993
with utils.working_directory(PATH_TO_RELEASE):
6094
manifest_filename = "MANIFEST"

dev/releases/release_notes.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,21 @@
2929
from typing import Any, Dict, List, TextIO
3030

3131
import requests
32-
from utils import download_with_sha256, error, is_existing_tag, notice, warning
32+
from utils import download_with_sha256, error, notice, warning
3333

3434

3535
def usage(name: str) -> None:
3636
print(f"Usage: `{name} NEWVERSION`")
3737
sys.exit(1)
3838

3939

40+
def is_existing_tag(tag: str) -> bool:
41+
res = subprocess.run(
42+
["git", "show-ref", "--quiet", "--verify", "refs/tags/" + tag], check=False
43+
)
44+
return res.returncode == 0
45+
46+
4047
def find_previous_version(version: str) -> str:
4148
major, minor, patchlevel = map(int, version.split("."))
4249
if major != 4:

0 commit comments

Comments
 (0)