Skip to content

Commit f2d527f

Browse files
committed
Report silent build command failures
1 parent fee06ee commit f2d527f

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

src/Executor/Runner/Docker.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,12 @@ public function createRuntime(
386386
);
387387

388388
if (!$status) {
389-
throw new ExecutorException(ExecutorException::RUNTIME_FAILED, 'Failed to create runtime: ' . $stdout);
389+
$message = \trim($stdout);
390+
391+
throw new ExecutorException(
392+
ExecutorException::RUNTIME_FAILED,
393+
$message === '' ? 'Build command failed.' : $message
394+
);
390395
}
391396

392397
if ($version === 'v2') {
@@ -545,14 +550,14 @@ private function getBuildCommands(string $command, string $version): array
545550
return [
546551
'sh',
547552
'-c',
548-
'touch /var/tmp/logs.txt && (' . $command . ') >> /var/tmp/logs.txt 2>&1 && cat /var/tmp/logs.txt'
553+
'touch /var/tmp/logs.txt && (' . $command . ') >> /var/tmp/logs.txt 2>&1; status=$?; cat /var/tmp/logs.txt; if [ $status -ne 0 ] && [ ! -s /var/tmp/logs.txt ]; then echo "Build command exited with code $status."; fi; exit $status'
549554
];
550555
}
551556

552557
return [
553558
'bash',
554559
'-c',
555-
'mkdir -p /tmp/logging && touch /tmp/logging/timings.txt && touch /tmp/logging/logs.txt && script --log-out /tmp/logging/logs.txt --flush --log-timing /tmp/logging/timings.txt --return --quiet --command "' . \str_replace('"', '\"', $command) . '"'
560+
'mkdir -p /tmp/logging && touch /tmp/logging/timings.txt && touch /tmp/logging/logs.txt && script --log-out /tmp/logging/logs.txt --flush --log-timing /tmp/logging/timings.txt --return --quiet --command "' . \str_replace('"', '\"', $command) . '"; status=$?; if [ $status -ne 0 ] && [ ! -s /tmp/logging/logs.txt ]; then echo "Build command exited with code $status."; fi; exit $status'
556561
];
557562
}
558563

tests/unit/Executor/Runner/DockerTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ public function testNoCacheLifecycleShellCommandsAreGenerated(): void
4444
$this->assertStringNotContainsString('build-cache-save.sh', $command);
4545
}
4646

47+
public function testBuildCommandsReportSilentNonZeroExit(): void
48+
{
49+
$docker = $this->createDocker();
50+
51+
foreach (['v2', 'v5'] as $version) {
52+
$commands = $this->invokeGetBuildCommands($docker, 'exit 1', $version);
53+
$command = \implode(' ', $commands);
54+
55+
$this->assertStringContainsString('Build command exited with code $status.', $command);
56+
$this->assertStringContainsString('exit $status', $command);
57+
}
58+
}
59+
4760
public function testInvalidBuildCacheKeyIsRejected(): void
4861
{
4962
$this->expectException(\Exception::class);

0 commit comments

Comments
 (0)