mirror of
https://github.com/frappe/bench.git
synced 2024-11-14 09:14:04 +00:00
Merge pull request #701 from saurabh6790/multi-branch-release
Multi branch release
This commit is contained in:
commit
9062a75c15
@ -47,7 +47,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,
|
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,
|
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_beta_release)
|
||||||
bench_command.add_command(start)
|
bench_command.add_command(start)
|
||||||
bench_command.add_command(restart)
|
bench_command.add_command(restart)
|
||||||
bench_command.add_command(set_nginx_port)
|
bench_command.add_command(set_nginx_port)
|
||||||
@ -64,6 +64,7 @@ bench_command.add_command(release)
|
|||||||
bench_command.add_command(renew_lets_encrypt)
|
bench_command.add_command(renew_lets_encrypt)
|
||||||
bench_command.add_command(disable_production)
|
bench_command.add_command(disable_production)
|
||||||
bench_command.add_command(bench_src)
|
bench_command.add_command(bench_src)
|
||||||
|
bench_command.add_command(prepare_beta_release)
|
||||||
|
|
||||||
from bench.commands.setup import setup
|
from bench.commands.setup import setup
|
||||||
bench_command.add_command(setup)
|
bench_command.add_command(setup)
|
||||||
|
@ -135,6 +135,16 @@ 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,
|
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)
|
remote=remote, owner=owner, repo_name=repo_name)
|
||||||
|
|
||||||
|
|
||||||
|
@click.command('prepare-beta-release')
|
||||||
|
@click.argument('app')
|
||||||
|
@click.option('--owner', default='frappe')
|
||||||
|
def prepare_beta_release(app, owner):
|
||||||
|
"""Prepare major beta release from develop branch"""
|
||||||
|
from bench.prepare_beta_release import prepare_beta_release
|
||||||
|
prepare_beta_release(bench_path='.', app=app, owner=owner)
|
||||||
|
|
||||||
|
|
||||||
@click.command('disable-production')
|
@click.command('disable-production')
|
||||||
def disable_production():
|
def disable_production():
|
||||||
"""Disables production environment for the bench."""
|
"""Disables production environment for the bench."""
|
||||||
|
119
bench/prepare_beta_release.py
Normal file
119
bench/prepare_beta_release.py
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
#! env python
|
||||||
|
import os
|
||||||
|
import git
|
||||||
|
import click
|
||||||
|
from .config.common_site_config import get_config
|
||||||
|
import semantic_version
|
||||||
|
|
||||||
|
github_username = None
|
||||||
|
github_password = None
|
||||||
|
|
||||||
|
def prepare_beta_release(bench_path, app, owner='frappe', remote='upstream'):
|
||||||
|
from .release import get_release_message
|
||||||
|
|
||||||
|
beta_hotfix = ''
|
||||||
|
beta_master = click.prompt('Branch name for beta release', type=str)
|
||||||
|
|
||||||
|
if click.confirm("Do you want to setup hotfix for beta ?"):
|
||||||
|
beta_hotfix = click.prompt('Branch name for beta hotfix ({}_hotifx)'.format(beta_master), type=str)
|
||||||
|
|
||||||
|
validate(bench_path)
|
||||||
|
repo_path = os.path.join(bench_path, 'apps', app)
|
||||||
|
version = get_bummped_version(repo_path)
|
||||||
|
|
||||||
|
update_branch(repo_path, remote)
|
||||||
|
prepare_beta_master(repo_path, beta_master, version, remote)
|
||||||
|
|
||||||
|
if beta_hotfix:
|
||||||
|
prepare_beta_hotfix(repo_path, beta_hotfix, remote)
|
||||||
|
|
||||||
|
tag_name = merge_beta_release_to_develop(repo_path, beta_master, remote, version)
|
||||||
|
push_branches(repo_path, beta_master, beta_hotfix, remote)
|
||||||
|
create_github_release(repo_path, tag_name, '', owner, remote)
|
||||||
|
|
||||||
|
def validate(bench_path):
|
||||||
|
from .release import validate
|
||||||
|
|
||||||
|
config = get_config(bench_path)
|
||||||
|
validate(bench_path, config)
|
||||||
|
|
||||||
|
def get_bummped_version(repo_path):
|
||||||
|
from .release import get_current_version
|
||||||
|
current_version = get_current_version(repo_path, 'master')
|
||||||
|
|
||||||
|
v = semantic_version.Version(current_version)
|
||||||
|
|
||||||
|
if v.major:
|
||||||
|
v.major += 1
|
||||||
|
v.minor = 0
|
||||||
|
v.patch = 0
|
||||||
|
v.prerelease = None
|
||||||
|
|
||||||
|
return str(v)
|
||||||
|
|
||||||
|
|
||||||
|
def update_branch(repo_path, remote):
|
||||||
|
from .release import update_branch
|
||||||
|
update_branch(repo_path, 'develop', remote)
|
||||||
|
|
||||||
|
def prepare_beta_master(repo_path, beta_master, version, remote):
|
||||||
|
g = git.Repo(repo_path).git
|
||||||
|
g.checkout(b=beta_master)
|
||||||
|
|
||||||
|
set_beta_version(repo_path, version)
|
||||||
|
|
||||||
|
def set_beta_version(repo_path, version):
|
||||||
|
from .release import set_filename_version
|
||||||
|
set_filename_version(os.path.join(repo_path, os.path.basename(repo_path),'hooks.py'), version, 'staging_version')
|
||||||
|
|
||||||
|
repo = git.Repo(repo_path)
|
||||||
|
app_name = os.path.basename(repo_path)
|
||||||
|
repo.index.add([os.path.join(app_name, 'hooks.py')])
|
||||||
|
repo.index.commit('bumped to version {}'.format(version))
|
||||||
|
|
||||||
|
|
||||||
|
def prepare_beta_hotfix(repo_path, beta_hotfix, remote):
|
||||||
|
g = git.Repo(repo_path).git
|
||||||
|
g.checkout(b=beta_hotfix)
|
||||||
|
|
||||||
|
|
||||||
|
def merge_beta_release_to_develop(repo_path, beta_master, remote, version):
|
||||||
|
from .release import handle_merge_error
|
||||||
|
|
||||||
|
repo = git.Repo(repo_path)
|
||||||
|
g = repo.git
|
||||||
|
|
||||||
|
tag_name = 'v' + version
|
||||||
|
repo.create_tag(tag_name, message='Release {}'.format(version))
|
||||||
|
|
||||||
|
g.checkout('develop')
|
||||||
|
|
||||||
|
try:
|
||||||
|
g.merge(beta_master)
|
||||||
|
except git.exc.GitCommandError as e:
|
||||||
|
handle_merge_error(e, source=beta_master, target='develop')
|
||||||
|
|
||||||
|
return tag_name
|
||||||
|
|
||||||
|
def push_branches(repo_path, beta_master, beta_hotfix, remote):
|
||||||
|
repo = git.Repo(repo_path)
|
||||||
|
g = repo.git
|
||||||
|
|
||||||
|
args = [
|
||||||
|
'develop:develop',
|
||||||
|
'{beta_master}:{beta_master}'.format(beta_master=beta_master),
|
||||||
|
]
|
||||||
|
|
||||||
|
if beta_hotfix:
|
||||||
|
args.append('{beta_hotfix}:{beta_hotfix}'.format(beta_hotfix=beta_hotfix))
|
||||||
|
|
||||||
|
args.append('--tags')
|
||||||
|
|
||||||
|
print("Pushing branches")
|
||||||
|
print(g.push(remote, *args))
|
||||||
|
|
||||||
|
def create_github_release(repo_path, tag_name, message, owner, remote):
|
||||||
|
from .release import create_github_release
|
||||||
|
|
||||||
|
create_github_release(repo_path, tag_name, message, remote=remote, owner=owner,
|
||||||
|
repo_name=None, gh_username=github_username, gh_password=github_password)
|
@ -31,6 +31,10 @@ def release(bench_path, app, bump_type, from_branch='develop', to_branch='master
|
|||||||
print('bench not configured to release')
|
print('bench not configured to release')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
if config.get('branches_to_update'):
|
||||||
|
branches_to_update.update(config.get('branches_to_update'))
|
||||||
|
|
||||||
validate(bench_path, config)
|
validate(bench_path, config)
|
||||||
|
|
||||||
bump(bench_path, app, bump_type, from_branch=from_branch, to_branch=to_branch, owner=owner,
|
bump(bench_path, app, bump_type, from_branch=from_branch, to_branch=to_branch, owner=owner,
|
||||||
@ -80,7 +84,7 @@ def bump(bench_path, app, bump_type, from_branch, to_branch, remote, owner, repo
|
|||||||
click.confirm('Do you want to continue?', abort=True)
|
click.confirm('Do you want to continue?', abort=True)
|
||||||
|
|
||||||
new_version = bump_repo(repo_path, bump_type, from_branch=from_branch, to_branch=to_branch)
|
new_version = bump_repo(repo_path, bump_type, from_branch=from_branch, to_branch=to_branch)
|
||||||
commit_changes(repo_path, new_version)
|
commit_changes(repo_path, new_version, to_branch)
|
||||||
tag_name = create_release(repo_path, new_version, from_branch=from_branch, to_branch=to_branch)
|
tag_name = create_release(repo_path, new_version, from_branch=from_branch, to_branch=to_branch)
|
||||||
push_release(repo_path, from_branch=from_branch, to_branch=to_branch, remote=remote)
|
push_release(repo_path, from_branch=from_branch, to_branch=to_branch, remote=remote)
|
||||||
create_github_release(repo_path, tag_name, message, remote=remote, owner=owner, repo_name=repo_name)
|
create_github_release(repo_path, tag_name, message, remote=remote, owner=owner, repo_name=repo_name)
|
||||||
@ -123,20 +127,27 @@ def get_release_message(repo_path, from_branch='develop', to_branch='master', re
|
|||||||
return "* " + log.replace('\n', '\n* ')
|
return "* " + log.replace('\n', '\n* ')
|
||||||
|
|
||||||
def bump_repo(repo_path, bump_type, from_branch='develop', to_branch='master'):
|
def bump_repo(repo_path, bump_type, from_branch='develop', to_branch='master'):
|
||||||
current_version = get_current_version(repo_path)
|
current_version = get_current_version(repo_path, to_branch)
|
||||||
new_version = get_bumped_version(current_version, bump_type)
|
new_version = get_bumped_version(current_version, bump_type)
|
||||||
|
|
||||||
print('bumping version from', current_version, 'to', new_version)
|
print('bumping version from', current_version, 'to', new_version)
|
||||||
|
|
||||||
set_version(repo_path, new_version)
|
set_version(repo_path, new_version, to_branch)
|
||||||
return new_version
|
return new_version
|
||||||
|
|
||||||
def get_current_version(repo_path):
|
def get_current_version(repo_path, to_branch):
|
||||||
# TODO clean this up!
|
# TODO clean this up!
|
||||||
filename = os.path.join(repo_path, os.path.basename(repo_path), '__init__.py')
|
version_key = '__version__'
|
||||||
|
|
||||||
|
if to_branch.lower() == 'master':
|
||||||
|
filename = os.path.join(repo_path, os.path.basename(repo_path), '__init__.py')
|
||||||
|
else:
|
||||||
|
filename = os.path.join(repo_path, os.path.basename(repo_path), 'hooks.py')
|
||||||
|
version_key = 'staging_version'
|
||||||
|
|
||||||
with open(filename) as f:
|
with open(filename) as f:
|
||||||
contents = f.read()
|
contents = f.read()
|
||||||
match = re.search(r"^(\s*%s\s*=\s*['\\\"])(.+?)(['\"])(?sm)" % '__version__',
|
match = re.search(r"^(\s*%s\s*=\s*['\\\"])(.+?)(['\"])(?sm)" % version_key,
|
||||||
contents)
|
contents)
|
||||||
return match.group(2)
|
return match.group(2)
|
||||||
|
|
||||||
@ -173,8 +184,11 @@ def get_bumped_version(version, bump_type):
|
|||||||
|
|
||||||
return str(v)
|
return str(v)
|
||||||
|
|
||||||
def set_version(repo_path, version):
|
def set_version(repo_path, version, to_branch):
|
||||||
set_filename_version(os.path.join(repo_path, os.path.basename(repo_path),'__init__.py'), version, '__version__')
|
if to_branch.lower() == 'master':
|
||||||
|
set_filename_version(os.path.join(repo_path, os.path.basename(repo_path),'__init__.py'), version, '__version__')
|
||||||
|
else:
|
||||||
|
set_filename_version(os.path.join(repo_path, os.path.basename(repo_path),'hooks.py'), version, 'staging_version')
|
||||||
|
|
||||||
# TODO fix this
|
# TODO fix this
|
||||||
# set_setuppy_version(repo_path, version)
|
# set_setuppy_version(repo_path, version)
|
||||||
@ -208,12 +222,17 @@ def set_filename_version(filename, version_number, pattern):
|
|||||||
with open(filename, 'w') as f:
|
with open(filename, 'w') as f:
|
||||||
f.write(contents)
|
f.write(contents)
|
||||||
|
|
||||||
def commit_changes(repo_path, new_version):
|
def commit_changes(repo_path, new_version, to_branch):
|
||||||
print('committing version change to', repo_path)
|
print('committing version change to', repo_path)
|
||||||
|
|
||||||
repo = git.Repo(repo_path)
|
repo = git.Repo(repo_path)
|
||||||
app_name = os.path.basename(repo_path)
|
app_name = os.path.basename(repo_path)
|
||||||
repo.index.add([os.path.join(app_name, '__init__.py')])
|
|
||||||
|
if to_branch.lower() == 'master':
|
||||||
|
repo.index.add([os.path.join(app_name, '__init__.py')])
|
||||||
|
else:
|
||||||
|
repo.index.add([os.path.join(app_name, 'hooks.py')])
|
||||||
|
|
||||||
repo.index.commit('bumped to version {}'.format(new_version))
|
repo.index.commit('bumped to version {}'.format(new_version))
|
||||||
|
|
||||||
def create_release(repo_path, new_version, from_branch='develop', to_branch='master'):
|
def create_release(repo_path, new_version, from_branch='develop', to_branch='master'):
|
||||||
@ -236,7 +255,7 @@ def create_release(repo_path, new_version, from_branch='develop', to_branch='mas
|
|||||||
handle_merge_error(e, source=to_branch, target=from_branch)
|
handle_merge_error(e, source=to_branch, target=from_branch)
|
||||||
|
|
||||||
for branch in branches_to_update[from_branch]:
|
for branch in branches_to_update[from_branch]:
|
||||||
print('merging master into', branch)
|
print('merging {0} into'.format(to_branch), branch)
|
||||||
g.checkout(branch)
|
g.checkout(branch)
|
||||||
try:
|
try:
|
||||||
g.merge(to_branch)
|
g.merge(to_branch)
|
||||||
|
Loading…
Reference in New Issue
Block a user