fwupd/contrib/get-version.py
Mario Limonciello 429a5128d3 Dynamically determine release version
This is inspired by a change in flashrom to read the version string for meson
dynamically.

No need for "post release version bump", this happens automatically from git
now by there being a dirty commit.
2019-11-08 09:52:02 -06:00

48 lines
1.2 KiB
Python
Executable File

#!/usr/bin/python3
#
# Copyright (C) 2019 Dell, Inc.
#
# SPDX-License-Identifier: LGPL-2.1+
#
import xml.etree.ElementTree as etree
import os
import subprocess
def sanitize_for_ci(version):
if not 'CI' in os.environ:
return version
OS=os.getenv('OS')
if not OS:
return version
if "fedora" in OS:
return version.replace('-','.')
return version
def get_version_git():
try:
version = subprocess.check_output(['git', 'describe'], stderr=subprocess.DEVNULL)
return version.strip().decode('utf-8')
except subprocess.CalledProcessError:
return ''
def get_version():
tree = etree.parse(os.path.join("data", "org.freedesktop.fwupd.metainfo.xml"))
version = ''
for child in tree.findall('releases'):
for release in child:
if not "version" in release.attrib:
continue
if release.attrib['version'] > version:
version = release.attrib['version']
return version
if __name__ == '__main__':
version = get_version_git()
if version:
version = sanitize_for_ci(version)
else:
version = get_version()
print(version)