]> git.ipfire.org Git - pbs.git/commitdiff
monitoring: Catch errors when we cannot create a build
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 8 Sep 2023 14:48:35 +0000 (14:48 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 8 Sep 2023 14:48:35 +0000 (14:48 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/releasemonitoring.py
src/database.sql

index 7ba6308bfd40afe112c045bdcb88da5183ff9b67..8dd824b31f508909812c2f9fce46a93d5d17ee0c 100644 (file)
@@ -29,6 +29,7 @@ import shutil
 import urllib.parse
 
 from . import base
+from . import config
 from . import database
 from .decorators import *
 
@@ -718,27 +719,28 @@ class Release(base.DataObject):
                log.info("Creating build for %s from %s" % (self, build))
 
                try:
-                       # Create a new repository
-                       repo = await self.backend.repos.create(
-                               self.monitoring.distro, "Test Build for %s" % self, owner=owner)
-
                        # Create a new temporary space for the
                        async with self.backend.tempdir() as target:
                                # Create a new source package
                                file = await self._update_source_package(build.pkg, target)
 
-                               # Upload the file
-                               upload = await self.backend.uploads.create_from_local(file)
+                               if file:
+                                       # Create a new repository
+                                       repo = await self.backend.repos.create(
+                                               self.monitoring.distro, "Test Build for %s" % self, owner=owner)
 
-                       try:
-                               # Create a package
-                               package = await self.backend.packages.create(upload)
+                                       # Upload the file
+                                       upload = await self.backend.uploads.create_from_local(file)
+
+                                       try:
+                                               # Create a package
+                                               package = await self.backend.packages.create(upload)
 
-                               # Create the build
-                               build = await self.backend.builds.create(repo, package, owner=owner)
+                                               # Create the build
+                                               build = await self.backend.builds.create(repo, package, owner=owner)
 
-                       finally:
-                               await upload.delete()
+                                       finally:
+                                               await upload.delete()
 
                # If anything went wrong, then remove the repository
                except Exception as e:
@@ -762,39 +764,54 @@ class Release(base.DataObject):
                if not package.is_source():
                        raise RuntimeError("%s is not a source package" % package)
 
+               # Capture Pakfire's log
+               logger = config.PakfireLogger()
+
                # Create temporary directory to extract the package to
-               async with self.backend.tempdir() as tmp:
-                       # Path to downloaded files
-                       files = os.path.join(tmp, "files")
+               try:
+                       async with self.backend.tempdir() as tmp:
+                               # Path to downloaded files
+                               files = os.path.join(tmp, "files")
 
-                       # Path to the makefile
-                       makefile = os.path.join(tmp, "%s.nm" % package.name)
+                               # Path to the makefile
+                               makefile = os.path.join(tmp, "%s.nm" % package.name)
 
-                       # Create a Pakfire instance from this distribution
-                       async with self.monitoring.distro.pakfire() as p:
-                               # Open the archive
-                               archive = await asyncio.to_thread(p.open, package.path)
+                               # Create a Pakfire instance from this distribution
+                               async with self.monitoring.distro.pakfire(logger=logger) as p:
+                                       # Open the archive
+                                       archive = await asyncio.to_thread(p.open, package.path)
 
-                               # Extract the archive into the temporary space
-                               await asyncio.to_thread(archive.extract, path=tmp)
+                                       # Extract the archive into the temporary space
+                                       await asyncio.to_thread(archive.extract, path=tmp)
 
-                               # XXX directories are being created with the wrong permissions
-                               os.system("chmod a+x -R %s" % tmp)
+                                       # XXX directories are being created with the wrong permissions
+                                       os.system("chmod a+x -R %s" % tmp)
 
-                               # Remove any downloaded files
-                               await asyncio.to_thread(shutil.rmtree, files)
+                                       # Remove any downloaded files
+                                       await asyncio.to_thread(shutil.rmtree, files)
 
-                               # Update the makefile
-                               diff = await self._update_makefile(makefile)
+                                       # Update the makefile
+                                       diff = await self._update_makefile(makefile)
 
-                               # Log the diff
-                               log.info("Generated diff:\n%s" % diff)
+                                       # Log the diff
+                                       log.info("Generated diff:\n%s" % diff)
+
+                                       # Store the diff
+                                       self._set_attribute("diff", diff)
+
+                                       # Generate a new source package
+                                       return await asyncio.to_thread(p.dist, makefile, target)
+
+               # If we could not create a new source package, this is okay and we will continue
+               # without. However, we will log the exception...
+               except Exception as e:
+                       log.error("Could not create source package for %s" % self, exc_info=True)
 
-                               # Store the diff
-                               self._set_attribute("diff", diff)
+                       return None
 
-                               # Generate a new source package
-                               return await asyncio.to_thread(p.dist, makefile, target)
+               # Store the Pakfire log
+               finally:
+                       self._set_attribute("log", "%s" % logger)
 
        async def _update_makefile(self, path):
                """
index 959c1bf3e423353f81a620924396d1f4a517ed65..ce155aa6274abd82f08c46cfde373cedef019e80 100644 (file)
@@ -699,7 +699,8 @@ CREATE TABLE public.release_monitoring_releases (
     bug_id integer,
     build_id integer,
     diff text,
-    repo_id integer
+    repo_id integer,
+    log text
 );