Skip to content

Commit 032d9ad

Browse files
committed
RHOAIENG-21668: chore(gha): fix handling of boolean argument in python's argparse
1 parent 0c761ce commit 032d9ad

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ci/cached-builds/gen_gha_matrix_jobs.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ def extract_image_targets(makefile_dir: pathlib.Path | str = os.getcwd()) -> lis
6363
return all_images
6464

6565

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}'")
74+
75+
6676
def main() -> None:
6777
logging.basicConfig(level=logging.DEBUG, stream=sys.stderr)
6878

@@ -71,7 +81,7 @@ def main() -> None:
7181
help="Git ref of the base branch (to determine changed files)")
7282
argparser.add_argument("--to-ref", type=str, required=False,
7383
help="Git ref of the PR branch (to determine changed files)")
74-
argparser.add_argument("--leave-out-rhel", type=bool, required=False, default=False, action=argparse.BooleanOptionalAction,
84+
argparser.add_argument("--leave-out-rhel", type=_str_to_bool, required=False, default=False, nargs='?',
7585
help="Does not output rhel-based images even when they have changed files")
7686
args = argparser.parse_args()
7787

0 commit comments

Comments
 (0)