diff --git a/bob/devtools/release.py b/bob/devtools/release.py index d0b780f119a008986f693a8649e4042f5edf98fb..be87b1b578dfa77cbdd194e4a98ddaf1c53326a4 100644 --- a/bob/devtools/release.py +++ b/bob/devtools/release.py @@ -28,16 +28,6 @@ def get_gitlab_instance(): return gl -def ensure_correct_package(candidates, group_name, pkg_name): - - for pkg in candidates: - # make sure the name and the group name match exactly - if pkg.name == pkg_name and pkg.namespace['name'] == group_name: - return pkg - - raise ValueError('Package "{0}" was not found inside group "{1}"'.format(pkg_name, group_name)) - - def _update_readme(readme, version): """ Inside text of the readme, replaces parts of the links to the provided @@ -130,7 +120,8 @@ def get_parsed_tag(gitpkg, tag): m = re.match(r"(\d.\d.\d)", latest_tag_name) if not m: raise ValueError('The latest tag name {0} in package {1} has ' \ - 'unknown format'.format('v' + latest_tag_name, gitpkg.name)) + 'unknown format'.format('v' + latest_tag_name, + gitpkg.attributes['path_with_namespace'])) # increase the version accordingly major, minor, patch = latest_tag_name.split('.') @@ -153,7 +144,7 @@ def get_parsed_tag(gitpkg, tag): return tag raise ValueError('Cannot parse changelog tag {0} of the ' \ - 'package {1}'.format(tag, gitpkg.name)) + 'package {1}'.format(tag, gitpkg.attributes['path_with_namespace'])) def update_tag_comments(gitpkg, tag_name, tag_comments_list, dry_run=False): @@ -203,7 +194,7 @@ def commit_files(gitpkg, files_dict, message='Updated files', dry_run=False): update_action['content'] = files_dict[filename] data['actions'].append(update_action) - logger.info("Committing changes in files: %s", str(files_dict.keys())) + logger.debug("Committing changes in files: %s", ', '.join(files_dict.keys())) if not dry_run: gitpkg.commits.create(data) @@ -270,8 +261,9 @@ def wait_for_pipeline_to_finish(gitpkg, pipeline_id, dry_run=False): max_sleep = 120 * 60 # two hours # pipeline = get_last_pipeline(gitpkg, before_last=before_last) - logger.info('Waiting for the pipeline %s of package %s to finish. ' \ - 'Do not interrupt.', pipeline_id, gitpkg.name) + logger.warn('Waiting for the pipeline %s of "%s" to finish', + pipeline_id, gitpkg.attributes['path_with_namespace']) + logger.warn('Do **NOT** interrupt!') if dry_run: return @@ -295,10 +287,11 @@ def wait_for_pipeline_to_finish(gitpkg, pipeline_id, dry_run=False): if pipeline.status != 'success': raise ValueError('Pipeline {0} of project {1} exited with ' \ 'undesired status "{2}". Release is not possible.' \ - .format(pipeline_id, gitpkg.name, pipeline.status)) + .format(pipeline_id, gitpkg.attributes['path_with_namespace'], + pipeline.status)) logger.info('Pipeline %s of package %s SUCCEEDED. Continue processing.', - pipeline_id, gitpkg.name) + pipeline_id, gitpkg.attributes['path_with_namespace']) def cancel_last_pipeline(gitpkg): @@ -312,7 +305,7 @@ def cancel_last_pipeline(gitpkg): pipeline = get_last_pipeline(gitpkg) logger.info('Cancelling the last pipeline %s of project %s', pipeline.id, - gitpkg.name) + gitpkg.attributes['path_with_namespace']) pipeline.cancel() @@ -359,9 +352,9 @@ def release_package(gitpkg, tag_name, tag_comments_list, dry_run=False): cancel_last_pipeline(gitpkg) # 2. Tag package with new tag and push - logger.info("Creating tag %s", tag_name) + logger.info('Tagging "%s"', tag_name) tag_comments = '\n'.join(tag_comments_list) - logger.info("Updating tag comments with:\n%s", tag_comments) + logger.debug("Updating tag comments with:\n%s", tag_comments) if not dry_run: tag = gitpkg.tags.create({'tag_name': tag_name, 'ref': 'master'}) # update tag with comments @@ -385,7 +378,7 @@ def release_package(gitpkg, tag_name, tag_comments_list, dry_run=False): return running_pipeline.id -def parse_and_process_package_changelog(gl, bob_group, pkg_name, +def parse_and_process_package_changelog(gl, gitpkg, package_changelog, dry_run): """Process the changelog of a single package @@ -396,12 +389,11 @@ def parse_and_process_package_changelog(gl, bob_group, pkg_name, Args: gl: Gitlab API object - bob_group: gitlab object for the group - pkg_name: name of the package + gitpkg: gitlab package object package_changelog: the changelog corresponding to the provided package dry_run: If True, nothing will be committed or pushed to GitLab - Returns: gitlab handle for the package, name of the latest tag, and tag's + Returns: the name of the latest tag, and tag's comments """ @@ -409,12 +401,6 @@ def parse_and_process_package_changelog(gl, bob_group, pkg_name, cur_tag = None cur_tag_comments = [] - grpkg = ensure_correct_package(bob_group.projects.list(search=pkg_name), - bob_group.name, pkg_name) - - # so, we need to retrieve the full info from GitLab using correct project id - gitpkg = gl.projects.get(id=grpkg.id) - # we assume that changelog is formatted as structured text # first line is the name of the package for line in package_changelog: @@ -431,7 +417,7 @@ def parse_and_process_package_changelog(gl, bob_group, pkg_name, cur_tag_comments.append(line.strip()) # return the last tag and comments for release - return gitpkg, cur_tag, cur_tag_comments + return cur_tag, cur_tag_comments def release_bob(changelog_file): diff --git a/bob/devtools/scripts/release.py b/bob/devtools/scripts/release.py index c6816744d80fa54194ad07914c58c86fa7fbd8e3..057be1b12744ac0a887615364c251ce216ba0cf0 100644 --- a/bob/devtools/scripts/release.py +++ b/bob/devtools/scripts/release.py @@ -3,6 +3,7 @@ import os + import logging logger = logging.getLogger(__name__) @@ -43,7 +44,7 @@ Examples: $ bdt release --dry-run changelog_since_last_release.md ''' ) -@click.argument('changelog', type=click.File('rb', lazy=False)) +@click.argument('changelog', type=click.File('rt', lazy=False)) @click.option('-g', '--group', default='bob', show_default=True, help='Group name where all packages are located') @click.option('-p', '--package', @@ -125,8 +126,6 @@ def release(changelog, group, package, resume, dry_run): gl = get_gitlab_instance() - use_group = gl.groups.list(search='"%s"' % group)[0] - # if we are releasing 'bob' metapackage, it's a simple thing, no GitLab # API if package == 'bob': @@ -139,7 +138,7 @@ def release(changelog, group, package, resume, dry_run): changelogs = changelog.readlines() # find the starts of each package's description in the changelog - pkgs = [i for i, line in enumerate(changelogs) if line[0] == '*'] + pkgs = [i for i, line in enumerate(changelogs) if line.startswith('*')] pkgs.append(len(changelogs)) #the end start_idx = 0 @@ -163,22 +162,31 @@ def release(changelog, group, package, resume, dry_run): # go through the list of packages and release them starting from the # start_idx for i in range(start_idx, len(pkgs) - 1): + cur_package_name = changelogs[pkgs[i]][1:].strip() - logger.info('Processing package %s', changelogs[pkgs[i]]) - gitpkg, tag, tag_comments = parse_and_process_package_changelog(gl, - use_group, cur_package_name, - changelogs[pkgs[i] + 1: pkgs[i + 1]], dry_run) + + if '/' not in cur_package_name: + cur_package_name = '/'.join((group, cur_package_name)) + + # retrieves the gitlab package object + use_package = gl.projects.get(cur_package_name) + logger.info('Processing %s (gitlab id=%d)', + use_package.attributes['path_with_namespace'], use_package.id) + + tag, tag_comments = parse_and_process_package_changelog(gl, + use_package, changelogs[pkgs[i] + 1: pkgs[i + 1]], dry_run) # release the package with the found tag and its comments - if gitpkg: - pipeline_id = release_package(gitpkg, tag, tag_comments, dry_run) + if use_package: + pipeline_id = release_package(use_package, tag, tag_comments, + dry_run) # now, wait for the pipeline to finish, before we can release the # next package - wait_for_pipeline_to_finish(gitpkg, pipeline_id, dry_run) + wait_for_pipeline_to_finish(use_package, pipeline_id, dry_run) # if package name is provided and resume is not set, process only # this package if package == cur_package_name and not resume: break - logger.info('Finished processing %s', changelog) + logger.info('Finished processing %s', changelog.name)