From 9f3685efb7e74b9a0106b087f9c5e74240b46742 Mon Sep 17 00:00:00 2001 From: Davide Beatrici Date: Tue, 16 Feb 2021 09:53:31 +0100 Subject: [PATCH 1/2] BUILD(versioning): Add "--type" and "--revision" options to mumble-version.py This commit removes the tag logic from the script. Its purpose was to set the name of the tag associated to the latest version as version. It was working as expected, however in some instances we don't want the script to take the tag into account. For example, we had to rebuild the first 1.4.0 snapshot as the version was accidentally set to 1.4.0-snapshot1. As replacement, the "--revision" and "--type" options are implemened. They allow to explicitly set the release type and its revision, when applicable. Assuming the revision is set to 1 (default value), the output is currently as follows: Type set to "snapshot": 1.4.0~2021-02-14~g973cee211~snapshot Type set to "beta": 1.4.0-beta1 Type set to "rc": 1.4.0-rc1 Type set to "stable": 1.4.0 --- scripts/mumble-version.py | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/scripts/mumble-version.py b/scripts/mumble-version.py index 70e1af8e695..efb7e400ef6 100755 --- a/scripts/mumble-version.py +++ b/scripts/mumble-version.py @@ -102,6 +102,8 @@ def main(): parser = argparse.ArgumentParser() parser.add_argument('-n', '--newline', action = "store_true", help = 'Break line after printing version') parser.add_argument('-p', '--project', action = "store_true", help = 'Print CMake project version') + parser.add_argument('-r', '--revision', type = int, default = 1, help = 'Revision (only used for type \'beta\' and \'rc\')') + parser.add_argument('-t', '--type', choices = ['snapshot', 'beta', 'rc', 'stable'], default = 'snapshot', help = 'Release type - determines the suffix') args = parser.parse_args() if args.newline: @@ -109,34 +111,24 @@ def main(): else: end = '' - if args.project: - projectVersion = readProjectVersion() + projectVersion = readProjectVersion() + + if args.project or args.type == 'stable': print(projectVersion, end = end) return - # Get all tags associated with the latest commit - latestCommitTags = [x for x in cmd(['git', 'tag', '--points-at', 'HEAD']).split("\n") if x] - - if len(latestCommitTags) > 1: - raise RuntimeError("Encountered commit with multiple tags: %s" % latestCommitTags) - - if len(latestCommitTags) == 1: - # Most recent commit is tagged -> this is a tagged release version - # Use the tag as the version-string - version = latestCommitTags[0] - else: - # This is a snapshot (i.e. built from a non-tagged commit) - - # Get the date of the most recent commit - latestCommitDate = cmd(['git', 'log', '-1', '--format=%cd', '--date=short']).strip() - - # Get the hash of the most recent commit (shortened) - latestCommitHash = cmd(['git', 'rev-parse', '--short' , 'HEAD']).strip() + if args.type == 'beta' or args.type == 'rc': + version = '{0}-{1}{2}'.format(projectVersion, args.type, args.revision) + print(version, end = end) + return - projectVersion = readProjectVersion() + # Get the date of the most recent commit + latestCommitDate = cmd(['git', 'log', '-1', '--format=%cd', '--date=short']).strip() - version = '{0}~{1}~g{2}~snapshot'.format(projectVersion, latestCommitDate, latestCommitHash) + # Get the hash of the most recent commit (shortened) + latestCommitHash = cmd(['git', 'rev-parse', '--short', 'HEAD']).strip() + version = '{0}~{1}~g{2}~snapshot'.format(projectVersion, latestCommitDate, latestCommitHash) print(version, end = end) if __name__ == '__main__': From 1e4932b898363990ae41435a5741b4f31ddc6b4c Mon Sep 17 00:00:00 2001 From: Davide Beatrici Date: Tue, 16 Feb 2021 09:57:12 +0100 Subject: [PATCH 2/2] BUILD(versioning): Implement "--format" option in mumble-version.py The option replaces "--project" and allows to specify the desired string format: - "full": The default. Prints version + suffix (e.g. "1.4.0~2021-02-14~g973cee211~snapshot"). - "version": Only prints the version (e.g. "1.4.0"). - "suffix": Only prints the suffix (e.g. "~2021-02-14~g973cee211~snapshot"). The main reason for implementing this new option is the suffix-only output. It will be passed to CMake in a future commit, for better filename control. --- .ci/azure-pipelines/build_linux.bash | 2 +- .ci/azure-pipelines/build_macos.bash | 2 +- .ci/azure-pipelines/build_windows.bat | 2 +- scripts/mumble-version.py | 32 +++++++++++++++------------ 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/.ci/azure-pipelines/build_linux.bash b/.ci/azure-pipelines/build_linux.bash index 72f3dcf24c8..b2a2a9cc4cb 100755 --- a/.ci/azure-pipelines/build_linux.bash +++ b/.ci/azure-pipelines/build_linux.bash @@ -20,7 +20,7 @@ # if [[ -n "$MUMBLE_BUILD_NUMBER_TOKEN" ]]; then - VERSION=$(python "scripts/mumble-version.py" --project) + VERSION=$(python "scripts/mumble-version.py" --format version) BUILD_NUMBER=$(curl "https://mumble.info/get-build-number?commit=${BUILD_SOURCEVERSION}&version=${VERSION}&token=${MUMBLE_BUILD_NUMBER_TOKEN}") else BUILD_NUMBER=0 diff --git a/.ci/azure-pipelines/build_macos.bash b/.ci/azure-pipelines/build_macos.bash index 90fa0dedfb0..ba2671ade78 100755 --- a/.ci/azure-pipelines/build_macos.bash +++ b/.ci/azure-pipelines/build_macos.bash @@ -31,7 +31,7 @@ # if [[ -n "$MUMBLE_BUILD_NUMBER_TOKEN" ]]; then - VERSION=$(python "scripts/mumble-version.py" --project) + VERSION=$(python "scripts/mumble-version.py" --format version) BUILD_NUMBER=$(curl "https://mumble.info/get-build-number?commit=${BUILD_SOURCEVERSION}&version=${VERSION}&token=${MUMBLE_BUILD_NUMBER_TOKEN}") else BUILD_NUMBER=0 diff --git a/.ci/azure-pipelines/build_windows.bat b/.ci/azure-pipelines/build_windows.bat index 0d128281d60..62efc3356b8 100644 --- a/.ci/azure-pipelines/build_windows.bat +++ b/.ci/azure-pipelines/build_windows.bat @@ -37,7 +37,7 @@ :: The method we use to store a command's output into a variable: :: https://stackoverflow.com/a/6362922 -for /f "tokens=* USEBACKQ" %%g in (`python "scripts\mumble-version.py" --project`) do (set "VERSION=%%g") +for /f "tokens=* USEBACKQ" %%g in (`python "scripts\mumble-version.py" --format version`) do (set "VERSION=%%g") :: For some really stupid reason we can't have this statement and the one where we set the VERSION variable in the same if body as :: in that case the variable substitution of that variable in the expression below fails (is replaced with empty string) diff --git a/scripts/mumble-version.py b/scripts/mumble-version.py index efb7e400ef6..e139179c0be 100755 --- a/scripts/mumble-version.py +++ b/scripts/mumble-version.py @@ -100,8 +100,8 @@ def readProjectVersion(): def main(): parser = argparse.ArgumentParser() + parser.add_argument('-f', '--format', choices = ['full', 'version', 'suffix'], default='full', help = 'Output format') parser.add_argument('-n', '--newline', action = "store_true", help = 'Break line after printing version') - parser.add_argument('-p', '--project', action = "store_true", help = 'Print CMake project version') parser.add_argument('-r', '--revision', type = int, default = 1, help = 'Revision (only used for type \'beta\' and \'rc\')') parser.add_argument('-t', '--type', choices = ['snapshot', 'beta', 'rc', 'stable'], default = 'snapshot', help = 'Release type - determines the suffix') args = parser.parse_args() @@ -111,25 +111,29 @@ def main(): else: end = '' - projectVersion = readProjectVersion() + version = readProjectVersion() - if args.project or args.type == 'stable': - print(projectVersion, end = end) - return - - if args.type == 'beta' or args.type == 'rc': - version = '{0}-{1}{2}'.format(projectVersion, args.type, args.revision) + if args.format == 'version': print(version, end = end) return - # Get the date of the most recent commit - latestCommitDate = cmd(['git', 'log', '-1', '--format=%cd', '--date=short']).strip() + suffix = '' + + if args.type == 'rc' or args.type == 'beta': + suffix = '-{0}{1}'.format(args.type, args.revision) + elif args.type == 'snapshot': + # Get the date of the most recent commit + latestCommitDate = cmd(['git', 'log', '-1', '--format=%cd', '--date=short']).strip() - # Get the hash of the most recent commit (shortened) - latestCommitHash = cmd(['git', 'rev-parse', '--short', 'HEAD']).strip() + # Get the hash of the most recent commit (shortened) + latestCommitHash = cmd(['git', 'rev-parse', '--short', 'HEAD']).strip() - version = '{0}~{1}~g{2}~snapshot'.format(projectVersion, latestCommitDate, latestCommitHash) - print(version, end = end) + suffix = '~{0}~g{1}~snapshot'.format(latestCommitDate, latestCommitHash) + + if args.format == 'suffix': + print(suffix, end = end) + else: + print(version + suffix, end = end) if __name__ == '__main__': main()