Skip to content

Commit

Permalink
Merge PR #4763: BUILD(versioning): Remove tag logic, implement "--rev…
Browse files Browse the repository at this point in the history
…ision", "--format" and "--type" options in mumble-version.py
  • Loading branch information
davidebeatrici authored Feb 16, 2021
2 parents 21f69a5 + 1e4932b commit cd7e9f9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .ci/azure-pipelines/build_linux.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .ci/azure-pipelines/build_macos.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .ci/azure-pipelines/build_windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
38 changes: 17 additions & 21 deletions scripts/mumble-version.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,44 +100,40 @@ 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()

if args.newline:
end = None
else:
end = ''

if args.project:
projectVersion = readProjectVersion()
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]
version = readProjectVersion()

if len(latestCommitTags) > 1:
raise RuntimeError("Encountered commit with multiple tags: %s" % latestCommitTags)
if args.format == 'version':
print(version, end = end)
return

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)
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()

projectVersion = readProjectVersion()
latestCommitHash = cmd(['git', 'rev-parse', '--short', 'HEAD']).strip()

version = '{0}~{1}~g{2}~snapshot'.format(projectVersion, latestCommitDate, latestCommitHash)
suffix = '~{0}~g{1}~snapshot'.format(latestCommitDate, latestCommitHash)

print(version, end = end)
if args.format == 'suffix':
print(suffix, end = end)
else:
print(version + suffix, end = end)

if __name__ == '__main__':
main()

0 comments on commit cd7e9f9

Please sign in to comment.