Files
chart/library/ix-dev/charts/collabora/upgrade_strategy
2023-09-18 18:49:35 +03:00

57 lines
1.5 KiB
Python
Executable File

#!/usr/bin/python3
import json
import sys
import re
from catalog_update.upgrade_strategy import datetime_versioning
RE_STABLE_VERSION = re.compile(r'^(\d+\.){4}\d+$')
def newer_mapping(image_tags):
key = list(image_tags.keys())[0]
temp_tags = {t: t for t in image_tags[key] if RE_STABLE_VERSION.fullmatch(t)}
tags = {}
for tag in temp_tags:
tag = tag.split('.')
for i in range(len(tag)):
# Ignore the first two parts as they are supposed to have leading zeros
if i in [0, 1]:
continue
# Add leading zero to single digit numbers
if len(tag[i]) == 1:
tag[i] = '0' + tag[i]
tag = '.'.join(tag)
tags[tag] = tag
version = datetime_versioning(list(tags), '%y.%m.%d.%H.%M')
if not version:
return {}
cleanVersion = ""
for idx, part in enumerate(version.split('.')):
# Ignore the first two parts as they are supposed to have leading zeros
if idx in [0, 1]:
cleanVersion += part + '.'
continue
# Remove leading zero
cleanVersion += part.lstrip('0') + '.'
# Remove trailing dot
cleanVersion = cleanVersion.rstrip('.')
return {
'tags': {key: cleanVersion},
'app_version': cleanVersion,
}
if __name__ == '__main__':
try:
versions_json = json.loads(sys.stdin.read())
except ValueError:
raise ValueError('Invalid json specified')
print(json.dumps(newer_mapping(versions_json)))