diff --git a/apps_ci/images_info.py b/apps_ci/images_info.py new file mode 100644 index 0000000..e24a759 --- /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..88a4317 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', type=str, 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__':