1
0
mirror of git://f0xx.org/ac/ac-ms-build synced 2026-08-12 18:13:16 +03:00

BuildRunner: failBuild on artifact dir errors; notifier sendmail fallback.

Mirror ac-be-builder enqueue/notification fixes in shared build module.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Anton Afanasyeu
2026-08-07 22:45:52 +02:00
parent 1fa8da68d5
commit 42030a59b9
2 changed files with 43 additions and 10 deletions

View File

@@ -47,6 +47,9 @@ final class BuildNotifier {
self::sendPlainEmail($to, $subject, nl2br(h($bodyText)), self::smtpConfig());
}
}
// Lab default: always alert admin_email (and Telegram when configured).
self::notifyAdmin($subject, $bodyText, $code, $safeError, $detailUrl);
}
private static function notifyAdmin(string $subject, string $bodyText, string $code, string $safeError, string $detailUrl): void {
@@ -106,15 +109,20 @@ final class BuildNotifier {
if (is_array($cached)) {
return $cached;
}
$path = (string) cfg(
'build.notify.broadcast_config',
'/var/www/ac/broadcast/config/config.php'
);
$paths = array_values(array_unique(array_filter([
(string) cfg('build.notify.broadcast_config', ''),
'/var/www/ac/broadcast/config/config.php',
'/var/www/ac/workspace/ac-ms-broadcast/config/config.php',
])));
foreach ($paths as $path) {
if ($path !== '' && is_file($path)) {
$cfg = require $path;
$cached = is_array($cfg) ? $cfg : [];
if (is_array($cfg)) {
$cached = $cfg;
return $cached;
}
}
}
$cached = [];
return $cached;
}
@@ -187,7 +195,13 @@ final class BuildNotifier {
/** @param array<string, mixed> $smtp */
private static function sendPlainEmail(string $to, string $subject, string $htmlBody, array $smtp): void {
if ($to === '' || empty($smtp['user']) || empty($smtp['pass'])) {
if ($to === '') {
return;
}
$transport = strtolower((string) cfg('mail.transport', 'smtp'));
$hasSmtpCreds = !empty($smtp['user']) && !empty($smtp['pass']);
if ($transport === 'sendmail' || !$hasSmtpCreds) {
self::sendMailTransport($to, $subject, $htmlBody);
return;
}
$host = (string) ($smtp['host'] ?? 'smtp.gmail.com');
@@ -233,4 +247,17 @@ final class BuildNotifier {
$send('QUIT');
fclose($sock);
}
private static function sendMailTransport(string $to, string $subject, string $htmlBody): void {
$from = (string) cfg('mail.from', 'Android Cast <noreply@apps.f0xx.org>');
$replyTo = (string) cfg('mail.reply_to', '');
$plain = strip_tags(str_replace(['<br>', '<br/>', '<br />'], "\n", $htmlBody));
$headers = "From: {$from}\r\n";
if ($replyTo !== '') {
$headers .= "Reply-To: {$replyTo}\r\n";
}
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
@mail($to, $subject, $htmlBody, $headers);
}
}

View File

@@ -133,7 +133,13 @@ YAML;
]);
$dir = self::artifactDir($id);
if (!is_dir($dir) && !mkdir($dir, 0775, true) && !is_dir($dir)) {
throw new RuntimeException('Cannot create artifact dir: ' . $dir);
self::failBuild(
$id,
'Cannot create artifact dir: ' . $dir
. ' (check prepare-be-builder-dirs.sh: builds/ must be writable by PHP-FPM user nobody)',
null
);
return BuildRepository::getById($id) ?? ['id' => $id, 'build_code' => $buildCode, 'status' => 'failed'];
}
$logPath = $dir . '/build.log';
BuildRepository::update($id, ['log_path' => $logPath]);