1111import argparse
1212import re
1313import os
14+ import sys
1415import tomllib
16+ import typing as t
1517from pathlib import Path
1618
1719import yaml
2325Z_CHANGELOG_EXTS = [".bugfix" , ".misc" ]
2426
2527
26- def options ():
28+ def options () -> argparse . Namespace :
2729 """Check which branches need a release."""
2830 parser = argparse .ArgumentParser ()
2931 parser .add_argument (
@@ -42,13 +44,13 @@ def options():
4244 return parser .parse_args ()
4345
4446
45- def template_config ():
47+ def template_config () -> dict [ str , t . Any ] :
4648 # Assume this script lies in .ci/scripts
4749 path = Path (__file__ ).absolute ().parent .parent .parent / "template_config.yml"
4850 return yaml .safe_load (path .read_text ())
4951
5052
51- def current_version (repo , commitish ) :
53+ def current_version (repo : Repo , commitish : str ) -> Version :
5254 try :
5355 pyproject_toml = tomllib .loads (repo .git .show (f"{ commitish } :pyproject.toml" ))
5456 try :
@@ -62,7 +64,7 @@ def current_version(repo, commitish):
6264 return Version (current_version )
6365
6466
65- def check_pyproject_dependencies (repo , from_commit , to_commit ) :
67+ def check_pyproject_dependencies (repo : Repo , from_commit : str , to_commit : str ) -> list [ str ] :
6668 try :
6769 new_pyproject = tomllib .loads (repo .git .show (f"{ to_commit } :pyproject.toml" ))
6870 try :
@@ -83,8 +85,8 @@ def check_pyproject_dependencies(repo, from_commit, to_commit):
8385 return ["pyproject.toml changed somehow (PLEASE check if dependencies are affected)." ]
8486
8587
86- def main (options , template_config ) :
87- DEFAULT_BRANCH = template_config ["plugin_default_branch" ]
88+ def main (options : argparse . Namespace , template_config : dict [ str , t . Any ]) -> int :
89+ DEFAULT_BRANCH : str = template_config ["plugin_default_branch" ]
8890
8991 repo = Repo ()
9092
@@ -97,7 +99,7 @@ def main(options, template_config):
9799
98100 # Warning: This will not work if branch names contain "/" but we don't really care here.
99101 heads = [h .split ("/" )[- 1 ] for h in repo .git .branch ("--remote" ).split ("\n " )]
100- available_branches = [h for h in heads if re .search (RELEASE_BRANCH_REGEX , h )]
102+ available_branches = [h for h in heads if re .fullmatch (RELEASE_BRANCH_REGEX , h )]
101103 available_branches .sort (key = lambda ver : Version (ver ))
102104 available_branches .append (DEFAULT_BRANCH )
103105
@@ -114,7 +116,10 @@ def main(options, template_config):
114116
115117 if diff := branches - set (available_branches ):
116118 print (f"Supplied branches contains non-existent branches! { diff } " )
117- exit (1 )
119+ return 1
120+
121+ branches = [branch for branch in available_branches if branch in branches ]
122+ branches .reverse ()
118123
119124 print (f"Checking for releases on branches: { branches } " )
120125
@@ -179,6 +184,8 @@ def main(options, template_config):
179184 if len (releases ) == 0 :
180185 print ("No new releases to perform." )
181186
187+ return 0
188+
182189
183190if __name__ == "__main__" :
184- main (options (), template_config ())
191+ sys . exit ( main (options (), template_config () ))
0 commit comments