22This script is part of the pytest release process which is triggered by comments
33in issues.
44
5- This script is started by the `prepare_release .yml` workflow, which is triggered by two comment
5+ This script is started by the `release-on-comment .yml` workflow, which is triggered by two comment
66related events:
77
88* https://help.github.com/en/actions/reference/events-that-trigger-workflows#issue-comment-event-issue_comment
99* https://help.github.com/en/actions/reference/events-that-trigger-workflows#issues-event-issues
1010
1111This script receives the payload and a secrets on the command line.
1212
13- The payload must contain a comment with a phrase matching this regular expression:
13+ The payload must contain a comment with a phrase matching this pseudo- regular expression:
1414
15- @pytestbot please prepare release from <branch name>
15+ @pytestbot please prepare (major )? release from <branch name>
1616
1717Then the appropriate version will be obtained based on the given branch name:
1818
19+ * a major release from master if "major" appears in the phrase in that position
1920* a feature or bug fix release from master (based if there are features in the current changelog
2021 folder)
2122* a bug fix from a maintenance branch
@@ -76,15 +77,15 @@ def get_comment_data(payload: Dict) -> str:
7677
7778def validate_and_get_issue_comment_payload (
7879 issue_payload_path : Optional [Path ],
79- ) -> Tuple [str , str ]:
80+ ) -> Tuple [str , str , bool ]:
8081 payload = json .loads (issue_payload_path .read_text (encoding = "UTF-8" ))
8182 body = get_comment_data (payload )["body" ]
82- m = re .match (r"@pytestbot please prepare release from ([\w\-_\.]+)" , body )
83+ m = re .match (r"@pytestbot please prepare (major )? release from ([\w\-_\.]+)" , body )
8384 if m :
84- base_branch = m .group (1 )
85+ is_major , base_branch = m .group (1 ) is not None , m . group ( 2 )
8586 else :
86- base_branch = None
87- return payload , base_branch
87+ is_major , base_branch = False , None
88+ return payload , base_branch , is_major
8889
8990
9091def print_and_exit (msg ) -> None :
@@ -94,7 +95,9 @@ def print_and_exit(msg) -> None:
9495
9596def trigger_release (payload_path : Path , token : str ) -> None :
9697 error_contents = "" # to be used to store error output in case any command fails
97- payload , base_branch = validate_and_get_issue_comment_payload (payload_path )
98+ payload , base_branch , is_major = validate_and_get_issue_comment_payload (
99+ payload_path
100+ )
98101 if base_branch is None :
99102 url = get_comment_data (payload )["html_url" ]
100103 print_and_exit (
@@ -109,10 +112,9 @@ def trigger_release(payload_path: Path, token: str) -> None:
109112 issue = repo .issue (issue_number )
110113
111114 check_call (["git" , "checkout" , f"origin/{ base_branch } " ])
112- print ("DEBUG:" , check_output (["git" , "rev-parse" , "HEAD" ]))
113115
114116 try :
115- version = find_next_version (base_branch )
117+ version = find_next_version (base_branch , is_major )
116118 except InvalidFeatureRelease as e :
117119 issue .create_comment (str (e ))
118120 print_and_exit (f"{ Fore .RED } { e } " )
@@ -215,7 +217,7 @@ def trigger_release(payload_path: Path, token: str) -> None:
215217 print_and_exit (f"{ Fore .RED } { error_contents } " )
216218
217219
218- def find_next_version (base_branch : str ) -> str :
220+ def find_next_version (base_branch : str , is_major : bool ) -> str :
219221 output = check_output (["git" , "tag" ], encoding = "UTF-8" )
220222 valid_versions = []
221223 for v in output .splitlines ():
@@ -242,7 +244,9 @@ def find_next_version(base_branch: str) -> str:
242244 msg += "\n " .join (f"* `{ x .name } `" for x in sorted (features + breaking ))
243245 raise InvalidFeatureRelease (msg )
244246
245- if is_feature_release :
247+ if is_major :
248+ return f"{ last_version [0 ]+ 1 } .0.0"
249+ elif is_feature_release :
246250 return f"{ last_version [0 ]} .{ last_version [1 ] + 1 } .0"
247251 else :
248252 return f"{ last_version [0 ]} .{ last_version [1 ]} .{ last_version [2 ] + 1 } "
0 commit comments