From 4620f23d9b14f5ec6138b6e645a108eb3d2b3ff5 Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Tue, 27 Aug 2024 18:46:20 +0300 Subject: [PATCH 1/8] add script for version bump --- catalog_reader/scripts/bump_version.py | 56 ++++++++++++++++++++++++++ setup.py | 1 + 2 files changed, 57 insertions(+) create mode 100644 catalog_reader/scripts/bump_version.py diff --git a/catalog_reader/scripts/bump_version.py b/catalog_reader/scripts/bump_version.py new file mode 100644 index 0000000..d7dbe47 --- /dev/null +++ b/catalog_reader/scripts/bump_version.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +import argparse +import os +import pathlib +import yaml + +from apps_exceptions import AppDoesNotExist, ValidationErrors +from catalog_reader.version_bump import is_valid_bump_type, bump_version, rename_versioned_dir + + +def update_app_version(app_path: str, bump_type: str) -> None: + if not os.path.exists(app_path): + raise AppDoesNotExist(app_path) + + verrors = ValidationErrors() + app_dir = pathlib.Path(app_path) + app_metadata_file = app_dir / 'app.yaml' + if not app_metadata_file.is_file(): + verrors.add('app_metadata', 'app.yaml file is missing') + + verrors.check() + + with open(str(app_metadata_file), 'r') as f: + app_config = yaml.safe_load(f.read()) + + if not is_valid_bump_type(bump_type): + verrors.add('app_metadata', f'Invalid bump type {bump_type!r}') + + verrors.check() + + old_version = app_config["version"] + app_config["version"] = bump_version(old_version, bump_type) + rename_versioned_dir(old_version, app_config['version'], app_dir.parent.name, app_dir) + + with open(str(app_metadata_file), 'w') as f: + f.write(yaml.safe_dump(app_config)) + + print( + f'[\033[92mOK\x1B[0m]\tUpdated app {app_dir.name!r} version from {old_version!r} to {app_config["version"]!r}' + ) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--path', help='Specify path of the app to be updated') + parser.add_argument('--bump', help='Bump type for app that the hash was updated') + + args = parser.parse_args() + if not args.path or not args.bump: + parser.print_help() + else: + update_app_version(args.path, args.bump) + + +if __name__ == '__main__': + main() diff --git a/setup.py b/setup.py index 2aafcf5..646e8b5 100644 --- a/setup.py +++ b/setup.py @@ -27,6 +27,7 @@ entry_points={ 'console_scripts': [ 'apps_catalog_hash_generate = catalog_reader.scripts.apps_hashes:main', + 'apps_catalog_bump_version = catalog_reader.scripts.bump_version:main', 'apps_catalog_update = apps_ci.scripts.catalog_update:main', 'apps_catalog_validate = apps_validation.scripts.catalog_validate:main', 'apps_dev_charts_validate = apps_validation.scripts.dev_apps_validate:main', # TODO: Remove apps_prefix From 172e57c60af95669757793aa4af851f7f7986d59 Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Tue, 27 Aug 2024 19:22:56 +0300 Subject: [PATCH 2/8] map bump types --- apps_ci/version_bump.py | 12 ++++++++++++ catalog_reader/scripts/bump_version.py | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/apps_ci/version_bump.py b/apps_ci/version_bump.py index 5fc790b..a699439 100644 --- a/apps_ci/version_bump.py +++ b/apps_ci/version_bump.py @@ -3,6 +3,18 @@ from apps_exceptions import AppDoesNotExist, ValidationErrors +def map_renovate_bump_type(bump: str) -> str: + if bump in ('patch', 'minor', 'major'): + return bump + + if bump in ('digest', 'pin', 'pinDigest'): + return 'patch' + + # There are few other types, but we should not proceed with them. + # For example: rollback, replacement + raise ValueError(f'Invalid bump type {bump!r}') + + def is_valid_version(version: str) -> bool: return isinstance(version, str) and version.count('.') == 2 diff --git a/catalog_reader/scripts/bump_version.py b/catalog_reader/scripts/bump_version.py index d7dbe47..dd66d15 100644 --- a/catalog_reader/scripts/bump_version.py +++ b/catalog_reader/scripts/bump_version.py @@ -5,7 +5,7 @@ import yaml from apps_exceptions import AppDoesNotExist, ValidationErrors -from catalog_reader.version_bump import is_valid_bump_type, bump_version, rename_versioned_dir +from catalog_reader.version_bump import is_valid_bump_type, map_renovate_bump_type, bump_version, rename_versioned_dir def update_app_version(app_path: str, bump_type: str) -> None: @@ -23,6 +23,7 @@ def update_app_version(app_path: str, bump_type: str) -> None: with open(str(app_metadata_file), 'r') as f: app_config = yaml.safe_load(f.read()) + bump_type = map_renovate_bump_type(bump_type) if not is_valid_bump_type(bump_type): verrors.add('app_metadata', f'Invalid bump type {bump_type!r}') From 75b4e7b59b2581252ef4f924ef660fe236fa9f07 Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Wed, 28 Aug 2024 16:56:51 +0300 Subject: [PATCH 3/8] update import --- {catalog_reader => apps_ci}/scripts/bump_version.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename {catalog_reader => apps_ci}/scripts/bump_version.py (93%) diff --git a/catalog_reader/scripts/bump_version.py b/apps_ci/scripts/bump_version.py similarity index 93% rename from catalog_reader/scripts/bump_version.py rename to apps_ci/scripts/bump_version.py index dd66d15..37f5b05 100644 --- a/catalog_reader/scripts/bump_version.py +++ b/apps_ci/scripts/bump_version.py @@ -5,7 +5,7 @@ import yaml from apps_exceptions import AppDoesNotExist, ValidationErrors -from catalog_reader.version_bump import is_valid_bump_type, map_renovate_bump_type, bump_version, rename_versioned_dir +from apps_ci.version_bump import is_valid_bump_type, map_renovate_bump_type, bump_version, rename_versioned_dir def update_app_version(app_path: str, bump_type: str) -> None: diff --git a/setup.py b/setup.py index 646e8b5..f852e5f 100644 --- a/setup.py +++ b/setup.py @@ -26,8 +26,8 @@ platforms='any', entry_points={ 'console_scripts': [ + 'app_bump_version = apps_ci.scripts.bump_version:main', 'apps_catalog_hash_generate = catalog_reader.scripts.apps_hashes:main', - 'apps_catalog_bump_version = catalog_reader.scripts.bump_version:main', 'apps_catalog_update = apps_ci.scripts.catalog_update:main', 'apps_catalog_validate = apps_validation.scripts.catalog_validate:main', 'apps_dev_charts_validate = apps_validation.scripts.dev_apps_validate:main', # TODO: Remove apps_prefix From c657dd6ec80c97994e702f48008da3a773f0b323 Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Wed, 28 Aug 2024 17:08:36 +0300 Subject: [PATCH 4/8] use single quote when possible --- 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 37f5b05..6666a21 100644 --- a/apps_ci/scripts/bump_version.py +++ b/apps_ci/scripts/bump_version.py @@ -29,8 +29,8 @@ def update_app_version(app_path: str, bump_type: str) -> None: verrors.check() - old_version = app_config["version"] - app_config["version"] = bump_version(old_version, bump_type) + old_version = app_config['version'] + app_config['version'] = bump_version(old_version, bump_type) rename_versioned_dir(old_version, app_config['version'], app_dir.parent.name, app_dir) with open(str(app_metadata_file), 'w') as f: From 55a3ec68566ac55fbb5621d7742e39972920f7ee Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Wed, 28 Aug 2024 17:39:42 +0300 Subject: [PATCH 5/8] update usage --- apps_ci/scripts/bump_version.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/apps_ci/scripts/bump_version.py b/apps_ci/scripts/bump_version.py index 6666a21..ad59757 100644 --- a/apps_ci/scripts/bump_version.py +++ b/apps_ci/scripts/bump_version.py @@ -5,7 +5,7 @@ import yaml from apps_exceptions import AppDoesNotExist, ValidationErrors -from apps_ci.version_bump import is_valid_bump_type, map_renovate_bump_type, bump_version, rename_versioned_dir +from apps_ci.version_bump import map_renovate_bump_type, bump_version, rename_versioned_dir def update_app_version(app_path: str, bump_type: str) -> None: @@ -24,10 +24,6 @@ def update_app_version(app_path: str, bump_type: str) -> None: app_config = yaml.safe_load(f.read()) bump_type = map_renovate_bump_type(bump_type) - if not is_valid_bump_type(bump_type): - verrors.add('app_metadata', f'Invalid bump type {bump_type!r}') - - verrors.check() old_version = app_config['version'] app_config['version'] = bump_version(old_version, bump_type) From 70eaf941ea768d013c8bac1ee3c3ead838b34549 Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Wed, 28 Aug 2024 17:47:40 +0300 Subject: [PATCH 6/8] update script arg and mapping --- apps_ci/scripts/bump_version.py | 6 +++++- apps_ci/version_bump.py | 10 +--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/apps_ci/scripts/bump_version.py b/apps_ci/scripts/bump_version.py index ad59757..6bd5cdd 100644 --- a/apps_ci/scripts/bump_version.py +++ b/apps_ci/scripts/bump_version.py @@ -40,7 +40,11 @@ def update_app_version(app_path: str, bump_type: str) -> None: def main(): parser = argparse.ArgumentParser() parser.add_argument('--path', help='Specify path of the app to be updated') - parser.add_argument('--bump', help='Bump type for app that the hash was updated') + parser.add_argument( + # We allow more choices here, as "Renovate" has more update types. We still map them to the ones we need. + '--bump', nargs=1, type=str, choices=('major', 'minor', 'patch', 'digest', 'pin', 'pinDigest'), + required=False, help='Version bump type for app that the hash was updated' + ) args = parser.parse_args() if not args.path or not args.bump: diff --git a/apps_ci/version_bump.py b/apps_ci/version_bump.py index a699439..d2d2531 100644 --- a/apps_ci/version_bump.py +++ b/apps_ci/version_bump.py @@ -4,15 +4,7 @@ def map_renovate_bump_type(bump: str) -> str: - if bump in ('patch', 'minor', 'major'): - return bump - - if bump in ('digest', 'pin', 'pinDigest'): - return 'patch' - - # There are few other types, but we should not proceed with them. - # For example: rollback, replacement - raise ValueError(f'Invalid bump type {bump!r}') + return bump if bump in ('patch', 'minor', 'major') else 'patch' def is_valid_version(version: str) -> bool: From 7c2a269542a5938fde081c7703cd66bc87e1e77b Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Wed, 28 Aug 2024 18:45:28 +0300 Subject: [PATCH 7/8] use the map function directly in the arg --- apps_ci/scripts/bump_version.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/apps_ci/scripts/bump_version.py b/apps_ci/scripts/bump_version.py index 6bd5cdd..6a3953a 100644 --- a/apps_ci/scripts/bump_version.py +++ b/apps_ci/scripts/bump_version.py @@ -23,8 +23,6 @@ def update_app_version(app_path: str, bump_type: str) -> None: with open(str(app_metadata_file), 'r') as f: app_config = yaml.safe_load(f.read()) - bump_type = map_renovate_bump_type(bump_type) - old_version = app_config['version'] app_config['version'] = bump_version(old_version, bump_type) rename_versioned_dir(old_version, app_config['version'], app_dir.parent.name, app_dir) @@ -41,9 +39,8 @@ def main(): parser = argparse.ArgumentParser() parser.add_argument('--path', help='Specify path of the app to be updated') parser.add_argument( - # We allow more choices here, as "Renovate" has more update types. We still map them to the ones we need. - '--bump', nargs=1, type=str, choices=('major', 'minor', 'patch', 'digest', 'pin', 'pinDigest'), - required=False, help='Version bump type for app that the hash was updated' + '--bump', type=map_renovate_bump_type, + help='Version bump type for app that the hash was updated' ) args = parser.parse_args() From 1314a455c91025ba695f712942e0363e567612f7 Mon Sep 17 00:00:00 2001 From: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Date: Thu, 29 Aug 2024 19:35:12 +0300 Subject: [PATCH 8/8] update imports --- 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 6a3953a..bbfa056 100644 --- a/apps_ci/scripts/bump_version.py +++ b/apps_ci/scripts/bump_version.py @@ -4,8 +4,8 @@ import pathlib import yaml -from apps_exceptions import AppDoesNotExist, ValidationErrors 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: