From 3335f56cf6303f0fa77a6a14c234fc5964f698ab Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Tue, 20 May 2025 21:15:05 +0530 Subject: [PATCH] Append build error to build logs --- .../Modules/Functions/Workers/Builds.php | 2 +- .../Services/Sites/SitesCustomServerTest.php | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 27c6e59128..257d596779 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -1222,7 +1222,7 @@ class Builds extends Action $deployment->setAttribute('buildEndedAt', $endTime); $deployment->setAttribute('buildDuration', \intval(\ceil($durationEnd - $durationStart))); $deployment->setAttribute('status', 'failed'); - $deployment->setAttribute('buildLogs', $message); + $deployment->setAttribute('buildLogs', $deployment->getAttribute('buildLogs', '') . "\n" . $message); $deployment = $dbForProject->updateDocument('deployments', $deploymentId, $deployment); diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index dd4efa5932..d3b4922b87 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -2651,4 +2651,46 @@ class SitesCustomServerTest extends Scope $this->cleanupSite($siteId); } + + public function testBuildErrorLogs(): void + { + $siteId = $this->setupSite([ + 'siteId' => ID::unique(), + 'name' => 'Astro SSR site', + 'framework' => 'astro', + 'buildRuntime' => 'node-22', + 'outputDirectory' => './dist', + 'buildCommand' => 'npm run build', + 'installCommand' => 'echo "custom error" && npm install', + 'adapter' => 'ssr', + ]); + $this->assertNotEmpty($siteId); + + $site = $this->getSite($siteId); + $this->assertEquals('200', $site['headers']['status-code']); + + $domain = $this->setupSiteDomain($siteId); + $this->assertNotEmpty($domain); + + $deployment = $this->createDeployment($siteId, [ + 'code' => $this->packageSite('astro-static'), + 'activate' => true + ]); + $this->assertEquals(202, $deployment['headers']['status-code']); + + $deploymentId = $deployment['body']['$id']; + $this->assertNotEmpty($deploymentId); + + $this->assertEventually(function () use ($siteId, $deploymentId) { + $deployment = $this->getDeployment($siteId, $deploymentId); + $this->assertEquals('failed', $deployment['body']['status'], 'Deployment status is failed, deployment: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT)); + }, 100000, 500); + + $deployment = $this->getDeployment($siteId, $deploymentId); + $this->assertEquals(200, $deployment['headers']['status-code']); + $this->assertStringContainsString('custom error', $deployment['body']['buildLogs']); + $this->assertStringContainsString('Adapter mismatch', $deployment['body']['buildLogs']); + + $this->cleanupSite($siteId); + } }