Skip to content

Commit 68f6329

Browse files
classabbyampthe-maldridge
authored andcommitted
services/nomad/build/buildbot: collect diff better to avoid skipping new packages
for some reason, when collapsing build requests, `self.build.allFiles()` only includes the changes from the `HEAD` commit, which is especially egregious when we jump to the `HEAD` commit (not the one that's supposed to be built according to buildbot). By doing the diff ourselves, we can avoid that pain and get the true list of packages that have changed from the previous build to now. This will still miss builds if there was a failure, though. We'd need a better build orchestrator to fix that, I think.
1 parent 79a1937 commit 68f6329

1 file changed

Lines changed: 35 additions & 13 deletions

File tree

services/nomad/build/buildbot.cfg

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import shlex
88
from pathlib import Path
99

1010
from twisted.internet import defer
11+
from twisted.python import log
1112

1213
from buildbot.process.results import SUCCESS, SKIPPED
1314
from buildbot.plugins import util, secrets, reporters, worker, schedulers
@@ -133,6 +134,37 @@ hide_skipped = lambda results, _: results == SKIPPED
133134
factory = util.BuildFactory()
134135

135136

137+
class GitWithDiff(steps.Git):
138+
"""git fetch and checkout, with diff"""
139+
@defer.inlineCallbacks
140+
def mode_incremental(self):
141+
action = yield self._sourcedirIsUpdatable()
142+
# if not updatable, do a full checkout
143+
if action == "clobber":
144+
yield self.clobber()
145+
return
146+
elif action == "clone":
147+
log.msg("No git repo present, making full clone")
148+
yield self._fullCloneOrFallback(shallowClone=self.shallow)
149+
pkgs = yield self._get_changed_pkgs("HEAD~")
150+
self.updateSourceProperty("packages_changed", " ".join(pkgs))
151+
return
152+
153+
old_ref = yield self._dovccmd(["rev-parse", "HEAD"], collectStdout=True)
154+
yield self._fetchOrFallback()
155+
pkgs = yield self._get_changed_pkgs(old_ref.strip())
156+
self.updateSourceProperty("packages_changed", " ".join(pkgs))
157+
158+
@defer.inlineCallbacks
159+
def _get_changed_pkgs(self, old_ref: str):
160+
diff = yield self._dovccmd(["diff", "--name-only", old_ref, "HEAD"], collectStdout=True)
161+
pkgs = []
162+
for pth in diff.splitlines():
163+
if pth and pth.startswith("srcpkgs/") and pth.endswith("/template"):
164+
pkgs.append(pth.split("/")[-2])
165+
return pkgs
166+
167+
136168
@util.renderer
137169
def make_xbps_src_cmd(props, cmd):
138170
command = [
@@ -166,21 +198,11 @@ def make_xbps_bulk_cmd(props):
166198
else:
167199
command += ['-a', 'native-' + props.getProperty('host')]
168200
command += ['--']
201+
command += props.getProperty('packages_changed').split()
169202

170203
return command
171204

172205

173-
class ShellCommandWithChanges(steps.ShellCommand):
174-
@defer.inlineCallbacks
175-
def run(self):
176-
cmd = yield self.makeRemoteShellCommand()
177-
pkgs = [f.split("/")[-2] for f in self.build.allFiles()
178-
if f.startswith("srcpkgs/") and f.endswith("/template")]
179-
cmd.command += pkgs
180-
yield self.runCommand(cmd)
181-
return cmd.results()
182-
183-
184206
@util.renderer
185207
def build_packages(props):
186208
cmds = []
@@ -226,7 +248,7 @@ rsync://buildsync-%(prop:worker)s@{{ .Address }}:{{ .Port }}/%(prop:worker)s
226248
{{ end -}}""")]
227249

228250

229-
factory.addStep(steps.Git(
251+
factory.addStep(GitWithDiff(
230252
repourl='https://github.com/void-linux/void-packages.git',
231253
mode='incremental',
232254
workdir=distdir(''),
@@ -274,7 +296,7 @@ factory.addStep(steps.ShellCommand(
274296
workdir='.',
275297
))
276298

277-
factory.addStep(ShellCommandWithChanges(
299+
factory.addStep(steps.ShellCommand(
278300
command=make_xbps_bulk_cmd,
279301
name='find_packages',
280302
description='finding packages to build',

0 commit comments

Comments
 (0)