From 9b99b1d34fe88ac6e22533a8888b5139ed6ebe0e Mon Sep 17 00:00:00 2001 From: Saurabh Date: Thu, 20 Jul 2017 16:11:02 +0530 Subject: [PATCH 1/2] command to staging branch from develop brach --- bench/commands/__init__.py | 3 +- bench/commands/utils.py | 7 ++++ bench/prepare_staging.py | 70 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100755 bench/prepare_staging.py diff --git a/bench/commands/__init__.py b/bench/commands/__init__.py index 1bf61806..683df339 100755 --- a/bench/commands/__init__.py +++ b/bench/commands/__init__.py @@ -38,7 +38,7 @@ bench_command.add_command(switch_to_develop) from bench.commands.utils import (start, restart, set_nginx_port, set_ssl_certificate, set_ssl_certificate_key, set_url_root, set_mariadb_host, set_default_site, download_translations, shell, backup_site, backup_all_sites, release, renew_lets_encrypt, - disable_production, bench_src) + disable_production, bench_src, prepare_staging) bench_command.add_command(start) bench_command.add_command(restart) bench_command.add_command(set_nginx_port) @@ -52,6 +52,7 @@ bench_command.add_command(shell) bench_command.add_command(backup_site) bench_command.add_command(backup_all_sites) bench_command.add_command(release) +bench_command.add_command(prepare_staging) bench_command.add_command(renew_lets_encrypt) bench_command.add_command(disable_production) bench_command.add_command(bench_src) diff --git a/bench/commands/utils.py b/bench/commands/utils.py index ef23bfd6..3a3202c4 100644 --- a/bench/commands/utils.py +++ b/bench/commands/utils.py @@ -130,6 +130,13 @@ def release(app, bump_type, from_branch, to_branch, owner, repo_name, remote): release(bench_path='.', app=app, bump_type=bump_type, from_branch=from_branch, to_branch=to_branch, remote=remote, owner=owner, repo_name=repo_name) +@click.command('prepare-staging') +@click.argument('app') +def prepare_staging(app): + """Prepare staging branch from develop branch""" + from bench.prepare_staging import prepare_staging + prepare_staging(bench_path='.', app=app) + @click.command('disable-production') def disable_production(): diff --git a/bench/prepare_staging.py b/bench/prepare_staging.py new file mode 100755 index 00000000..9b55eff0 --- /dev/null +++ b/bench/prepare_staging.py @@ -0,0 +1,70 @@ +#! env python +import os +import git +import click + +github_username = None +github_password = None + +def prepare_staging(bench_path, app, remote='upstream'): + from .release import get_release_message + validate(bench_path) + + repo_path = os.path.join(bench_path, 'apps', app) + update_branches(repo_path, remote) + message = get_release_message(repo_path, develop='develop', master='staging', remote=remote) + + if not message: + print('No commits to release') + return + + print() + print(message) + print() + + click.confirm('Do you want to continue?', abort=True) + + create_staging(repo_path) + push_commits(repo_path) + +def validate(bench_path): + from .release import validate + validate(bench_path) + +def update_branches(repo_path, remote): + from .release import update_branch + update_branch(repo_path, 'staging', remote) + update_branch(repo_path, 'develop', remote) + + git.Repo(repo_path).git.checkout('develop') + +def create_staging(repo_path, develop='develop'): + from .release import handle_merge_error + + print('creating staging from', develop) + repo = git.Repo(repo_path) + g = repo.git + g.checkout('staging') + try: + g.merge(develop, '--no-ff') + except git.exc.GitCommandError as e: + handle_merge_error(e, source=develop, target='staging') + + g.checkout(develop) + try: + g.merge('staging') + except git.exc.GitCommandError as e: + handle_merge_error(e, source='staging', target=develop) + +def push_commits(repo_path, remote='upstream'): + print('pushing staging branch of', repo_path) + + repo = git.Repo(repo_path) + g = repo.git + + args = [ + 'develop:develop', + 'staging:staging' + ] + + print(g.push(remote, *args)) From ce4a02b224e33921f37dfb9aca3dd9d36db1b825 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Tue, 25 Jul 2017 18:00:54 +0530 Subject: [PATCH 2/2] [fix] to make compatible with new release functionality --- bench/prepare_staging.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/bench/prepare_staging.py b/bench/prepare_staging.py index 9b55eff0..baa2a7c3 100755 --- a/bench/prepare_staging.py +++ b/bench/prepare_staging.py @@ -2,6 +2,7 @@ import os import git import click +from .config.common_site_config import get_config github_username = None github_password = None @@ -12,7 +13,7 @@ def prepare_staging(bench_path, app, remote='upstream'): repo_path = os.path.join(bench_path, 'apps', app) update_branches(repo_path, remote) - message = get_release_message(repo_path, develop='develop', master='staging', remote=remote) + message = get_release_message(repo_path, from_branch='develop', to_branch='staging', remote=remote) if not message: print('No commits to release') @@ -29,7 +30,9 @@ def prepare_staging(bench_path, app, remote='upstream'): def validate(bench_path): from .release import validate - validate(bench_path) + + config = get_config(bench_path) + validate(bench_path, config) def update_branches(repo_path, remote): from .release import update_branch @@ -38,23 +41,23 @@ def update_branches(repo_path, remote): git.Repo(repo_path).git.checkout('develop') -def create_staging(repo_path, develop='develop'): +def create_staging(repo_path, from_branch='develop'): from .release import handle_merge_error - print('creating staging from', develop) + print('creating staging from', from_branch) repo = git.Repo(repo_path) g = repo.git g.checkout('staging') try: - g.merge(develop, '--no-ff') + g.merge(from_branch, '--no-ff') except git.exc.GitCommandError as e: - handle_merge_error(e, source=develop, target='staging') + handle_merge_error(e, source=from_branch, target='staging') - g.checkout(develop) + g.checkout(from_branch) try: g.merge('staging') except git.exc.GitCommandError as e: - handle_merge_error(e, source='staging', target=develop) + handle_merge_error(e, source='staging', target=from_branch) def push_commits(repo_path, remote='upstream'): print('pushing staging branch of', repo_path)