2
0
mirror of https://github.com/frappe/bench.git synced 2025-01-09 08:30:39 +00:00

add branch switching commands and update release script

This commit is contained in:
Pratik Vyas 2015-03-17 08:58:49 +05:30
parent a379a97de3
commit b559572277
3 changed files with 55 additions and 17 deletions

View File

@ -136,6 +136,22 @@ def get_upstream_version(repo_dir):
raise
return get_version_from_string(contents)
def switch_branch(branch, apps=None, bench='.'):
apps_dir = os.path.join(bench, 'apps')
if not apps:
apps = ('frappe', 'erpnext', 'shopping_cart')
for app in apps:
app_dir = os.path.join(apps_dir, app)
if os.path.exists(app_dir):
exec_cmd("git fetch upstream", cwd=app_dir)
exec_cmd("git checkout {branch}".format(branch=branch), cwd=app_dir)
def switch_to_master(apps=None, bench='.'):
switch_branch('master', apps=apps, bench=bench)
def switch_to_v4(apps=None, bench='.'):
switch_branch('v4.x.x', apps=apps, bench=bench)
def get_version_from_string(contents):
match = re.search(r"^(\s*%s\s*=\s*['\\\"])(.+?)(['\"])(?sm)" % 'version',
contents)

View File

@ -17,7 +17,7 @@ from .utils import (build_assets, patch_sites, exec_cmd, update_bench, get_env_c
pre_upgrade)
from .app import get_app as _get_app
from .app import new_app as _new_app
from .app import pull_all_apps, get_apps, get_current_frappe_version, is_version_upgrade
from .app import pull_all_apps, get_apps, get_current_frappe_version, is_version_upgrade, switch_to_v4, switch_to_master
from .config import generate_nginx_config, generate_supervisor_config, generate_redis_config
from .production_setup import setup_production as _setup_production
from .migrate_to_v5 import migrate_to_v5
@ -222,6 +222,8 @@ def update(pull=False, patch=False, build=False, bench=False, auto=False, restar
print
print "This update will cause a major version change in Frappe/ERPNext from {0} to {1}.".format(*version_upgrade)
print "This would take significant time to migrate and might break custom apps. Please run `bench update --upgrade` to confirm."
print
print "You can also pin your bench to {0} by running `bench swtich-to-v{0}`".format(version_upgrade[0])
sys.exit(1)
elif not version_upgrade and upgrade:
upgrade = False
@ -280,6 +282,22 @@ def _migrate_to_v5(bench='.'):
if click.confirm("This is irreversible. Do you want to continue?", abort=True):
migrate_to_v5(bench=bench)
@click.command('switch-to-master')
def _switch_to_master():
"Switch frappe and erpnext to master branch"
switch_to_master()
print
print 'Switched to master'
print 'Please run `bench update --patch` to be safe from any differences in database schema'
@click.command('switch-to-v4')
def _switch_to_v4():
"Switch frappe and erpnext to v4 branch"
switch_to_v4()
print
print 'Switched to v4'
print 'Please run `bench update --patch` to be safe from any differences in database schema'
@click.command('set-nginx-port')
@click.argument('site')
@click.argument('port', type=int)
@ -342,11 +360,13 @@ def _prime_wheel_cache():
@click.command('release')
@click.argument('app', type=click.Choice(['frappe', 'erpnext', 'shopping_cart']))
@click.argument('bump-type', type=click.Choice(['major', 'minor', 'patch']))
def _release(app, bump_type):
@click.option('--develop', default='develop')
@click.option('--master', default='master')
def _release(app, bump_type, develop, master):
"Release app (internal to the Frappe team)"
from .release import release
repo = os.path.join('apps', app)
release(repo, bump_type)
release(repo, bump_type, develop, master)
## Setup
@click.group()
@ -527,6 +547,8 @@ bench.add_command(_set_ssl_certificate_key)
bench.add_command(_set_mariadb_host)
bench.add_command(set_default_site)
bench.add_command(migrate_3to4)
bench.add_command(_switch_to_master)
bench.add_command(_switch_to_v4)
bench.add_command(shell)
bench.add_command(_backup_all_sites)
bench.add_command(_backup_site)

View File

@ -34,10 +34,10 @@ def create_release(repo_path, version, remote='origin', develop_branch='develop'
g.merge(master_branch)
return tag_name
def push_release(repo_path):
def push_release(repo_path, develop_branch='develop', master_branch='master'):
repo = git.Repo(repo_path)
g = repo.git
print g.push('upstream', 'master:master', 'develop:develop', '--tags')
print g.push('upstream', '{master}:{master}'.format(master=master_branch), '{develop}:{develop}'.format(develop=develop_branch), '--tags')
def create_github_release(owner, repo, tag_name, log, gh_username=None, gh_password=None):
global github_username, github_password
@ -137,25 +137,25 @@ def get_current_version(repo):
contents)
return match.group(2)
def bump_repo(repo, bump_type):
update_branch(repo, 'master', remote='upstream')
update_branch(repo, 'develop', remote='upstream')
git.Repo(repo).git.checkout('develop')
current_version = get_current_version(repo)
new_version = get_bumped_version(current_version, bump_type)
set_version(repo, new_version)
return new_version
def bump_repo(repo, bump_type, develop='develop', master='master', remote='upstream'):
update_branch(repo, master, remote=remote)
update_branch(repo, develop, remote=remote)
git.Repo(repo).git.checkout(develop)
current_version = get_current_version(repo)
new_version = get_bumped_version(current_version, bump_type)
set_version(repo, new_version)
return new_version
def bump(repo, bump_type):
def bump(repo, bump_type, develop='develop', master='master', remote='upstream'):
assert bump_type in ['minor', 'major', 'patch']
new_version = bump_repo(repo, bump_type)
new_version = bump_repo(repo, bump_type, develop=develop, master=master, remote=remote)
commit_changes(repo, new_version)
tag_name = create_release(repo, new_version)
push_release(repo)
create_github_release('frappe', repo, tag_name, '')
print 'Released {tag} for {repo}'.format(tag=tag_name, repo=repo)
def release(repo, bump_type):
def release(repo, bump_type, develop, master):
if not get_config().get('release_bench'):
print 'bench not configured to release'
sys.exit(1)
@ -164,7 +164,7 @@ def release(repo, bump_type):
github_password = getpass.getpass()
r = requests.get('https://api.github.com/user', auth=HTTPBasicAuth(github_username, github_password))
r.raise_for_status()
bump(repo, bump_type)
bump(repo, bump_type, develop=develop, master=master)
if __name__ == "__main__":
main()