Skip to content

Commit

Permalink
fix(release): handle release for multiple branches
Browse files Browse the repository at this point in the history
  • Loading branch information
sahil28297 committed Jul 19, 2019
1 parent d88a327 commit dd78011
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions bench/release.py
Expand Up @@ -15,13 +15,14 @@

branches_to_update = {
'develop': [],
'hotfix': ['develop']
'version-11-hotfix': [],
'version-12-hotfix': [],
}

github_username = None
github_password = None

def release(bench_path, app, bump_type, from_branch='develop', to_branch='master',
def release(bench_path, app, bump_type, from_branch, to_branch,
remote='upstream', owner='frappe', repo_name=None, frontport=True):

confirm_testing()
Expand All @@ -30,7 +31,7 @@ def release(bench_path, app, bump_type, from_branch='develop', to_branch='master
if not config.get('release_bench'):
print('bench not configured to release')
sys.exit(1)


if config.get('branches_to_update'):
branches_to_update.update(config.get('branches_to_update'))
Expand Down Expand Up @@ -91,7 +92,7 @@ def bump(bench_path, app, bump_type, from_branch, to_branch, remote, owner, repo
create_github_release(repo_path, tag_name, message, remote=remote, owner=owner, repo_name=repo_name, prerelease=prerelease)
print('Released {tag} for {repo_path}'.format(tag=tag_name, repo_path=repo_path))

def update_branches_and_check_for_changelog(repo_path, from_branch='develop', to_branch='master', remote='upstream'):
def update_branches_and_check_for_changelog(repo_path, from_branch, to_branch, remote='upstream'):

update_branch(repo_path, to_branch, remote=remote)
update_branch(repo_path, from_branch, remote=remote)
Expand All @@ -116,7 +117,7 @@ def check_for_unmerged_changelog(repo_path):
if os.path.exists(current) and [f for f in os.listdir(current) if f != "readme.md"]:
raise Exception("Unmerged change log! in " + repo_path)

def get_release_message(repo_path, from_branch='develop', to_branch='master', remote='upstream'):
def get_release_message(repo_path, from_branch, to_branch, remote='upstream'):
print('getting release message for', repo_path, 'comparing', to_branch, '...', from_branch)

repo = git.Repo(repo_path)
Expand All @@ -127,7 +128,7 @@ def get_release_message(repo_path, from_branch='develop', to_branch='master', re
if log:
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, to_branch):
current_version = get_current_version(repo_path, to_branch)
new_version = get_bumped_version(current_version, bump_type)

Expand All @@ -140,7 +141,7 @@ def get_current_version(repo_path, to_branch):
# TODO clean this up!
version_key = '__version__'

if to_branch.lower() == 'master':
if to_branch.lower() in ['version-11', 'version-12']:
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')
Expand Down Expand Up @@ -194,7 +195,7 @@ def get_bumped_version(version, bump_type):
return str(v)

def set_version(repo_path, version, to_branch):
if to_branch.lower() == 'master':
if to_branch.lower() in ['version-11', 'version-12']:
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')
Expand Down Expand Up @@ -237,14 +238,14 @@ def commit_changes(repo_path, new_version, to_branch):
repo = git.Repo(repo_path)
app_name = os.path.basename(repo_path)

if to_branch.lower() == 'master':
if to_branch.lower() in ['version-11', 'version-12']:
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))

def create_release(repo_path, new_version, from_branch='develop', to_branch='master', frontport=True):
def create_release(repo_path, new_version, from_branch, to_branch, frontport=True):
print('creating release for version', new_version)
repo = git.Repo(repo_path)
g = repo.git
Expand Down Expand Up @@ -283,7 +284,7 @@ def handle_merge_error(e, source, target):
print('-'*80)
click.confirm('Have you manually resolved the error?', abort=True)

def push_release(repo_path, from_branch='develop', to_branch='master', remote='upstream'):
def push_release(repo_path, from_branch, to_branch, remote='upstream'):
print('pushing branches', to_branch, from_branch, 'of', repo_path)
repo = git.Repo(repo_path)
g = repo.git
Expand Down

0 comments on commit dd78011

Please sign in to comment.