Skip to content

Commit 1435b88

Browse files
committed
support alpha workflow on feature branch
1 parent cc61a15 commit 1435b88

File tree

1 file changed

+54
-7
lines changed

1 file changed

+54
-7
lines changed

scripts/release.py

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727

2828
RELEASE_BRANCH_PREFIX = "prepare-release-"
2929

30-
PRERELEASE_VERSION_PATTERN = re.compile(r"^(?:a|rc)([1-9]\d*)$")
30+
PRERELEASE_VERSION_PATTERN = re.compile(r"^(a|rc)([1-9]\d*)$")
31+
32+
RELEASE_BRANCH_PATTERN = re.compile(r"^\d+\.\d+\.x$")
3133

3234

3335
class Version(BaseVersion):
@@ -210,6 +212,15 @@ def git_current_branch() -> Text:
210212
return "master"
211213

212214

215+
def git_current_branch_is_master_or_release() -> bool:
216+
"""Returns True if the current local git branch is master or a release branch e.g. 1.10.x"""
217+
current_branch = git_current_branch()
218+
return (
219+
current_branch == "master"
220+
or RELEASE_BRANCH_PATTERN.match(current_branch) is not None
221+
)
222+
223+
213224
def create_release_branch(version: Text) -> Text:
214225
"""Create a new branch for this release. Returns the branch name."""
215226

@@ -261,12 +272,28 @@ def is_prerelease_version(version: Version) -> bool:
261272
)
262273

263274

275+
def is_alpha_version(version: Version) -> bool:
276+
"""
277+
Validate that the alpha part in a version follows
278+
the pattern specified in `PRERELEASE_VERSION_PATTERN`
279+
and is an alpha (as opposed to a release candidate).
280+
"""
281+
if len(version.prerelease) != 1:
282+
return False
283+
284+
version_match = PRERELEASE_VERSION_PATTERN.match(version.prerelease[0])
285+
if version_match is None:
286+
return False
287+
288+
return version_match.group(1) == "a"
289+
290+
264291
def next_prerelease(version: Version, flavor: Text) -> Version:
265292
"""Bump the current version to the next prerelease."""
266293
prerelease_number = 0
267294
if version.prerelease:
268295
prerelease_number = int(
269-
PRERELEASE_VERSION_PATTERN.match(version.prerelease[0]).group(1)
296+
PRERELEASE_VERSION_PATTERN.match(version.prerelease[0]).group(2)
270297
)
271298

272299
return Version(
@@ -317,6 +344,18 @@ def print_done_message(branch: Text, base: Text, version: Text) -> None:
317344
print(f"Please open a PR on GitHub: {pull_request_url}")
318345

319346

347+
def print_done_message_same_branch(version: Text) -> None:
348+
"""
349+
Print final information for the user in case changes
350+
are directly committed on this branch.
351+
"""
352+
353+
print()
354+
print(
355+
f"\033[94m All done - changes for version {version} where committed on this branch \033[0m"
356+
)
357+
358+
320359
def main(args: argparse.Namespace) -> None:
321360
"""Start a release preparation."""
322361

@@ -337,13 +376,21 @@ def main(args: argparse.Namespace) -> None:
337376
if not version.prerelease:
338377
# never update changelog on a prerelease version
339378
generate_changelog(version)
340-
base = git_current_branch()
341-
branch = create_release_branch(version)
342379

343-
create_commit(version)
344-
push_changes()
380+
# alpha workflow on feature branch when a version bump is required
381+
if is_alpha_version(version) and not git_current_branch_is_master_or_release():
382+
create_commit(version)
383+
push_changes()
384+
385+
print_done_message_same_branch(version)
386+
else:
387+
base = git_current_branch()
388+
branch = create_release_branch(version)
389+
390+
create_commit(version)
391+
push_changes()
345392

346-
print_done_message(branch, base, version)
393+
print_done_message(branch, base, version)
347394

348395

349396
if __name__ == "__main__":

0 commit comments

Comments
 (0)