Skip to content

Commit 646f49a

Browse files
remove the sed command
1 parent b8e54d9 commit 646f49a

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

.github/workflows/update_operator_images.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ jobs:
9494
python3 scripts/update_images.py \
9595
--images-file images.txt \
9696
--operator-repo-dir ./ \
97-
--create-new-file True
97+
--create-new-file True \
98+
--helm-chart-version "${{ inputs.helm_chart_version }}"
9899
99100
- name: Verify Generated Files
100101
run: |
@@ -125,9 +126,6 @@ jobs:
125126
tests/helm_install.sh
126127
chmod +x tests/helm_install.sh tests/replace_components_images.sh
127128
128-
- name: Update Helm Chart Version in Test Scripts
129-
run: sed -i "s/--version [0-9]\+\.[0-9]\+\.[0-9]\+/--version ${{ inputs.helm_chart_version }}/g" tests/helm_install.sh
130-
131129
- name: Update Helm Submodule
132130
run: |
133131
cd helm-charts/sumologic-kubernetes-collection

scripts/update_images.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424
HELM_INSTALL_SCRIPT_PATH = "tests/helm_install.sh"
2525
BASH_HEADER = "#!/usr/bin/env bash\n\n"
2626

27-
HELM_INSTALL_COMMAND_HEADER = """readonly ROOT_DIR="$(dirname "$(dirname "${0}")")"
28-
29-
helm upgrade --install test-openshift sumologic/sumologic \\
30-
--version 4.17.1 \\
31-
-n sumologic-system \\
32-
--create-namespace -f "${ROOT_DIR}/tests/values.yaml" \\\n"""
27+
def get_helm_install_command_header(helm_chart_version: str) -> str:
28+
"""Generate helm install command header with dynamic version.
29+
Args:
30+
helm_chart_version (str): Helm chart version to use
31+
Returns:
32+
str: Formatted helm install command header
33+
"""
34+
return f"""readonly ROOT_DIR="$(dirname "$(dirname "${{0}}")")"\n\nhelm upgrade --install test-openshift sumologic/sumologic \\\n --version {helm_chart_version} \\\n -n sumologic-system \\\n --create-namespace -f "${{ROOT_DIR}}/tests/values.yaml" \\\n"""
3335

3436
# COMPONENTS_CONFIG_MAP maps helm chart configuration keys into components names
3537
COMPONENTS_CONFIG_MAP = {
@@ -340,11 +342,13 @@ def prepare_components_images_map(file_path: str) -> dict:
340342
return components_images
341343

342344

343-
def update_helm_install(image_file_path: str, create_new_file: bool):
345+
def update_helm_install(image_file_path: str, create_new_file: bool, helm_chart_version: str):
344346
"""Updates helm install command in tests/helm_install.sh"
345347
346348
Args:
347-
file_path (str): path to the output of get_images_sha256.sh, see: https://github.com/SumoLogic/sumologic-openshift-images/blob/main/scripts/get_images_sha256.sh
349+
image_file_path (str): path to the output of get_images_sha256.sh, see: https://github.com/SumoLogic/sumologic-openshift-images/blob/main/scripts/get_images_sha256.sh
350+
create_new_file (bool): whether to create a new file or overwrite existing
351+
helm_chart_version (str): Helm chart version to use in the install command
348352
"""
349353
# pylint: disable=R0912,R0914
350354
image_config_keys = get_image_keys()
@@ -397,7 +401,8 @@ def update_helm_install(image_file_path: str, create_new_file: bool):
397401

398402
new_file_path = create_new_file_path(HELM_INSTALL_SCRIPT_PATH, create_new_file, ".sh")
399403
with open(new_file_path, "w", encoding="utf-8") as new_file:
400-
file_content = BASH_HEADER + HELM_INSTALL_COMMAND_HEADER + "\n".join(set_args)
404+
helm_install_header = get_helm_install_command_header(helm_chart_version)
405+
file_content = BASH_HEADER + helm_install_header + "\n".join(set_args)
401406
file_content = file_content.removesuffix(" \\") # remove last \ after last helm install argument
402407
new_file.write(f"{file_content}\n")
403408

@@ -420,6 +425,11 @@ def parse_args():
420425
help="determines whether new file should be created or the exiting file should be overwritten",
421426
default=True,
422427
)
428+
parser.add_argument(
429+
"--helm-chart-version",
430+
help="Helm chart version to use in the install command (e.g., 4.18.0)",
431+
required=True,
432+
)
423433
return parser.parse_args()
424434

425435

@@ -436,4 +446,4 @@ def parse_args():
436446

437447
update_replace_components_images(args.images_file, args.create_new_file)
438448

439-
update_helm_install(args.images_file, args.create_new_file)
449+
update_helm_install(args.images_file, args.create_new_file, args.helm_chart_version)

0 commit comments

Comments
 (0)