Skip to content

Commit

Permalink
Merge pull request #3044 from dirkmueller/bci_publish_immediately_on_…
Browse files Browse the repository at this point in the history
…repo_change

publish bci repo right away on package set changes
  • Loading branch information
dirkmueller authored Jan 3, 2024
2 parents 6478168 + b8fff45 commit 0dc1993
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions gocd/bci_repo_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ def version_of_product(self, project, package, repo, arch):

raise RuntimeError(f"Failed to get version of {project}/{package}")

def srcmd5_of_product(self, project, package):
"""Get the srcmd5 of the given source package."""
# convert to the base package (without multibuild flavor)
package = package.partition(':')[0]
url = makeurl(self.apiurl, ['source', project, package])
root = ET.parse(http_GET(url)).getroot()
if root.tag == 'directory' and 'srcmd5' in root.attrib:
return root.attrib['srcmd5']
raise RuntimeError(f"Failed to get srcmd5 of {project}/{package}")

def mtime_of_product(self, project, package, repo, arch):
"""Get the build time stamp of the given product, based on _buildenv."""
url = makeurl(self.apiurl, ['build', project, repo, arch, package])
Expand Down Expand Up @@ -104,12 +114,16 @@ def run(self, version, token=None):
# 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')
pkg['built_srcmd5'] = self.srcmd5_of_product(
pkg['build_prj'], pkg['name'])
pkg['published_srcmd5'] = self.srcmd5_of_product(
pkg['publish_prj'], pkg['name'])
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}
Expand All @@ -126,11 +140,18 @@ def run(self, version, token=None):
return

# If the last published build is less than a day old, don't publish
newest_published_mtime = max([int(pkg['published_mtime']) for pkg in packages])
published_build_age_hours = int(time.time() - newest_published_mtime) // (60 * 60)
if published_build_age_hours < 24:
self.logger.info('Current published build less than a day old '
f'({published_build_age_hours}h).')
oldest_published_mtime = min([int(pkg['published_mtime']) for pkg in packages])
published_build_age_hours = int(time.time() - oldest_published_mtime) // (60 * 60)
pending_source_changes = [
f"{pkg['name']}: {pkg['built_srcmd5']}/{pkg['published_srcmd5']}"
for pkg in packages if pkg['built_srcmd5'] != pkg['published_srcmd5']]
if pending_source_changes:
self.logger.info(f"Pending source changes to published, skipping waiting for 24h: {pending_source_changes}")
# If the source commit different than the published version, we
# do not wait for 24h for a publish as there was a package addition or removal change
pass
elif published_build_age_hours < 24:
self.logger.info(f'Oldest published build is only {published_build_age_hours}h old, not publishing yet.')
return

# Check openQA results
Expand Down

0 comments on commit 0dc1993

Please sign in to comment.