From: Magnus Jacobsson Date: Tue, 21 Jul 2020 15:01:05 +0000 (+0200) Subject: Add gen_version.py script X-Git-Tag: 2.46.0~20^2^2~175^2~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=10751dc6bcb06526c6589df174b992a0c06ff79d;p=graphviz Add gen_version.py script --- 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}')