From 3bc7b9d106603266ab24600b36cf783020b02eb7 Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Fri, 30 Aug 2024 00:20:37 +0300 Subject: [PATCH 1/5] extend bump version script --- apps_ci/images_info.py | 38 +++++++++++++++++++++++++++++++++ apps_ci/scripts/bump_version.py | 9 ++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 apps_ci/images_info.py diff --git a/apps_ci/images_info.py b/apps_ci/images_info.py new file mode 100644 index 0000000..c209fcf --- /dev/null +++ b/apps_ci/images_info.py @@ -0,0 +1,38 @@ +import yaml + +from pathlib import Path + +from apps_exceptions import AppDoesNotExist, ValidationErrors + + +""" +ix_values.yaml example: +"image" is the "main" container + +images: + image: + repository: some_repo + tag: some_tag + db_image: + repository: some_repo + tag: some_tag +""" + + +def is_main_dep(app_dir: Path, dep_name: str) -> bool: + if not app_dir.is_dir(): + raise AppDoesNotExist(app_dir) + if not dep_name: + return False + + verrors = ValidationErrors() + ix_values = app_dir / "ix_values.yaml" + if not ix_values.is_file(): + verrors.add("image_key", f"Missing ix_values.yaml file for {app_dir.name!r}") + verrors.check() + with open(ix_values, "r") as f: + ix_values_data = yaml.safe_load(f.read()) + if ix_values_data.get("images").get("image").get("repository") == dep_name: + return True + + return False diff --git a/apps_ci/scripts/bump_version.py b/apps_ci/scripts/bump_version.py index bbfa056..c4461f5 100644 --- a/apps_ci/scripts/bump_version.py +++ b/apps_ci/scripts/bump_version.py @@ -4,11 +4,12 @@ import pathlib import yaml +from apps_ci.images_info import is_main_dep from apps_ci.version_bump import map_renovate_bump_type, bump_version, rename_versioned_dir from apps_exceptions import AppDoesNotExist, ValidationErrors -def update_app_version(app_path: str, bump_type: str) -> None: +def update_app_version(app_path: str, bump_type: str, dep_name: str, dep_version: str) -> None: if not os.path.exists(app_path): raise AppDoesNotExist(app_path) @@ -25,6 +26,8 @@ def update_app_version(app_path: str, bump_type: str) -> None: old_version = app_config['version'] app_config['version'] = bump_version(old_version, bump_type) + if dep_name and dep_version and is_main_dep(app_dir, dep_name): + app_config['app_version'] = dep_version rename_versioned_dir(old_version, app_config['version'], app_dir.parent.name, app_dir) with open(str(app_metadata_file), 'w') as f: @@ -42,12 +45,14 @@ def main(): '--bump', type=map_renovate_bump_type, help='Version bump type for app that the hash was updated' ) + parser.add_argument('--dep_name', help='Name of the dependency') + parser.add_argument('--dep_version', help='Version of the dependency') args = parser.parse_args() if not args.path or not args.bump: parser.print_help() else: - update_app_version(args.path, args.bump) + update_app_version(args.path, args.bump, args.dep_name, args.dep_version) if __name__ == '__main__': From 8c849114aa6f0c23c4bd1220af217276904ff2e8 Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Fri, 30 Aug 2024 00:22:17 +0300 Subject: [PATCH 2/5] fix casing --- apps_ci/scripts/bump_version.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps_ci/scripts/bump_version.py b/apps_ci/scripts/bump_version.py index c4461f5..4a05075 100644 --- a/apps_ci/scripts/bump_version.py +++ b/apps_ci/scripts/bump_version.py @@ -45,8 +45,8 @@ def main(): '--bump', type=map_renovate_bump_type, help='Version bump type for app that the hash was updated' ) - parser.add_argument('--dep_name', help='Name of the dependency') - parser.add_argument('--dep_version', help='Version of the dependency') + parser.add_argument('--dep-name', help='Name of the dependency') + parser.add_argument('--dep-version', help='Version of the dependency') args = parser.parse_args() if not args.path or not args.bump: From a4a044f8dc81433b7f497a5f4c6d71b8d2c70c6b Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Fri, 30 Aug 2024 00:50:22 +0300 Subject: [PATCH 3/5] make sure version is treated as string --- apps_ci/scripts/bump_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps_ci/scripts/bump_version.py b/apps_ci/scripts/bump_version.py index 4a05075..88a4317 100644 --- a/apps_ci/scripts/bump_version.py +++ b/apps_ci/scripts/bump_version.py @@ -46,7 +46,7 @@ def main(): help='Version bump type for app that the hash was updated' ) parser.add_argument('--dep-name', help='Name of the dependency') - parser.add_argument('--dep-version', help='Version of the dependency') + parser.add_argument('--dep-version', type=str, help='Version of the dependency') args = parser.parse_args() if not args.path or not args.bump: From 449658013d3d38679d926b6ece43e562c93e2914 Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Fri, 30 Aug 2024 15:05:24 +0300 Subject: [PATCH 4/5] safelly drill down the dict, and use single quotes --- apps_ci/images_info.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps_ci/images_info.py b/apps_ci/images_info.py index c209fcf..857295e 100644 --- a/apps_ci/images_info.py +++ b/apps_ci/images_info.py @@ -7,7 +7,7 @@ """ ix_values.yaml example: -"image" is the "main" container +'image' is the 'main' container images: image: @@ -26,13 +26,13 @@ def is_main_dep(app_dir: Path, dep_name: str) -> bool: return False verrors = ValidationErrors() - ix_values = app_dir / "ix_values.yaml" + ix_values = app_dir / 'ix_values.yaml' if not ix_values.is_file(): - verrors.add("image_key", f"Missing ix_values.yaml file for {app_dir.name!r}") + verrors.add('image_key', f'Missing ix_values.yaml file for {app_dir.name!r}') verrors.check() - with open(ix_values, "r") as f: + with open(ix_values, 'r') as f: ix_values_data = yaml.safe_load(f.read()) - if ix_values_data.get("images").get("image").get("repository") == dep_name: + if ix_values_data.get('images', {}).get('image', {}).get('repository', '') == dep_name: return True return False From 8d9f74a74ad3848b95e409e61839449ba59faff0 Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Fri, 30 Aug 2024 15:06:01 +0300 Subject: [PATCH 5/5] remove redundant default value --- apps_ci/images_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps_ci/images_info.py b/apps_ci/images_info.py index 857295e..e24a759 100644 --- a/apps_ci/images_info.py +++ b/apps_ci/images_info.py @@ -32,7 +32,7 @@ def is_main_dep(app_dir: Path, dep_name: str) -> bool: verrors.check() with open(ix_values, 'r') as f: ix_values_data = yaml.safe_load(f.read()) - if ix_values_data.get('images', {}).get('image', {}).get('repository', '') == dep_name: + if ix_values_data.get('images', {}).get('image', {}).get('repository') == dep_name: return True return False