From f8e2558b41b176272d94e3bc028a0020614171af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Vidal=20Garc=C3=ADa?= Date: Thu, 6 Aug 2020 15:41:31 +0200 Subject: [PATCH 1/2] cli: add git-upgrade-shared-modules command closes #365 --- reana/reana_dev/git.py | 139 +++++++++++++++++++++++++++++---------- reana/reana_dev/utils.py | 123 ++++++++++++++++++++++++++++++++++ 2 files changed, 226 insertions(+), 36 deletions(-) diff --git a/reana/reana_dev/git.py b/reana/reana_dev/git.py index 4c023a52..714fbe34 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,7 +726,7 @@ def git_push(component): # noqa: D301 run_command(cmd, component) -@git_commands.command(name="git-shared-modules-upgrade") +@git_commands.command(name="git-upgrade-all-shared-modules") @click.option( "--commit-and-publish", is_flag=True, @@ -734,33 +736,11 @@ def git_push(component): # noqa: D301 ' "installation: shared packages version bump" message will' " be created for all affected CLUSTER components.", ) -def git_shared_modules_upgrade(commit_and_publish): - """Upgrade all cluster components to latest REANA-Commons version.""" +def git_upgrade_all_shared_modules(commit_and_publish): + """Upgrade all cluster components to latest REANA-Commons/DB version. - def _fetch_latest_pypi_version(package): - """Fetch latest released version of a package.""" - import requests - - 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", + ) From 45fe7a6f1438dea964f7171121b333e4cf075093 Mon Sep 17 00:00:00 2001 From: Diego Rodriguez Date: Tue, 11 Aug 2020 10:51:45 +0200 Subject: [PATCH 2/2] cli: remove git_upgrade_all_shared_modules --- reana/reana_dev/git.py | 62 ------------------------------------------ 1 file changed, 62 deletions(-) diff --git a/reana/reana_dev/git.py b/reana/reana_dev/git.py index 714fbe34..fee41c3c 100644 --- a/reana/reana_dev/git.py +++ b/reana/reana_dev/git.py @@ -726,68 +726,6 @@ def git_push(component): # noqa: D301 run_command(cmd, component) -@git_commands.command(name="git-upgrade-all-shared-modules") -@click.option( - "--commit-and-publish", - 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.", -) -def git_upgrade_all_shared_modules(commit_and_publish): - """Upgrade all cluster components to latest REANA-Commons/DB version. - - Optionally create commits and PRs in all components bumping version. - """ - - def _commit_and_publish_version_bumps(components): - """Create commit and version bump PRs for all specified components.""" - for component in components: - has_changes = run_command( - "git status --porcelain --untracked-files=no | " - "grep setup.py || echo", - component=component, - return_output=True, - ) - if has_changes: - branch_name = datetime.datetime.now().strftime("version-bump-%Y%m%d") - create_branch = "git checkout -b {}".format(branch_name) - run_command(create_branch, component) - create_commit = ( - "git add setup.py && " - "git commit " - '-m "installation: shared packages version bump"' - ) - run_command(create_commit, component) - create_pr = "hub pull-request -p --no-edit && hub pr list -L 1" - run_command(create_pr, component) - else: - click.echo("{} has no changes, skipping.".format(component)) - - cluster_components_with_shared_modules = set( - COMPONENTS_USING_SHARED_MODULE_DB - ).union(set(COMPONENTS_USING_SHARED_MODULE_COMMONS)) - - for module in REPO_LIST_SHARED: - last_version = fetch_latest_pypi_version(module) - update_module_in_cluster_components(module, last_version) - - if commit_and_publish: - click.secho("Creating version bump commits and pull requests...") - _commit_and_publish_version_bumps(cluster_components_with_shared_modules) - click.secho( - "\nVersion bump commits and pull requests created ✨", bold=True, fg="green" - ) - click.secho( - "PR list 👉 https://github.com/search?q=" - "org%3Areanahub+is%3Apr+is%3Aopen&" - "unscoped_q=is%3Apr+is%3Aopen", - fg="green", - ) - - @git_commands.command(name="git-upgrade-shared-modules") @click.option( "--component",