Implement version checking
All checks were successful
Build Docker Image / build (push) Successful in 27s
All checks were successful
Build Docker Image / build (push) Successful in 27s
This commit is contained in:
48
main.py
48
main.py
@@ -70,51 +70,57 @@ class Autopkg:
|
||||
|
||||
# Grab data from data file
|
||||
data_section = f"tags.{app}"
|
||||
data_tag = []
|
||||
data_tag = [list.append(i[1]) for i in self.data.items(data_section)]
|
||||
|
||||
for i in self.data.items(conf_section):
|
||||
tag.append(i[1])
|
||||
app_name = info["name"]
|
||||
|
||||
|
||||
# Ping API
|
||||
response = requests.get(info["url"]) # Fetch data from Git API
|
||||
|
||||
# Parse through JSON data
|
||||
if response.status_code == 200:
|
||||
json = response.json()
|
||||
tag = json["tag_name"] # App version from API
|
||||
api_tag = json["tag_name"] # App version from API
|
||||
pre_release = json["prerelease"]
|
||||
|
||||
# Package new versions if available
|
||||
if tag != ini_version and not pre_release:
|
||||
logging.info(f"Found new version ({tag}) for {app}, packaging..")
|
||||
api_tag_higher = is_tag_higher(api_tag, data_tag, info)
|
||||
|
||||
try:
|
||||
if Package(app, tag).build():
|
||||
ini_version = str(tag)
|
||||
if not pre_release and api_tag_higher[0]:
|
||||
logging.info(f"Found new version ({api_tag}) for {app_name}, packaging..")
|
||||
|
||||
try: # REMOVE!!!
|
||||
if Package(app, api_tag).build():
|
||||
ini_version = str(api_tag)
|
||||
|
||||
self.write_data()
|
||||
except Exception as e:
|
||||
logging.error(f"Error starting docker container for {app}")
|
||||
logging.error(f"Error starting docker container for {app_name}")
|
||||
else:
|
||||
logging.log(f"No new versions were found for {app_name}")
|
||||
else:
|
||||
logging.error(f"Failed to ping {app_name}'s API.")
|
||||
|
||||
|
||||
def version_is_higher(tag: str, ini_tag: tuple, app_info: dict) -> (str, None):
|
||||
def is_tag_higher(api_tag: str, data_tag: list, data_info: dict) -> tuple:
|
||||
regular_scheme = r"^v(\d+)\.(\d+)\.(\d+)$"
|
||||
|
||||
# Derive version from API tag
|
||||
try:
|
||||
version = re.match(info["versioningScheme"], tag)
|
||||
version = re.match(data_info, api_tag)
|
||||
except:
|
||||
version = re.match(regular_scheme, tag)
|
||||
version = re.match(regular_scheme, api_tag)
|
||||
|
||||
if version:
|
||||
tag_major = int(version.group(1))
|
||||
tag_minor = int(version.group(2))
|
||||
tag_patch = int(version.group(3))
|
||||
else:
|
||||
if not version:
|
||||
logging.warning(f"New tag for {app_info["name"]} doesn't follow versioning schemes, ignoring..")
|
||||
|
||||
return None
|
||||
return (False)
|
||||
|
||||
if
|
||||
# Compare versions
|
||||
re_tag = map(int, version.groups())
|
||||
is_higher = tuple(map(lambda a, b: a >= b, re_tag, data_tag))
|
||||
|
||||
return (True, re_tag) if all(is_higher) else (False)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import re
|
||||
|
||||
|
||||
Reference in New Issue
Block a user