diff --git a/release/generate_changelog.py b/release/generate_changelog.py index bb6d45bc29692c6866396f70d2362eab2eee8cb1..6383729741c24227109b2a155df09ce1f905bc59 100755 --- a/release/generate_changelog.py +++ b/release/generate_changelog.py @@ -26,6 +26,10 @@ Options: mrs). To use tag annotations, use mode tags. If you use commits as mode, we use the text in commits to produce the change log. [default: mrs] + -s, --since=<date> The date in any Date format from, + which you want to generate the changelog. If 'None', + the Bob's last release date will be used. + [default: None] Examples: @@ -41,8 +45,12 @@ Examples: $ {0} --package=bob.package.xyz --mode=commits > changelog.md + 3. Generates the changelog for a single package looking at merge requests starting from a given date of January 1, 2016: - 3. Generates a complete list of changelogs for the whole of Bob (whatever is + $ {0} --package=bob.package.xyz --mode=mrs --since=2016-01-01 > changelog.md + + + 4. Generates a complete list of changelogs for the whole of Bob (whatever is registered in the file "order.txt" in the project "bob/bob.nightlies" $ {0} > changelog.md @@ -52,7 +60,8 @@ Examples: import os import sys import datetime - +import dateutil.parser +import pytz def _insure_correct_package(candidates, group_name, pkg_name): for pkg in candidates: @@ -75,10 +84,14 @@ def get_packages_list(gl, gl_group=None): # release date of last Bob release + 1 day -def bob_last_release(gl): - bobpkg = gl.projects.get(id=1535) # 1535 is id of 'bob' meta-package - last_bob_tag = bobpkg.tags.list()[0] # get the last tag - return last_bob_tag.commit['committed_date'] +def bob_last_release(gl, since=None): + if since is None: + bobpkg = gl.projects.get(id=1535) # 1535 is id of 'bob' meta-package + last_bob_tag = bobpkg.tags.list()[0] # get the last tag + return last_bob_tag.commit['committed_date'] + # if 'since' is provided, convert it in ISO format + fulldate = dateutil.parser.parse(since).replace(tzinfo=pytz.timezone("Europe/Zurich")) + return (fulldate + datetime.timedelta(milliseconds=500)).isoformat() def get_datetime_from_gitdate(gitdate): @@ -210,7 +223,7 @@ def print_tags_with_commits(pkg_name, gitpkg, since='2017-01-01T00:00:00Z', rele print_commits_range(pkg_name, leftover_commits) -def main(group_name, pkg_name="", packages_list='bob.nightlies', release_mode=None): +def main(group_name, pkg_name="", packages_list='bob.nightlies', release_mode=None, since=None): try: import gitlab @@ -229,7 +242,7 @@ def main(group_name, pkg_name="", packages_list='bob.nightlies', release_mode=No gl = gitlab.Gitlab(server, private_token=token, api_version=4) bob_group = gl.groups.list(search=group_name)[0] - last_release_date = bob_last_release(gl) + last_release_date = bob_last_release(gl, since) if release_mode == 'tags': visibility = ('public',) @@ -280,4 +293,5 @@ if __name__ == '__main__': pkg_name=arguments['--package'], packages_list=arguments['--list'], release_mode=arguments['--mode'], + since=arguments['--since'], ) diff --git a/release/release.py b/release/release.py index 6e86bf60403813e465b706907c0a898bcaa25707..b16f6b2629cd53ce979b563d57fef629cd294e1f 100755 --- a/release/release.py +++ b/release/release.py @@ -190,7 +190,7 @@ def get_parsed_tag(gitpkg, tag): The latest tag is either patch, minor, major, or none """ - m = re.search(r"(v\d.\d.\d)", tag) + m = re.search(r"(v\d+.\d+.\d+)", tag) if m: return m.group(0) # tag = Version(tag) @@ -237,6 +237,7 @@ def update_tag_comments(gitpkg, tag_name, tag_comments_list, dry_run=False): """ # get tag and update its description + print(tag_name) tag = gitpkg.tags.get(tag_name) print('Found tag {1}, updating its comments with:'.format(gitpkg.name, tag.name)) print(tag_comments_list) @@ -452,8 +453,9 @@ def parse_and_process_package_changelog(gl, bob_group, pkg_name, package_changel return gitpkg, cur_tag, cur_tag_comments -def release_bob(gl, bob_group, changelog_file): +def release_bob(changelog_file): instructions = ''' + Here are the instructions to release Bob meta package: * Run ./check_private.sh bob.buildout bob.extension ... with the list of packages from bob.nightlies/order.txt * Put the list of public packages in ../../bob/requirements.txt @@ -542,8 +544,9 @@ def main(group_name='bob', changelog_file='changelog.rst', dry_run=False, packag bob_group = gl.groups.list(search=group_name)[0] + # if we are releasing 'bob' metapackage, it's a simple thing, no GitLab API if package == 'bob': - release_bob(gl, bob_group, changelog_file) + release_bob(changelog_file) return # traverse all packages in the changelog, edit older tags with updated comments, @@ -562,8 +565,13 @@ def main(group_name='bob', changelog_file='changelog.rst', dry_run=False, packag if not start_idx: print('Package {0} was not found in the changelog'.format(package)) return - start_idx = pkgs.tolist().index(start_idx[0]) + start_idx = pkgs.index(start_idx[0]) + # if we are in a dry-run mode, let's let it be known + if dry_run: + print('\n########### DRY RUN MODE ###########\nNothing is being committed to GitLab\n') + + # 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 = changelog[pkgs[i]][1:].strip() print('\nProcessing package {0}'.format(changelog[pkgs[i]]))