Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split release start command into 2 parts: init and perform #6849

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 60 additions & 11 deletions script/release/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ def create_initial_branch(repository, args):
cherries = input('Indicate (space-separated) PR numbers to cherry-pick then press Enter:\n')
repository.cherry_pick_prs(release_branch, cherries.split())

return create_bump_commit(repository, release_branch, args.bintray_user, args.bintray_org)
return create_bump_commit(repository, release_branch)


def create_bump_commit(repository, release_branch, bintray_user, bintray_org):
def create_bump_commit(repository, release_branch):
with release_branch.config_reader() as cfg:
release = cfg.get('release')
print('Updating version info in __init__.py and run.sh')
Expand All @@ -58,19 +58,15 @@ def create_bump_commit(repository, release_branch, bintray_user, bintray_org):
repository.create_bump_commit(release_branch, release)
repository.push_branch_to_remote(release_branch)

bintray_api = BintrayAPI(os.environ['BINTRAY_TOKEN'], bintray_user)
if not bintray_api.repository_exists(bintray_org, release_branch.name):
print('Creating data repository {} on bintray'.format(release_branch.name))
bintray_api.create_repository(bintray_org, release_branch.name, 'generic')
else:
print('Bintray repository {} already exists. Skipping'.format(release_branch.name))


def monitor_pr_status(pr_data):
print('Waiting for CI to complete...')
last_commit = pr_data.get_commits().reversed[0]
while True:
status = last_commit.get_combined_status()
if status.total_count == 0:
print('Nothing to monitor, skipping.')
return True
if status.state == 'pending' or status.state == 'failure':
summary = {
'pending': 0,
Expand Down Expand Up @@ -131,6 +127,16 @@ def create_release_draft(repository, version, pr_data, files):
return gh_release


def init_bintray_reppository(bintray_user, bintray_org, version):
bintray_api = BintrayAPI(os.environ['BINTRAY_TOKEN'], bintray_user)
repo_name = branch_name(version)
if not bintray_api.repository_exists(bintray_org, repo_name):
print('Creating data repository {} on bintray'.format(repo_name))
bintray_api.create_repository(bintray_org, repo_name, 'generic')
else:
print('Bintray repository {} already exists. Skipping'.format(repo_name))


def print_final_instructions(args):
print(
"You're almost done! Please verify that everything is in order and "
Expand Down Expand Up @@ -191,7 +197,8 @@ def resume(args):
cherries = input('Indicate (space-separated) PR numbers to cherry-pick then press Enter:\n')
repository.cherry_pick_prs(release_branch, cherries.split())

create_bump_commit(repository, release_branch, args.bintray_user, args.bintray_org)
create_bump_commit(repository, release_branch)
init_bintray_reppository(args.bintray_user, args.bintray_org, args.release)
pr_data = repository.find_release_pr(args.release)
if not pr_data:
pr_data = repository.create_release_pull_request(args.release)
Expand Down Expand Up @@ -231,11 +238,47 @@ def cancel(args):
return 0


def init(args):
distclean()
try:
repository = Repository(REPO_ROOT, args.repo)
create_initial_branch(repository, args)
repository.create_release_pull_request(args.release)
except ScriptError as e:
print(e)
return 1

return 0


def perform(args):
distclean()
try:
init_bintray_reppository(args.bintray_user, args.bintray_org, args.release)
repository = Repository(REPO_ROOT, args.repo)
pr_data = repository.find_release_pull_request(args.release)
check_pr_mergeable(pr_data)
if not args.skip_ci:
monitor_pr_status(pr_data)
downloader = BinaryDownloader(args.destination)
files = downloader.download_all(args.release)
gh_release = create_release_draft(repository, args.release, pr_data, files)
upload_assets(gh_release, files)
img_manager = ImageManager(args.release)
img_manager.build_images(repository)
except ScriptError as e:
print(e)
return 1

return 0


def start(args):
distclean()
try:
repository = Repository(REPO_ROOT, args.repo)
create_initial_branch(repository, args)
init_bintray_reppository(args.bintray_user, args.bintray_org, args.release)
pr_data = repository.create_release_pull_request(args.release)
check_pr_mergeable(pr_data)
if not args.skip_ci:
Expand Down Expand Up @@ -298,6 +341,8 @@ def finalize(args):


ACTIONS = [
'init',
'perform',
'start',
'cancel',
'resume',
Expand Down Expand Up @@ -368,7 +413,11 @@ def main():
)
args = parser.parse_args()

if args.action == 'start':
if args.action == 'init':
return init(args)
elif args.action == 'perform':
return perform(args)
elif args.action == 'start':
return start(args)
elif args.action == 'resume':
return resume(args)
Expand Down
14 changes: 14 additions & 0 deletions script/release/release/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ def create_release_pull_request(self, version):
head=branch_name(version),
)

def find_release_pull_request(self, version):
pullRequests = self.gh_repo.get_pulls(
base='release',
)
if pullRequests.totalCount == 0:
raise ScriptError('Unable to find release pull requests.')
elif pullRequests.totalCount > 1:
raise ScriptError('Too many release pull requests are open.')
else:
pr = pullRequests[0]
if pr.head.ref != branch_name(version):
raise ScriptError('Unable to find release pull requests.')
return pr

def create_release(self, version, release_notes, **kwargs):
return self.gh_repo.create_git_release(
tag=version, name=version, message=release_notes, **kwargs
Expand Down
2 changes: 1 addition & 1 deletion script/release/setup-venv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if debian_based; then
fi

$VENV_PYTHONBIN -m pip install -U Jinja2==2.10 \
PyGithub==1.39 \
PyGithub==1.43 \
GitPython==2.1.9 \
requests==2.18.4 \
setuptools==40.6.2 \
Expand Down