phase1: Fix the force scheduler process
authorThibaut VARÈNE <hacks@slashdirt.org>
Wed, 26 Oct 2022 18:51:20 +0000 (20:51 +0200)
committerPetr Štetiar <ynezz@true.cz>
Mon, 15 May 2023 15:36:01 +0000 (17:36 +0200)
Signed-off-by: Thibaut VARÈNE <hacks@slashdirt.org>
phase1/master.cfg

index 0562fcf37157a2d4d156d8165e8ecd717d6c23c1..95a6feee0510a2e6761edd12f45d47ea80f20d0a 100644 (file)
@@ -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 []
 
-@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),
        ))