diff --git a/reana/config.py b/reana/config.py index 4f26000b..eb9a8e12 100644 --- a/reana/config.py +++ b/reana/config.py @@ -269,6 +269,9 @@ TIMEOUT = 900 """Maximum timeout to wait for results when running demo analyses in CI.""" +DOCKER_VERSION_FILE = "Dockerfile" +"""Docker version file.""" + HELM_VERSION_FILE = "Chart.yaml" """Helm package version file.""" diff --git a/reana/reana_dev/git.py b/reana/reana_dev/git.py index 0093627c..e5ad4f37 100644 --- a/reana/reana_dev/git.py +++ b/reana/reana_dev/git.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # This file is part of REANA. -# Copyright (C) 2020, 2021 CERN. +# Copyright (C) 2020, 2021, 2023, 2024 CERN. # # REANA is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. @@ -18,6 +18,7 @@ from reana.config import ( COMPONENTS_USING_SHARED_MODULE_COMMONS, COMPONENTS_USING_SHARED_MODULE_DB, + DOCKER_VERSION_FILE, GIT_DEFAULT_BASE_BRANCH, HELM_VERSION_FILE, JAVASCRIPT_VERSION_FILE, @@ -135,7 +136,9 @@ def git_create_release_branch(component: str, next_version: Optional[str]): if not next_version: # bump current version depending on whether it is semver2 or pep440 current_version = get_current_component_version_from_source_files(component) - if version_files.get(HELM_VERSION_FILE): + if version_files.get(DOCKER_VERSION_FILE): + next_version = bump_semver2_version(current_version) + elif version_files.get(HELM_VERSION_FILE): next_version = bump_semver2_version(current_version) elif version_files.get(PYTHON_VERSION_FILE): next_version = bump_pep440_version(current_version) @@ -146,7 +149,8 @@ def git_create_release_branch(component: str, next_version: Optional[str]): else: # provided next_version is always in pep440 version if ( - HELM_VERSION_FILE in version_files + DOCKER_VERSION_FILE in version_files + or HELM_VERSION_FILE in version_files or JAVASCRIPT_VERSION_FILE in version_files ): next_version = translate_pep440_to_semver2(next_version) diff --git a/reana/reana_dev/utils.py b/reana/reana_dev/utils.py index 5e0570e2..1ce74119 100644 --- a/reana/reana_dev/utils.py +++ b/reana/reana_dev/utils.py @@ -13,6 +13,7 @@ import importlib.util import json import os +import re import subprocess import sys from concurrent import futures @@ -28,6 +29,7 @@ CLUSTER_DEPLOYMENT_MODES, COMPONENTS_USING_SHARED_MODULE_COMMONS, COMPONENTS_USING_SHARED_MODULE_DB, + DOCKER_VERSION_FILE, GIT_DEFAULT_BASE_BRANCH, HELM_VERSION_FILE, JAVASCRIPT_VERSION_FILE, @@ -613,6 +615,7 @@ def get_component_version_files(component, abs_path=False) -> Dict[str, str]: """Get a dictionary with all component's version files.""" version_files = {} for file_ in [ + DOCKER_VERSION_FILE, HELM_VERSION_FILE, OPENAPI_VERSION_FILE, JAVASCRIPT_VERSION_FILE, @@ -651,7 +654,17 @@ def get_current_component_version_from_source_files( all_version_files = {version_file: all_version_files[version_file]} version = "" - if all_version_files.get(HELM_VERSION_FILE): + if all_version_files.get(DOCKER_VERSION_FILE): + with open(all_version_files.get(DOCKER_VERSION_FILE)) as f: + for line in f.readlines(): + match = re.match( + r'LABEL org.opencontainers.image.version="(.*?)"', line + ) + if match: + version = match.groups(1)[0] + break + + elif all_version_files.get(HELM_VERSION_FILE): with open(all_version_files.get(HELM_VERSION_FILE)) as f: chart_yaml = yaml.safe_load(f.read()) version = chart_yaml["version"] @@ -864,7 +877,11 @@ def bump_component_version( component, version_file=file_type ) - if file_type in [HELM_VERSION_FILE, JAVASCRIPT_VERSION_FILE]: + if file_type in [ + DOCKER_VERSION_FILE, + HELM_VERSION_FILE, + JAVASCRIPT_VERSION_FILE, + ]: new_version = ( translate_pep440_to_semver2(next_version) if next_version @@ -889,7 +906,9 @@ def bump_component_version( next_version_per_file_type[file_type] = new_version # depending on a component, return proper component version - if HELM_VERSION_FILE in next_version_per_file_type.keys(): + if DOCKER_VERSION_FILE in next_version_per_file_type.keys(): + return next_version_per_file_type[DOCKER_VERSION_FILE], updated_files + elif HELM_VERSION_FILE in next_version_per_file_type.keys(): return next_version_per_file_type[HELM_VERSION_FILE], updated_files elif JAVASCRIPT_VERSION_FILE in next_version_per_file_type: return next_version_per_file_type[JAVASCRIPT_VERSION_FILE], updated_files