Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extend bump version script #49

Merged
merged 5 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions apps_ci/images_info.py
Original file line number Diff line number Diff line change
@@ -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
9 changes: 7 additions & 2 deletions apps_ci/scripts/bump_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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:
Expand All @@ -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__':
Expand Down
Loading