11#!/usr/bin/env python3
22
33import argparse
4+ import enum
45import json
56import logging
67import platform
@@ -63,14 +64,10 @@ def extract_image_targets(makefile_dir: pathlib.Path | str = os.getcwd()) -> lis
6364 return all_images
6465
6566
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"
7471
7572
7673def main () -> None :
@@ -81,8 +78,8 @@ def main() -> None:
8178 help = "Git ref of the base branch (to determine changed files)" )
8279 argparser .add_argument ("--to-ref" , type = str , required = False ,
8380 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 " )
8683 args = argparser .parse_args ()
8784
8885 targets = extract_image_targets ()
@@ -92,8 +89,14 @@ def main() -> None:
9289 changed_files = gha_pr_changed_files .list_changed_files (args .from_ref , args .to_ref )
9390 targets = gha_pr_changed_files .filter_out_unchanged (targets , changed_files )
9491
95- if args .leave_out_rhel :
92+ if args .rhel_images == RhelImages .INCLUDE :
93+ pass
94+ elif args .rhel_images == RhelImages .EXCLUDE :
9695 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 } " )
97100
98101 # https://stackoverflow.com/questions/66025220/paired-values-in-github-actions-matrix
99102 output = [
0 commit comments