payfrit-api/_webhook/deploy.php

28 lines
832 B
PHP

<?php
header('Content-Type: application/json');
$secret = 'payfrit-deploy-2026';
$headerSecret = $_SERVER['HTTP_X_FORGEJO_SIGNATURE'] ?? $_GET['secret'] ?? '';
if ($headerSecret !== $secret) {
http_response_code(403);
echo json_encode(['OK' => false, 'ERROR' => 'unauthorized']);
exit;
}
// Run git pull directly
$repoPath = dirname(__DIR__);
$output = [];
$exitCode = 0;
exec("cd " . escapeshellarg($repoPath) . " && git pull origin main 2>&1", $output, $exitCode);
// Also write trigger file for backward compatibility
$triggerFile = '/tmp/deploy-payfrit-api.trigger';
file_put_contents($triggerFile, date('Y-m-d H:i:s'));
echo json_encode([
'OK' => $exitCode === 0,
'MESSAGE' => $exitCode === 0 ? 'Deploy successful' : 'Deploy failed',
'OUTPUT' => implode("\n", $output),
'TIME' => date('c')
]);