[yocto-autobuilder2][PATCH 4/4] builders/runconfig: Terminate release builds if output directory already exists

Yoann Congal <[email protected]>
Newsgroups org.yoctoproject.lists.yocto-patches
Message-ID <[email protected]>
From: Yoann Congal <[email protected]>

Add a new step "CheckReleaseDir" that, on release builds, check if the
release artefact directory already exist, if it does, terminate the
build before corrupting it.

Fixes [YOCTO #15937]

Signed-off-by: Yoann Congal <[email protected]>
---
 builders.py        |  3 ++-
 steps/runconfig.py | 21 +++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/builders.py b/builders.py
index 721adc5..40873a7 100644
--- a/builders.py
+++ b/builders.py
@@ -7,7 +7,7 @@ from buildbot.plugins import *
 from yoctoabb import config
 from yoctoabb.steps.writelayerinfo import WriteLayerInfo
 from yoctoabb.steps.writebbsetupjson import WriteBBSetupJson
-from yoctoabb.steps.runconfig import get_publish_dest, get_publish_resultdir, get_publish_name, RunConfigCheckSteps, TargetPresent
+from yoctoabb.steps.runconfig import get_publish_dest, get_publish_resultdir, get_publish_name, RunConfigCheckSteps, TargetPresent, CheckReleaseDir
 from buildbot.process.results import Results, SUCCESS, FAILURE, CANCELLED, WARNINGS, SKIPPED, EXCEPTION, RETRY
 from buildbot.process.remotecommand import RemoteCommand
 from buildbot.data import resultspec
@@ -317,6 +317,7 @@ def create_parent_builder_factory(buildername, waitname):
         mode='incremental',
         haltOnFailure=True,
         name='Fetch yocto-autobuilder-helper'))
+    factory.addStep(CheckReleaseDir(haltOnFailure=True))
     factory.addStep(WriteLayerInfo(name='Write main layerinfo.json', haltOnFailure=True))
     factory.addStep(WriteBBSetupJson(name='Write bbsetup-overrides.json', haltOnFailure=True))
     factory.addStep(steps.ShellCommand(
diff --git a/steps/runconfig.py b/steps/runconfig.py
index 18cdd7a..d52c7cd 100644
--- a/steps/runconfig.py
+++ b/steps/runconfig.py
@@ -237,3 +237,24 @@ class TargetPresent(shell.ShellCommand):
         cmd = yield self.makeRemoteShellCommand()
         yield self.runCommand(cmd)
         return self.evaluateCommand(cmd)
+
+class CheckReleaseDir(buildstep.BuildStep):
+    name = "Check if release directory already exists"
+    description = ["checking release directory"]
+    descriptionDone = ["checked release directory"]
+
+    def __init__(self, **kwargs):
+        buildstep.BuildStep.__init__(self, **kwargs)
+
+    @defer.inlineCallbacks
+    def run(self):
+        is_release = self.getProperty("is_release", False)
+        deploy_artefacts = self.getProperty("deploy_artefacts", False)
+        if is_release and deploy_artefacts:
+            dest = get_publish_internal(self.build.properties)
+            if dest and os.path.exists(dest):
+                self.descriptionDone = [f"Release directory {dest} already exists!"]
+                yield add_to_log(self, "error", f"Release directory already exists: {dest}\n")
+                return FAILURE
+        return SUCCESS
+
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.