]> git.ipfire.org Git - pbs.git/commitdiff
builds: Send an email if test builds fail
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 12 May 2023 20:33:17 +0000 (20:33 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 12 May 2023 20:33:17 +0000 (20:33 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/buildservice/builds.py
src/templates/builds/messages/test-builds-failed.txt [new file with mode: 0644]

index a851be675befe073ae57323837132a3606bac12f..4a5bea45a288d7853a0c12dc4a38d3719dec43df 100644 (file)
@@ -196,7 +196,8 @@ templates_builds_groups_modulesdir = $(templates_builds_groupsdir)/modules
 dist_templates_builds_messages_DATA = \
        src/templates/builds/messages/comment.txt \
        src/templates/builds/messages/failed.txt \
-       src/templates/builds/messages/finished.txt
+       src/templates/builds/messages/finished.txt \
+       src/templates/builds/messages/test-builds-failed.txt
 
 templates_builds_messagesdir = $(templates_buildsdir)/messages
 
index e4f0bf2d864aade31494cd9d44ad39e362fb8f74..256234fdc565c427cdad3a625fab2131a1ee3a69 100644 (file)
@@ -1002,6 +1002,15 @@ class Build(base.DataObject):
 
        test_builds = lazy_property(get_test_builds, set_test_builds)
 
+       async def _test_builds_finished(self, success):
+               """
+                       Called when all test builds have finished
+               """
+               # Send an email on fail
+               if not success:
+                       self._send_email("builds/messages/test-builds-failed.txt",
+                               build=self, test_builds=self.test_builds)
+
 
 class Groups(base.Object):
        """
@@ -1229,7 +1238,9 @@ class Group(base.DataObject):
                # Mark as finished
                self._set_attribute_now("finished_at")
 
-               # XXX call the build that that has created this group for test builds
+               # Call the build that has created this test group
+               if self.tested_build:
+                       await self.tested_build._test_builds_finished(success=not self.has_failed())
 
        async def failed(self):
                """
diff --git a/src/templates/builds/messages/test-builds-failed.txt b/src/templates/builds/messages/test-builds-failed.txt
new file mode 100644 (file)
index 0000000..72414ea
--- /dev/null
@@ -0,0 +1,21 @@
+To: {{ recipient.email_to }}
+Subject: [{{ build }}] {{ _("Test Builds Failed") }}
+Message-Id: <build-{{ build.uuid }}-tests-failed@pakfire.ipfire.org>
+In-Reply-To: <build-{{ build.uuid }}-finished@pakfire.ipfire.org>
+References: <build-{{ build.uuid }}-finished@pakfire.ipfire.org>
+
+{{ _("Hello %s,") % recipient }}
+
+{{ _("This is an automated email to let you know that the automated test build for your build has failed:",
+       "This is an automated email to let you know that the automated test builds for your build have failed:",
+       len(test_builds)) }}
+
+       /builds/{{ build.uuid }}
+
+{{ _("Test Builds") }}:
+
+{% for t in test_builds %}
+       * {% if t.is_successful() %}SUCCESS{% elif t.has_failed() %}FAILED {% end %} {{ t }}{% end %}
+
+{{ _("Sincerely,") }}
+-{{ _("The Pakfire Build Service") }}