|
8 | 8 | ## |
9 | 9 | ## SPDX-License-Identifier: GPL-2.0-or-later |
10 | 10 | ## |
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. |
17 | 12 | ## |
| 13 | +import re |
| 14 | +import subprocess |
18 | 15 | import sys |
19 | 16 |
|
20 | 17 | import utils |
|
24 | 21 | if len(sys.argv) != 3: |
25 | 22 | error("usage: " + sys.argv[0] + " <tag_name> <path_to_release>") |
26 | 23 |
|
| 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 | + |
27 | 63 | TAG_NAME = sys.argv[1] |
28 | 64 | PATH_TO_RELEASE = sys.argv[2] |
29 | 65 | VERSION = TAG_NAME[1:] # strip 'v' prefix |
30 | 66 |
|
31 | 67 | 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() |
34 | 70 |
|
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}'") |
38 | 74 |
|
39 | 75 | # make sure that TAG_NAME |
40 | 76 | # - exists |
41 | 77 | # - is an annotated tag |
42 | 78 | # - points to current HEAD |
43 | | -utils.check_git_tag_for_release(TAG_NAME) |
| 79 | +check_git_tag_for_release(TAG_NAME) |
44 | 80 |
|
45 | 81 | # 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()): |
47 | 83 | error(f"Github release with tag '{TAG_NAME}' already exists!") |
48 | 84 |
|
49 | 85 | # Create release |
|
52 | 88 | + f"[CHANGES.md](https://github.com/gap-system/gap/blob/{TAG_NAME}/CHANGES.md) file." |
53 | 89 | ) |
54 | 90 | 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) |
58 | 92 |
|
59 | 93 | with utils.working_directory(PATH_TO_RELEASE): |
60 | 94 | manifest_filename = "MANIFEST" |
|
0 commit comments