1
1
#!/usr/bin/env python3
2
2
3
3
import argparse
4
+ import enum
4
5
import json
5
6
import logging
6
7
import platform
@@ -63,14 +64,10 @@ def extract_image_targets(makefile_dir: pathlib.Path | str = os.getcwd()) -> lis
63
64
return all_images
64
65
65
66
66
- def _str_to_bool (value : str ) -> bool :
67
- value = value .lower ()
68
- if value in ('true' , 't' , 'yes' , 'y' , '1' ):
69
- return True
70
- elif value in ('false' , 'f' , 'no' , 'n' , '0' ):
71
- return False
72
- else :
73
- raise ValueError (f"Invalid boolean string: '{ value } '" )
67
+ class RhelImages (enum .Enum ):
68
+ EXCLUDE = "exclude"
69
+ INCLUDE = "include"
70
+ INCLUDE_ONLY = "include-only"
74
71
75
72
76
73
def main () -> None :
@@ -81,8 +78,8 @@ def main() -> None:
81
78
help = "Git ref of the base branch (to determine changed files)" )
82
79
argparser .add_argument ("--to-ref" , type = str , required = False ,
83
80
help = "Git ref of the PR branch (to determine changed files)" )
84
- argparser .add_argument ("--leave-out- rhel" , type = _str_to_bool , required = False , default = False , nargs = '?' ,
85
- help = "Does not output rhel-based images even when they have changed files " )
81
+ argparser .add_argument ("--rhel-images " , type = RhelImages , required = False , default = RhelImages . INCLUDE , nargs = '?' ,
82
+ help = "Whether to `include` rhel images or `exclude` them or `include-only` them " )
86
83
args = argparser .parse_args ()
87
84
88
85
targets = extract_image_targets ()
@@ -92,8 +89,14 @@ def main() -> None:
92
89
changed_files = gha_pr_changed_files .list_changed_files (args .from_ref , args .to_ref )
93
90
targets = gha_pr_changed_files .filter_out_unchanged (targets , changed_files )
94
91
95
- if args .leave_out_rhel :
92
+ if args .rhel_images == RhelImages .INCLUDE :
93
+ pass
94
+ elif args .rhel_images == RhelImages .EXCLUDE :
96
95
targets = [target for target in targets if "rhel" not in target ]
96
+ elif args .rhel_images == RhelImages .INCLUDE_ONLY :
97
+ targets = [target for target in targets if "rhel" in target ]
98
+ else :
99
+ raise Exception (f"Unknown value for --rhel-images: { args .rhel_images } " )
97
100
98
101
# https://stackoverflow.com/questions/66025220/paired-values-in-github-actions-matrix
99
102
output = [
0 commit comments