diff --git a/reana/reana_dev/git.py b/reana/reana_dev/git.py index 4c023a52..fee41c3c 100644 --- a/reana/reana_dev/git.py +++ b/reana/reana_dev/git.py @@ -23,9 +23,11 @@ ) from reana.reana_dev.utils import ( display_message, + fetch_latest_pypi_version, get_srcdir, run_command, select_components, + update_module_in_cluster_components, ) @@ -724,95 +726,98 @@ def git_push(component): # noqa: D301 run_command(cmd, component) -@git_commands.command(name="git-shared-modules-upgrade") +@git_commands.command(name="git-upgrade-shared-modules") @click.option( - "--commit-and-publish", + "--component", + "-c", + multiple=True, + default=["CLUSTER", "CLIENT"], + help="Which components? [shortname|name|.|CLUSTER|ALL]", +) +@click.option( + "--use-latest-known-tag", + is_flag=True, + default=False, + help="Should the upgrade use the latest known tag of the shared modules?" + " If so, the latest known tag of the shared modules will be used to upgrade the" + " provided components. Else, the upgrade will only occur if the latest commit of the" + " shared modules points at a tag, in other case, the command will be aborted.", +) +@click.option( + "--amend", is_flag=True, default=False, - help="Should the changes be committed and pull requests created?" - " If so, a commit and a PR with" - ' "installation: shared packages version bump" message will' - " be created for all affected CLUSTER components.", + help="Should the changes be integrated as part of the latest commit of each component?.", ) -def git_shared_modules_upgrade(commit_and_publish): - """Upgrade all cluster components to latest REANA-Commons version.""" +@click.option( + "--push", + is_flag=True, + default=False, + help="Should the feature branches with the upgrades be pushed?.", +) +@click.pass_context +def git_upgrade_shared_modules( + ctx, component, use_latest_known_tag, amend, push +): # noqa: D301 + """Upgrade selected components to latest REANA-Commons/DB version. - def _fetch_latest_pypi_version(package): - """Fetch latest released version of a package.""" - import requests + \b + :param components: The option ``component`` can be repeated. The value may + consist of: + * (1) standard component name such as + 'reana-workflow-controller'; + * (2) short component name such as 'r-w-controller'; + * (3) special value '.' indicating component of the + current working directory; + * (4) special value 'CLUSTER' that will expand to + cover all REANA cluster components [default]; + * (5) special value 'CLIENT' that will expand to + cover all REANA client components; + * (6) special value 'DEMO' that will expand + to include several runable REANA demo examples; + * (7) special value 'ALL' that will expand to include + all REANA repositories. + :type component: str + """ - pypi_rc_info = requests.get( - "https://pypi.python.org/pypi/{}/json".format(package) - ) - return sorted(pypi_rc_info.json()["releases"].keys())[-1] - - def _update_module_in_cluster_components(module, new_version): - """Update the specified module version in all affected components.""" - components_to_update = { - "reana-commons": COMPONENTS_USING_SHARED_MODULE_COMMONS, - "reana-db": COMPONENTS_USING_SHARED_MODULE_DB, - } - for component in components_to_update[module]: - update_setup_py_dep_cmd = ( - 'LN=`cat setup.py | grep -n -e "{module}.*>=" | cut -f1 -d: `' - '&& sed -i.bk "`echo $LN`s/>=.*,={new_version},=.*,<", + replace=f">={new_version},<", + line_selector_regex=f"{module}.*>=", + component=component, + ) + if os.path.exists(get_srcdir(component) + os.sep + "requirements.txt"): + replace_string( + file_="requirements.txt", + find="==.*#", + replace=f"=={new_version}\t#", + line_selector_regex=f"{module}.*==", + component=component, + ) + + if components_to_update: + click.secho( + "✅ {module} updated to: {last_version}".format( + module=module, last_version=new_version + ), + bold=True, + fg="green", + )