Skip to content

Commit a9e4e0f

Browse files
committed
RHOAIENG-21668: chore(gha): change boolean argument in python's argparse to enum
1 parent 032d9ad commit a9e4e0f

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

.github/workflows/build-notebooks-pr-rhel.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ jobs:
4949
python3 ci/cached-builds/gen_gha_matrix_jobs.py \
5050
--from-ref 'origin/${{ github.event.pull_request.base.ref }}' \
5151
--to-ref '${{ github.event.pull_request.head.ref }}' \
52+
--rhel-images include-only
5253
id: gen
5354
env:
5455
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/build-notebooks-pr.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
python3 ci/cached-builds/gen_gha_matrix_jobs.py \
3535
--from-ref 'origin/${{ github.event.pull_request.base.ref }}' \
3636
--to-ref '${{ github.event.pull_request.head.ref }}' \
37-
--leave-out-rhel '${{ github.event_name == 'pull_request' }}'
37+
--rhel-images exclude
3838
id: gen
3939
env:
4040
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

ci/cached-builds/gen_gha_matrix_jobs.py

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22

33
import argparse
4+
import enum
45
import json
56
import logging
67
import 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

7673
def 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

Comments
 (0)