From ce1971972cb992905bd15f864a49fcb827b76476 Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Tue, 23 Feb 2021 13:39:44 +0100 Subject: bin/semver: only annotate when explicitly requested via -a --- bin/semver | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'bin') diff --git a/bin/semver b/bin/semver index 19d2a58..4a891c3 100755 --- a/bin/semver +++ b/bin/semver @@ -14,7 +14,7 @@ import sys import tempfile import getopt -simple_tag = False +simple_tag = True force = False changelog = True @@ -22,29 +22,31 @@ changelog = True def usage(): print(f"usage: {sys.argv[0]} OPTIONS COMMANDS") print(""" +bump the previous tag and create a new one + OPTIONS: \t-h\tshow this help -\t-t\tonly create a simple tag, otherwise annotate as well +\t-a\tannotate tag \t-f\toverwrite existing tag \t-c\tdon't write changelog COMMANDS: \tpatch \tminor -\tmajor\tbump the previous tag and create a new one +\tmajor """) sys.exit(2) try: - opts, argv = getopt.getopt(sys.argv[1:], 'tfch') + opts, argv = getopt.getopt(sys.argv[1:], 'afch') except getopt.GetoptError as err: print(err) usage() for o, val in opts: - if o == "-t": - simple_tag = not force + if o == "-a": + simple_tag = not simple_tag elif o == "-f": force = not force elif o == "-c": @@ -54,6 +56,9 @@ for o, val in opts: else: assert False, "unhandled option" +if any(item in ["-h", "--help", "help"] for item in argv): + usage() + if subprocess.run(["git", "branch", "--show-current"], stdout=subprocess.PIPE).stdout.decode().strip() != "master": print("WARNING! Not on the master branch.") @@ -64,6 +69,12 @@ p = subprocess.run(["git", "describe", "--abbrev=0", "--tags"], stdout=subprocess.PIPE) describe = p.stdout.decode().strip() # TODO also ask to re-append the trailing portion.... e.g. -rev1 + +prepend = '' +if describe[0] == 'v': + describe = describe[1:] + prepend = 'v' + old_version = describe.split("-")[0].split(".") if len(old_version) == 2: [major, minor] = old_version @@ -77,11 +88,12 @@ else: print( f"WARNING: git describe returned invalid semver version: \"{describe}\"" ) - # sys.exit(1) + sys.exit(1) # old_version = [0, 0, 0] -p = subprocess.run(["git", "shortlog", "--no-merges", f"{describe}..HEAD"], - stdout=subprocess.PIPE) +p = subprocess.run( + ["git", "shortlog", "--no-merges", f"{prepend}{describe}..HEAD"], + stdout=subprocess.PIPE) shortlog = p.stdout.decode() new_version = None @@ -103,6 +115,9 @@ if new_version is None: else: new_version = f"{major}.{minor}.{patch}" +if prepend is not '': + new_version = prepend + new_version + p = None if os.path.exists("contrib/_incr_version"): p = subprocess.run(["contrib/_incr_version", describe, new_version]) @@ -130,7 +145,7 @@ if not simple_tag: args.extend(["-e", "-F", f.name, "-a", new_version]) subprocess.run(args) else: - args.extend([new_version]) + args.extend(["-m", new_version, new_version]) subprocess.run(args) if changelog: @@ -143,6 +158,3 @@ if changelog: f.write(shortlog) f.write(data) f.flush() - -print(args) -print(new_version) -- cgit 1.4.1