27
27
28
28
RELEASE_BRANCH_PREFIX = "prepare-release-"
29
29
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$" )
31
33
32
34
33
35
class Version (BaseVersion ):
@@ -210,6 +212,15 @@ def git_current_branch() -> Text:
210
212
return "master"
211
213
212
214
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
+
213
224
def create_release_branch (version : Text ) -> Text :
214
225
"""Create a new branch for this release. Returns the branch name."""
215
226
@@ -261,12 +272,28 @@ def is_prerelease_version(version: Version) -> bool:
261
272
)
262
273
263
274
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
+
264
291
def next_prerelease (version : Version , flavor : Text ) -> Version :
265
292
"""Bump the current version to the next prerelease."""
266
293
prerelease_number = 0
267
294
if version .prerelease :
268
295
prerelease_number = int (
269
- PRERELEASE_VERSION_PATTERN .match (version .prerelease [0 ]).group (1 )
296
+ PRERELEASE_VERSION_PATTERN .match (version .prerelease [0 ]).group (2 )
270
297
)
271
298
272
299
return Version (
@@ -317,6 +344,18 @@ def print_done_message(branch: Text, base: Text, version: Text) -> None:
317
344
print (f"Please open a PR on GitHub: { pull_request_url } " )
318
345
319
346
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
+
320
359
def main (args : argparse .Namespace ) -> None :
321
360
"""Start a release preparation."""
322
361
@@ -337,13 +376,21 @@ def main(args: argparse.Namespace) -> None:
337
376
if not version .prerelease :
338
377
# never update changelog on a prerelease version
339
378
generate_changelog (version )
340
- base = git_current_branch ()
341
- branch = create_release_branch (version )
342
379
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 ()
345
392
346
- print_done_message (branch , base , version )
393
+ print_done_message (branch , base , version )
347
394
348
395
349
396
if __name__ == "__main__" :
0 commit comments