Skip to content

Commit

Permalink
consolidate: sort versions, highest first
Browse files Browse the repository at this point in the history
  • Loading branch information
ES-Alexander committed Apr 25, 2023
1 parent b6e637c commit b01893c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions blueos_repository/consolidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,23 +151,22 @@ async def all_repositories(self) -> AsyncIterable[RepositoryEntry]:
raise Exception(f"unable to read file {individual_file}: {error}") from error

@staticmethod
def is_valid_semver(string: str) -> bool:
def valid_semver(string: str) -> Optional[semver.VersionInfo]:
# We want to allow versions to be prefixed with a 'v'.
# This is up for discussion
if string.startswith("v"):
string = string[1:]
try:
semver.VersionInfo.parse(string)
return True
return semver.VersionInfo.parse(string)
except ValueError:
return False
return None # not valid

# pylint: disable=too-many-locals
async def run(self) -> None:
async for repository in self.all_repositories():
for tag in await self.registry.fetch_remote_tags(repository.docker):
try:
if not self.is_valid_semver(tag):
if not self.valid_semver(tag):
print(f"{tag} is not valid SemVer, ignoring it...")
continue
raw_labels = await self.registry.fetch_labels(f"{repository.docker}:{tag}")
Expand Down Expand Up @@ -205,6 +204,10 @@ async def run(self) -> None:
repository.versions[tag] = new_version
except KeyError as error:
raise Exception(f"unable to parse repository {repository}: {error}") from error
# sort the versions, with the highest version first
repository.versions = dict(
sorted(repository.versions.items(), key=lambda i: self.valid_semver(i[0]), reverse=True) # type: ignore
)
self.consolidated_data.append(repository)

with open("manifest.json", "w", encoding="utf-8") as manifest_file:
Expand Down

0 comments on commit b01893c

Please sign in to comment.