Skip to content

Commit 5b50825

Browse files
committed
Add PR to bump version after finalizing release
1 parent e67b6d8 commit 5b50825

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

.github/workflows/finalize-release.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,29 @@ jobs:
5656
version=${BASE_REF#rc/}
5757
echo "Finalizing release v$version"
5858
59-
gh release edit "v$version" --draft=false --tag=v$version
59+
gh release edit "v$version" --draft=false --tag=v$version
60+
61+
- name: Determine if release was a hotfix release
62+
run: |
63+
version=${BASE_REF#rc/}
64+
echo "HOTFIX_RELEASE=$(python scripts/release/is-hotfix.py $version)" >> "$GITHUB_ENV"
65+
66+
- name: Bump main version
67+
if: env.HOTFIX_RELEASE == 'false'
68+
run: |
69+
version=${BASE_REF#rc/}
70+
next_version="$version-dev"
71+
echo "Bumping main version to $next_version"
72+
73+
git switch main
74+
git pull --ff-only origin main
75+
76+
git switch -c release-automation/bump-version
77+
78+
python scripts/bump_version.sh "$next_version"
79+
80+
git add -u .
81+
git commit -m "Bump version to $next_version"
82+
git push --set-upstream origin release-automation/bump-version
83+
84+
gh pr create --repo $GITHUB_REPOSITORY --base main --head release-automation/bump-version --body "Bump the version of main to the dev label of the just released version $next_version" --title "Bump version to $next_version"

scripts/release/is-hotfix-release.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from semantic_version import Version # type: ignore
2+
from subprocess import run
3+
from typing import List, Literal, TYPE_CHECKING
4+
from sys import stderr
5+
6+
if TYPE_CHECKING:
7+
from argparse import Namespace
8+
9+
def get_merge_base_of_ref() -> str:
10+
cp = run(["git", "merge-base", "HEAD", "origin/main"], capture_output=True, text=True)
11+
if cp.returncode != 0:
12+
raise RuntimeError("Failed to get merge base")
13+
return cp.stdout.strip()
14+
15+
def get_release_branches_containing(commit: str) -> List[Version]:
16+
cp = run(["git", "branch", "--list", "rc/*", "--contains", commit], capture_output=True, text=True)
17+
if cp.returncode != 0:
18+
raise RuntimeError("Failed to get branches containing commit")
19+
release_versions: List[Version] = []
20+
for version in [b.strip() for b in cp.stdout.splitlines()]:
21+
try:
22+
if version.startswith("rc/"):
23+
version = version[3:]
24+
release_versions.append(Version(version))
25+
except ValueError:
26+
print(f"Warning: Skipping invalid version string: {version}", file=stderr)
27+
28+
return release_versions
29+
30+
def main(args: 'Namespace') -> Literal[0,1]:
31+
try:
32+
merge_base = get_merge_base_of_ref()
33+
release_versions = get_release_branches_containing(merge_base)
34+
if len(release_versions) == 0:
35+
print(f"Info: No release branches found containing merge base {merge_base}", file=stderr)
36+
print("false")
37+
return 0
38+
39+
for version in release_versions:
40+
if version.next_patch() == Version(args.version):
41+
print("true")
42+
return 0
43+
44+
print("false")
45+
return 0
46+
except RuntimeError as e:
47+
print(f"Error: {e}", file=stderr)
48+
return 1
49+
50+
if __name__ == '__main__':
51+
from sys import stderr, exit
52+
import argparse
53+
54+
parser = argparse.ArgumentParser(description="Check if a version is a hotfix release")
55+
parser.add_argument("version", help="The version string to compare against the base branches")
56+
exit(main(parser.parse_args()))

0 commit comments

Comments
 (0)