From 10751dc6bcb06526c6589df174b992a0c06ff79d Mon Sep 17 00:00:00 2001 From: Magnus Jacobsson Date: Tue, 21 Jul 2020 17:01:05 +0200 Subject: [PATCH] Add gen_version.py script --- gen_version.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 gen_version.py diff --git a/gen_version.py b/gen_version.py new file mode 100644 index 000000000..301d1e758 --- /dev/null +++ b/gen_version.py @@ -0,0 +1,46 @@ +# Generate version +# +# Stable release entry format : ..>patch> +# Development release entry format: ..-dev +# +# Stable release output format : .. +# Development release output format: ..-dev. + +# The patch version of a development release should be the next stable +# release patch number followed by "-dev". The committer date will be +# added with a period separator. +# +# Example sequence: +# +# Entry Output +# 2.44.1 => 2.44.1 +# 2.44.2-dev => 2.44.2-dev.20200704.1652 +# 2.44.2 => 2.44.2 +# 2.44.3-dev => 2.44.3-dev.20200824.1337 + +version = '2.44.2-dev' + +import os +import subprocess + +major_version, minor_version, patch_version = version.split('.') + +try: + int(patch_version) +except ValueError: + # Non-numerical patch version; add committer date + os.environ['TZ'] = 'UTC' + committer_date = subprocess.run( + [ + 'git', + 'log', + '-n', + '1', + '--format=%cd', + '--date=format-local:%Y%m%d.%H%M' + ], + stdout=subprocess.PIPE, + ).stdout.decode('utf-8').strip() + patch_version += '.' + committer_date + +print(f'{major_version}.{minor_version}.{patch_version}') -- 2.40.0