[buildbot] phase1: Fix the force scheduler process

LEDE Commits lede-commits at lists.infradead.org
Mon May 15 08:39:37 PDT 2023


ynezz pushed a commit to buildbot.git, branch master:
https://git.openwrt.org/6f98f53c43c2d059c00b82882ca1af23dd2fb626

commit 6f98f53c43c2d059c00b82882ca1af23dd2fb626
Author: Thibaut VARÈNE <hacks at slashdirt.org>
AuthorDate: Wed Oct 26 20:51:20 2022 +0200

    phase1: Fix the force scheduler process
    
    Signed-off-by: Thibaut VARÈNE <hacks at slashdirt.org>
---
 phase1/master.cfg | 99 ++++++++++++++++++++++++++-----------------------------
 1 file changed, 47 insertions(+), 52 deletions(-)

diff --git a/phase1/master.cfg b/phase1/master.cfg
index 0562fcf..95a6fee 100644
--- a/phase1/master.cfg
+++ b/phase1/master.cfg
@@ -319,10 +319,12 @@ class TagChoiceParameter(BaseParameter):
 			if not line:
 				break
 
-			tagver = re.search(r'\brefs/tags/v([0-9]+\.[0-9]+\.[0-9]+(?:-rc[0-9]+)?)$', line.decode().strip())
+			(ref, tag) = line.split()
+
+			tagver = re.search(r'\brefs/tags/(v[0-9]+\.[0-9]+\.[0-9]+(?:-rc[0-9]+)?)$', tag.decode().strip())
 
 			# only list tags matching configured branches
-			if tagver and any(tagver[1].startswith(b) for b in branchvers):
+			if tagver and any(tagver[1][1:].startswith(b) for b in branchvers):
 				taglist.append(tagver[1])
 
 		taglist.sort(reverse=True, key=lambda tag: tag if re.search(r'-rc[0-9]+$', tag) else tag + '-z')
@@ -332,6 +334,32 @@ class TagChoiceParameter(BaseParameter):
 
 		return self._choice_list
 
+	def updateFromKwargs(self, properties, kwargs, **unused):
+		tag = self.getFromKwargs(kwargs)
+		properties[self.name] = tag
+
+		# find the commit matching the tag
+		findrev = subprocess.Popen(['git', 'rev-parse', 'tags/'+tag], stdout=subprocess.PIPE, cwd=work_dir+'/work.git')
+		findrev.wait(timeout=10)
+		line = findrev.stdout.readline()
+
+		if findrev.returncode!=0 or not line:
+			raise ValidationError("Couldn't find tag")
+
+		properties['force_revision'] = line.decode().strip()
+
+		# find the branch matching the tag
+		branch = None
+		branchver = re.search(r'v([0-9]+\.[0-9]+)', tag)
+		for b in branchNames:
+			if b.endswith(branchver[1]):
+				branch = b
+
+		if not branch:
+			raise ValidationError("Couldn't find branch")
+
+		properties['force_branch'] = branch
+
 	def parse_from_arg(self, s):
 		if self.strict and s not in self._choice_list:
 			raise ValidationError("'%s' does not belong to list of available choices '%s'" % (s, self._choice_list))
@@ -370,23 +398,16 @@ c['schedulers'].append(ForceScheduler(
 	),
 
 	properties = [
-		util.NestedParameter(
-			name="options",
-			label="Build Options",
-			layout="vertical",
-			fields=[
-				util.ChoiceStringParameter(
-					name    = "target",
-					label   = "Build target",
-					default = "all",
-					choices = [ "all" ] + list(targets)
-				),
-				TagChoiceParameter(
-					name    = "tag",
-					label   = "Build tag",
-					default = ""
-				)
-			]
+		util.ChoiceStringParameter(
+			name    = "target",
+			label   = "Build target",
+			default = "all",
+			choices = [ "all" ] + list(targets)
+		),
+		TagChoiceParameter(
+			name    = "tag",
+			label   = "Build tag",
+			default = ""
 		)
 	]
 ))
@@ -397,10 +418,6 @@ c['schedulers'].append(ForceScheduler(
 # what steps, and which workers can execute them.  Note that any particular build will
 # only take place on one worker.
 
-def IsTaggingRequested(step):
-	tag = step.getProperty("tag")
-	return tag and re.match(r"^[0-9]+\.[0-9]+\.[0-9]+(?:-rc[0-9]+)?$", tag)
-
 def IsNoMasterBuild(step):
 	return step.getProperty("branch") != "master"
 
@@ -426,8 +443,8 @@ def GetBaseVersion(branch):
 def GetVersionPrefix(props):
 	branch = props.getProperty("branch")
 	basever = GetBaseVersion(branch)
-	if props.hasProperty("tag") and re.match(r"^[0-9]+\.[0-9]+\.[0-9]+(?:-rc[0-9]+)?$", props["tag"]):
-		return "%s/" % props["tag"]
+	if props.hasProperty("tag") and re.match(r"^v[0-9]+\.[0-9]+\.[0-9]+(?:-rc[0-9]+)?$", props["tag"]):
+		return "%s/" % props["tag"][1:]
 	elif basever != "master":
 		return "%s-SNAPSHOT/" % basever
 	else:
@@ -505,25 +522,11 @@ def NetLockUl(props):
 	else:
 		return []
 
- at util.renderer
-def TagPropertyValue(props):
-	if props.hasProperty("options"):
-		options = props.getProperty("options")
-		if type(options) is dict:
-			return options.get("tag")
-	return None
-
 def IsTargetSelected(target):
 	def CheckTargetProperty(step):
-		try:
-			options = step.getProperty("options")
-			if type(options) is dict:
-				selected_target = options.get("target", "all")
-				if selected_target != "all" and selected_target != target:
-					return False
-		except KeyError:
-			pass
-
+		selected_target = step.getProperty("target", "all")
+		if selected_target != "all" and selected_target != target:
+			return False
 		return True
 
 	return CheckTargetProperty
@@ -641,15 +644,6 @@ for target in targets:
 		haltOnFailure = True,
 	))
 
-	# switch to tag
-	factory.addStep(ShellCommand(
-		name = "switchtag",
-		description = "Checking out Git tag",
-		command = ["git", "checkout", Interpolate("tags/v%(prop:tag:-)s")],
-		haltOnFailure = True,
-		doStepIf = IsTaggingRequested
-	))
-
 	# Verify that Git HEAD points to a tag or branch
 	# Ref: https://web.archive.org/web/20190729224316/http://lists.infradead.org/pipermail/openwrt-devel/2019-June/017809.html
 	factory.addStep(ShellCommand(
@@ -1186,7 +1180,8 @@ for target in targets:
 		name = "trigger_%s" % target,
 		description = "Triggering %s build" % target,
 		schedulerNames = [ "trigger_%s" % target ],
-		set_properties = { "reason": Property("reason"), "tag": TagPropertyValue },
+		sourceStamps = [{ "codebase": "", "branch": Property("force_branch"), "revision": Property("force_revision"), "repository": repo_url, "project": "" }],
+		set_properties = { "reason": Property("reason"), "tag": Property("tag"), },
 		doStepIf = IsTargetSelected(target),
 	))
 




More information about the lede-commits mailing list