1
0
mirror of git://f0xx.org/ac/ac-ms-build synced 2026-08-12 18:13:16 +03:00
Files
ac-ms-build/public/api/build_webhook.php
Anton Afanasyeu 1fa8da68d5 Builder: docker home env + Gitea CI webhook status.
Export HOME/DOCKER_CONFIG for nobody PHP-FPM, improve docker health
checks, and report build status to Gitea when enabled.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-07 22:15:26 +02:00

33 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/../../src/bootstrap.php';
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
json_out(['ok' => false, 'error' => 'POST required'], 405);
}
$secret = trim((string) cfg('build.webhook_secret', ''));
$raw = file_get_contents('php://input') ?: '';
$sig = (string) ($_SERVER['HTTP_X_GITEA_SIGNATURE'] ?? $_SERVER['HTTP_X_HUB_SIGNATURE_256'] ?? '');
if ($secret !== '') {
$expected = hash_hmac('sha256', $raw, $secret);
if ($sig === '' || !hash_equals($expected, $sig)) {
json_out(['ok' => false, 'error' => 'bad_signature'], 403);
}
}
$payload = json_decode($raw, true);
if (!is_array($payload)) {
json_out(['ok' => false, 'error' => 'invalid_json'], 400);
}
try {
$build = BuildRunner::enqueueFromWebhook($payload);
json_out(['ok' => true, 'build' => $build]);
} catch (InvalidArgumentException $e) {
json_out(['ok' => false, 'error' => $e->getMessage()], 422);
} catch (Throwable $e) {
error_log('build_webhook: ' . $e->getMessage());
json_out(['ok' => false, 'error' => 'enqueue_failed'], 500);
}