Use version from git describe in builds

This commit is contained in:
alesapin 2021-11-25 14:19:26 +03:00
parent 81942b8128
commit 3d811aeec1
2 changed files with 24 additions and 3 deletions

View File

@ -115,8 +115,15 @@ if __name__ == "__main__":
image_version = docker_image.version
version = get_version_from_repo(repo_path)
version.tweak_update()
update_version_local(repo_path, pr_info.sha, version)
logging.info("Got version from repo %s", version.get_version_string())
version_type = 'testing'
if 'release' in pr_info.labels or 'release-lts' in pr_info.labels:
version_type = 'stable'
update_version_local(repo_path, pr_info.sha, version, version_type)
logging.info("Updated local files with version")
build_name = build_config_to_string(build_config)
logging.info("Build short name %s", build_name)

View File

@ -66,13 +66,27 @@ def _get_version_from_line(line):
_, ver_with_bracket = line.strip().split(' ')
return ver_with_bracket[:-1]
def get_tweak_from_git_describe(repo_path):
# something like v21.12.1.8816-testing-358-g81942b8128
# or v21.11.4.14-stable-31-gd6aab025e0
output = subprocess.check_output(f"cd {repo_path} && git describe --long", shell=True).decode('utf-8')
commits_number = int(output.split('-')[2])
# for testing releases we have to also add fourth number of
# the previous tag
if 'testing' in output:
previous_version = output.split('-')[0]
previous_version_commits = int(previous_version.split('.')[3])
commits_number += previous_version_commits
return commits_number
def get_version_from_repo(repo_path):
path_to_file = os.path.join(repo_path, FILE_WITH_VERSION_PATH)
major = 0
minor = 0
patch = 0
tweak = 0
tweak = get_tweak_from_git_describe(repo_path)
version_revision = 0
with open(path_to_file, 'r') as ver_file:
for line in ver_file: