diff --git a/Dockerfile b/Dockerfile index ed7f70a3cefb0fe7c71470e24af4e114228e9ebd..2d35071a8934a7bd215b71aaf673399bcc459644 100644 --- a/Dockerfile +++ b/Dockerfile @@ -80,6 +80,8 @@ RUN echo 'hosts: files dns' > /etc/nsswitch.conf && \ ln -s /lib/libgcc_s.so.1 /usr/glibc-compat/lib/ && \ ln -s python3 /usr/bin/python && \ ln -s pip3 /usr/bin/pip && \ + python -m pip install --upgrade pip && \ + pip install semver && \ \ wget -q https://github.com/ahoy-cli/ahoy/releases/download/${AHOY_VERSION}/ahoy-bin-`uname -s`-amd64 -O /usr/local/bin/ahoy && \ chmod +x /usr/local/bin/ahoy && \ diff --git a/bin/gen-semver b/bin/gen-semver new file mode 100755 index 0000000000000000000000000000000000000000..1468170c6ac275e6ea46f4cf08b61e4ebfdc7167 --- /dev/null +++ b/bin/gen-semver @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 + +import argparse +import semver +import subprocess +import sys + + +def git(*args): + return subprocess.check_output(["git"] + list(args)) + + +def bump(latest, major, minor): + prefix = '' + try: + if latest[0] == 'v' or latest[0] == 'V': + prefix = latest[0] + latest = latest[1:] + if major: + version = semver.bump_major(latest) + elif minor: + version = semver.bump_minor(latest) + else: + version = semver.bump_patch(latest) + except ValueError: + # Latest tag is not SemVer compatible + version = "1.0.0" + return prefix + version + + +def main(): + parser = argparse.ArgumentParser(description='Get new semantic version of git repo, bumps patch version by default') + parser.add_argument('--minor', action='store_true', default=False, + help='Bump the minor version, would be overwritten by --major') + parser.add_argument('--major', action='store_true', default=False, + help='Bump the major version') + args, extras = parser.parse_known_args() + try: + latest = git("describe", "--tags").decode().strip() + except subprocess.CalledProcessError: + # No tags in the repository + version = "1.0.0" + else: + # Skip already tagged commits + if '-' not in latest: + version = latest + else: + version = bump(latest, args.major, args.minor) + + print(version) + return 0 + + +if __name__ == "__main__": + sys.exit(main())