Skip to content

Commit

Permalink
Fix overwriting build config for dynamically changing branches
Browse files Browse the repository at this point in the history
This patch creates copies of BuildConfig objects so that the initial
values are not changed. This way dynamic branch triggers (external JSON
resources) are not replaced with static branch names after first
request.

Fixes: #1047

Signed-off-by: Paweł Wieczorek <pawiecz@collabora.com>
  • Loading branch information
pawiecz authored and nuclearcat committed Feb 25, 2025
1 parent babb471 commit 11f050a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
6 changes: 4 additions & 2 deletions src/tarball.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Author: Jeny Sadadia <jeny.sadadia@collabora.com>
# Author: Nikolay Yurin <yurinnick@meta.com>

import copy
from datetime import datetime, timedelta
import os
import re
Expand Down Expand Up @@ -58,8 +59,9 @@ def _find_build_config(self, node):
if config.tree.name == tree and config.branch == branch:
return config
if config.tree.name == tree and config.branch.startswith('http'):
config._branch = branch
return config
current = copy.copy(config)
current._branch = branch
return current

def _find_build_commit(self, node):
revision = node['data'].get('kernel_revision')
Expand Down
28 changes: 15 additions & 13 deletions src/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Author: Guillaume Tucker <guillaume.tucker@collabora.com>
# Author: Jeny Sadadia <jeny.sadadia@collabora.com>

import copy
from datetime import datetime, timedelta
import json
import logging
Expand Down Expand Up @@ -44,20 +45,21 @@ def _run_trigger(self, build_config, force, timeout, trees):
return

try:
if validate_url(build_config.branch):
response = requests.get(build_config.branch)
current_config = copy.copy(build_config)
if validate_url(current_config.branch):
response = requests.get(current_config.branch)
# Following extractor supports only NIPA JSON scheme.
# Adding support for other schemas will force moving it to a separate function.
branches = response.json()
latest = sorted(branches, key=lambda x: x['date'], reverse=True)[0]
tree = build_config.tree.name
tree = current_config.tree.name
self.log.info(f"NIPA Latest branch: {latest['branch']} Date: {latest['date']}"
f" Tree: {tree}")
build_config._branch = latest['branch']
current_config._branch = latest['branch']

head_commit = kernelci.build.get_branch_head(build_config)
head_commit = kernelci.build.get_branch_head(current_config)
except Exception as ex:
self.log.error(f"Failed to get branch head for {build_config.name:32s}")
self.log.error(f"Failed to get branch head for {current_config.name:32s}")
self.traceback(ex)
return
search_terms = {
Expand All @@ -74,30 +76,30 @@ def _run_trigger(self, build_config, force, timeout, trees):
# it means we retry the same commit 3 times and it still fails
if incomplete_node_count >= 3:
self._log_revision(
"Too many incomplete checkouts", build_config, head_commit
"Too many incomplete checkouts", current_config, head_commit
)
return

# Do not count incomplete checkouts
if node_count > 0 and incomplete_node_count != node_count:
if force:
self._log_revision(
"Resubmitting existing revision", build_config, head_commit
"Resubmitting existing revision", current_config, head_commit
)
else:
self._log_revision(
"Existing revision", build_config, head_commit
"Existing revision", current_config, head_commit
)
return
else:
self._log_revision(
"New revision", build_config, head_commit
"New revision", current_config, head_commit
)

revision = {
'tree': build_config.tree.name,
'url': build_config.tree.url,
'branch': build_config.branch,
'tree': current_config.tree.name,
'url': current_config.tree.url,
'branch': current_config.branch,
'commit': head_commit,
}
checkout_timeout = datetime.utcnow() + timedelta(minutes=timeout)
Expand Down

0 comments on commit 11f050a

Please sign in to comment.