From f15464c43cbb814acebd47aa5490962bb2e33a39 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Sirot Date: Fri, 9 Aug 2019 16:58:52 +0200 Subject: [PATCH 1/2] Split start command into 2 parts: init and TBD. init prepares the PR and pushed it to the repo. perform handles the rest of the release process Signed-off-by: Jean-Christophe Sirot --- script/release/release.py | 71 +++++++++++++++++++++++----- script/release/release/repository.py | 14 ++++++ script/release/setup-venv.sh | 2 +- 3 files changed, 75 insertions(+), 12 deletions(-) diff --git a/script/release/release.py b/script/release/release.py index a9c05eb7874..c4e599fcbd5 100755 --- a/script/release/release.py +++ b/script/release/release.py @@ -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') @@ -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, @@ -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, release_branch.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 " @@ -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) @@ -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) + pr_data = 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: @@ -298,6 +341,8 @@ def finalize(args): ACTIONS = [ + 'init', + 'perform', 'start', 'cancel', 'resume', @@ -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) diff --git a/script/release/release/repository.py b/script/release/release/repository.py index a0281eaa3d8..bb6b25846df 100644 --- a/script/release/release/repository.py +++ b/script/release/release/repository.py @@ -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 diff --git a/script/release/setup-venv.sh b/script/release/setup-venv.sh index ab419be0cdd..8c9de44e918 100755 --- a/script/release/setup-venv.sh +++ b/script/release/setup-venv.sh @@ -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 \ From 0667f6ddf73a5dd097438734dd325fed9995dae1 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Sirot Date: Tue, 27 Aug 2019 16:45:12 +0200 Subject: [PATCH 2/2] Fixing some lint errors Signed-off-by: Jean-Christophe Sirot --- script/release/release.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/release/release.py b/script/release/release.py index c4e599fcbd5..5aebabf82e6 100755 --- a/script/release/release.py +++ b/script/release/release.py @@ -132,7 +132,7 @@ def init_bintray_reppository(bintray_user, bintray_org, version): 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, release_branch.name, 'generic') + bintray_api.create_repository(bintray_org, repo_name, 'generic') else: print('Bintray repository {} already exists. Skipping'.format(repo_name)) @@ -243,7 +243,7 @@ def init(args): try: repository = Repository(REPO_ROOT, args.repo) create_initial_branch(repository, args) - pr_data = repository.create_release_pull_request(args.release) + repository.create_release_pull_request(args.release) except ScriptError as e: print(e) return 1