Commit fd238ed2 authored by André Anjos's avatar André Anjos 💬
Browse files

Multiple fixes and better naming convention (see full log)

* Use the full package path with namespace everywhere
* Use better method to quickly find package at gitlab
* Pass the package around and avoid ensure_correct_package()
* Improve logging
parent 1fd283d8
Pipeline #25733 passed with stages
in 2 minutes and 40 seconds
......@@ -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 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,
'unknown format'.format('v' + latest_tag_name,
# 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,
'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)"Committing changes in files: %s", str(files_dict.keys()))
logger.debug("Committing changes in files: %s", ', '.join(files_dict.keys()))
if not dry_run:
......@@ -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)'Waiting for the pipeline %s of package %s to finish. ' \
'Do not interrupt.', pipeline_id,
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,, pipeline.status))
.format(pipeline_id, gitpkg.attributes['path_with_namespace'],
pipeline.status))'Pipeline %s of package %s SUCCEEDED. Continue processing.',
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)'Cancelling the last pipeline %s of project %s',,
......@@ -359,9 +352,9 @@ def release_package(gitpkg, tag_name, tag_comments_list, dry_run=False):
# 2. Tag package with new tag and push"Creating tag %s", tag_name)'Tagging "%s"', tag_name)
tag_comments = '\n'.join(tag_comments_list)"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):
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,
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
......@@ -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),, pkg_name)
# so, we need to retrieve the full info from GitLab using correct project id
gitpkg = gl.projects.get(
# 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,
# 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):
......@@ -3,6 +3,7 @@
import os
import logging
logger = logging.getLogger(__name__)
......@@ -43,7 +44,7 @@ Examples:
$ bdt release --dry-run
@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
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()'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)'Processing %s (gitlab id=%d)',
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,
# 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'Finished processing %s', changelog)'Finished processing %s',
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment