diff options
Diffstat (limited to 'bin/semver')
| -rwxr-xr-x | bin/semver | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/bin/semver b/bin/semver index cdc993a..19d2a58 100755 --- a/bin/semver +++ b/bin/semver @@ -16,6 +16,8 @@ import getopt simple_tag = False force = False +changelog = True + def usage(): print(f"usage: {sys.argv[0]} OPTIONS COMMANDS") @@ -24,6 +26,7 @@ OPTIONS: \t-h\tshow this help \t-t\tonly create a simple tag, otherwise annotate as well \t-f\toverwrite existing tag +\t-c\tdon't write changelog COMMANDS: \tpatch @@ -34,16 +37,18 @@ COMMANDS: try: - opts, argv = getopt.getopt(sys.argv[1:], 'tfh') + opts, argv = getopt.getopt(sys.argv[1:], 'tfch') except getopt.GetoptError as err: print(err) usage() for o, val in opts: if o == "-t": - simple_tag = True + simple_tag = not force elif o == "-f": - force = True + force = not force + elif o == "-c": + changelog = not changelog elif o == "-h": usage() else: @@ -55,7 +60,8 @@ if subprocess.run(["git", "branch", "--show-current"], subprocess.run(["git", "pull", "--rebase"]) -p = subprocess.run(["git", "describe", "--abbrev=0", "--tags"], stdout=subprocess.PIPE) +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 old_version = describe.split("-")[0].split(".") @@ -68,7 +74,9 @@ elif len(old_version) == 3: [major, minor, patch] = map(int, [major, minor, patch]) else: - print(f"WARNING: git describe returned invalid semver version: \"{describe}\"") + print( + f"WARNING: git describe returned invalid semver version: \"{describe}\"" + ) # sys.exit(1) # old_version = [0, 0, 0] @@ -125,5 +133,16 @@ else: args.extend([new_version]) subprocess.run(args) +if changelog: + import time + now = time.strftime("%Y-%m-%d", time.localtime()) + with open("CHANGELOG", "r+") as f: + data = f.read() + f.seek(0) + f.write(f"\n{new_version} ({now})\n\n") + f.write(shortlog) + f.write(data) + f.flush() + print(args) print(new_version) |