Skip to content

Commit

Permalink
[BCIRepoPublisher] Simplify packages list creation in run()
Browse files Browse the repository at this point in the history
The current version is iterating twice over the package list, but that is not
necessary. The list can be assembled in a single pass, making it more obvious
what is happening.
  • Loading branch information
dcermak committed Oct 25, 2023
1 parent a06219a commit fc5b24c
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions gocd/bci_repo_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,36 +83,43 @@ def is_repo_published(self, project: str, repo: str) -> bool:

return True

def run(self, version, token=None):
def run(self, version: _SLE_VERSION_T, token: Optional[str]=None) -> None:

class Package(TypedDict):
arch: str
name: str
build_prj: str
publish_prj: str
built_version: str
built_mtime: int
published_mtime: int

build_prj = f'SUSE:SLE-{version}:Update:BCI'

if not self.is_repo_published(build_prj, 'images'):
self.logger.info(f'{build_prj}/images not successfully built')
return

# Build the list of packages with metainfo
packages = []
packages: List[Package] = []
# As long as it's the same everywhere, hardcoding this list here
# is easier and safer than trying to derive it from the package list.
for arch in ('aarch64', 'ppc64le', 's390x', 'x86_64'):
name = f'000product:SLE_BCI-ftp-POOL-{arch}'
publish_prj = f'SUSE:Products:SLE-BCI:{version}:{arch}'
packages.append({
'arch': arch,
'name': f'000product:SLE_BCI-ftp-POOL-{arch}',
'name': name,
'build_prj': build_prj,
'publish_prj': f'SUSE:Products:SLE-BCI:{version}:{arch}'
'publish_prj': publish_prj,
# Fetch the build numbers of built products.
# After release, the BuildXXX part vanishes, so the mtime has to be
# used instead for comparing built and published binaries.
'built_version': self.version_of_product(build_prj, name, 'images', 'local'),
'built_mtime': self.mtime_of_product(build_prj, name, 'images', 'local'),
'published_mtime': self.mtime_of_product(publish_prj, name, 'images', 'local')
})

# Fetch the build numbers of built products.
# After release, the BuildXXX part vanishes, so the mtime has to be
# used instead for comparing built and published binaries.
for pkg in packages:
pkg['built_version'] = self.version_of_product(pkg['build_prj'], pkg['name'],
'images', 'local')
pkg['built_mtime'] = self.mtime_of_product(pkg['build_prj'], pkg['name'],
'images', 'local')
pkg['published_mtime'] = self.mtime_of_product(pkg['publish_prj'], pkg['name'],
'images', 'local')

# Verify that the builds for all archs are in sync
built_versions = {pkg['built_version'] for pkg in packages}
if len(built_versions) != 1:
Expand Down

0 comments on commit fc5b24c

Please sign in to comment.