2
2
This script is part of the pytest release process which is triggered by comments
3
3
in issues.
4
4
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
6
6
related events:
7
7
8
8
* https://help.github.com/en/actions/reference/events-that-trigger-workflows#issue-comment-event-issue_comment
9
9
* https://help.github.com/en/actions/reference/events-that-trigger-workflows#issues-event-issues
10
10
11
11
This script receives the payload and a secrets on the command line.
12
12
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:
14
14
15
- @pytestbot please prepare release from <branch name>
15
+ @pytestbot please prepare (major )? release from <branch name>
16
16
17
17
Then the appropriate version will be obtained based on the given branch name:
18
18
19
+ * a major release from master if "major" appears in the phrase in that position
19
20
* a feature or bug fix release from master (based if there are features in the current changelog
20
21
folder)
21
22
* a bug fix from a maintenance branch
@@ -76,15 +77,15 @@ def get_comment_data(payload: Dict) -> str:
76
77
77
78
def validate_and_get_issue_comment_payload (
78
79
issue_payload_path : Optional [Path ],
79
- ) -> Tuple [str , str ]:
80
+ ) -> Tuple [str , str , bool ]:
80
81
payload = json .loads (issue_payload_path .read_text (encoding = "UTF-8" ))
81
82
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 )
83
84
if m :
84
- base_branch = m .group (1 )
85
+ is_major , base_branch = m .group (1 ) is not None , m . group ( 2 )
85
86
else :
86
- base_branch = None
87
- return payload , base_branch
87
+ is_major , base_branch = False , None
88
+ return payload , base_branch , is_major
88
89
89
90
90
91
def print_and_exit (msg ) -> None :
@@ -94,7 +95,9 @@ def print_and_exit(msg) -> None:
94
95
95
96
def trigger_release (payload_path : Path , token : str ) -> None :
96
97
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
+ )
98
101
if base_branch is None :
99
102
url = get_comment_data (payload )["html_url" ]
100
103
print_and_exit (
@@ -109,10 +112,9 @@ def trigger_release(payload_path: Path, token: str) -> None:
109
112
issue = repo .issue (issue_number )
110
113
111
114
check_call (["git" , "checkout" , f"origin/{ base_branch } " ])
112
- print ("DEBUG:" , check_output (["git" , "rev-parse" , "HEAD" ]))
113
115
114
116
try :
115
- version = find_next_version (base_branch )
117
+ version = find_next_version (base_branch , is_major )
116
118
except InvalidFeatureRelease as e :
117
119
issue .create_comment (str (e ))
118
120
print_and_exit (f"{ Fore .RED } { e } " )
@@ -215,7 +217,7 @@ def trigger_release(payload_path: Path, token: str) -> None:
215
217
print_and_exit (f"{ Fore .RED } { error_contents } " )
216
218
217
219
218
- def find_next_version (base_branch : str ) -> str :
220
+ def find_next_version (base_branch : str , is_major : bool ) -> str :
219
221
output = check_output (["git" , "tag" ], encoding = "UTF-8" )
220
222
valid_versions = []
221
223
for v in output .splitlines ():
@@ -242,7 +244,9 @@ def find_next_version(base_branch: str) -> str:
242
244
msg += "\n " .join (f"* `{ x .name } `" for x in sorted (features + breaking ))
243
245
raise InvalidFeatureRelease (msg )
244
246
245
- if is_feature_release :
247
+ if is_major :
248
+ return f"{ last_version [0 ]+ 1 } .0.0"
249
+ elif is_feature_release :
246
250
return f"{ last_version [0 ]} .{ last_version [1 ] + 1 } .0"
247
251
else :
248
252
return f"{ last_version [0 ]} .{ last_version [1 ]} .{ last_version [2 ] + 1 } "
0 commit comments