From dd78d4f1858c8e0eb22ef623b75ba98fc353f805 Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Tue, 3 Sep 2019 16:31:05 +0200 Subject: [PATCH] Add scripts for assisting with the release procedure --- .../generate_changelog | 0 scripts/tag_version | 53 +++++++++++++++++++ 2 files changed, 53 insertions(+) rename generate_changelog => scripts/generate_changelog (100%) create mode 100755 scripts/tag_version diff --git a/generate_changelog b/scripts/generate_changelog similarity index 100% rename from generate_changelog rename to scripts/generate_changelog diff --git a/scripts/tag_version b/scripts/tag_version new file mode 100755 index 0000000..a027c1f --- /dev/null +++ b/scripts/tag_version @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 + +""" +Creates an annotated git tag for a given version number. + +The tag will include the version number and changes for given version. + +Usage: tag_version [version] +""" + +import subprocess +import sys +import textwrap +import yaml + +from datetime import date +from os import path + +path = path.join(path.dirname(path.dirname(path.abspath(__file__))), "changelog.yaml") +with open(path, "r") as f: + changelog = yaml.safe_load(f) + +if len(sys.argv) != 2: + print("Wrong argument count", file=sys.stderr) + sys.exit(1) + +version = sys.argv[1] +changelog_item = changelog.get(version) + +if not changelog_item: + print(f"Version `{version}` not found in changelog.", file=sys.stderr) + sys.exit(1) + +release_date = changelog_item["date"] +changes = changelog_item["changes"] + +if not isinstance(release_date, date): + print(f"Release date not set for version `{version}` in the changelog.", file=sys.stderr) + sys.exit(1) + +commit_message = f"toot {version}\n\n" +for c in changes: + lines = textwrap.wrap(c, 70) + initial = True + for line in lines: + lead = " *" if initial else " " + initial = False + commit_message += f"{lead} {line}\n" + +subprocess.run(["git", "tag", "-a", version, "-m", commit_message]) + +print("Tagged version:") +print(commit_message)