Skip to content

Commit

Permalink
extend bump version script
Browse files Browse the repository at this point in the history
  • Loading branch information
stavros-k committed Aug 29, 2024
1 parent 8063cdb commit 3bc7b9d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
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', 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

0 comments on commit 3bc7b9d

Please sign in to comment.