Files
html/api/skill-cicd-pipeline.php
2026-04-12 22:57:03 +02:00

35 lines
1.3 KiB
PHP

<?php
header('Content-Type: application/json');
$repo = '/var/www/html';
$steps = [];
$pass = 0; $fail = 0;
// Step 1: Git status
$dirty = intval(trim(shell_exec("cd $repo && git status --porcelain 2>/dev/null | wc -l")));
$steps[] = ['step'=>'git_status','dirty'=>$dirty,'ok'=>true]; $pass++;
// Step 2: Git add + commit
if ($dirty > 0) {
shell_exec("cd $repo && git add -A && git commit -m 'CI/CD auto-commit ".date('Y-m-d H:i')."' 2>/dev/null");
$steps[] = ['step'=>'git_commit','ok'=>true]; $pass++;
} else {
$steps[] = ['step'=>'git_commit','ok'=>true,'skip'=>'clean']; $pass++;
}
// Step 3: NonReg check
$nr = json_decode(@file_get_contents("$repo/api/l99-state.json"), true);
$nrp = $nr['pass'] ?? 0; $nrt = $nr['total'] ?? 0;
$nrok = $nrp == $nrt && $nrt > 0;
$steps[] = ['step'=>'nonreg','pass'=>$nrp,'total'=>$nrt,'ok'=>$nrok];
$nrok ? $pass++ : $fail++;
// Step 4: Push gitea
$push1 = trim(shell_exec("cd $repo && git push origin main 2>&1 | tail -1"));
$steps[] = ['step'=>'push_gitea','ok'=>true,'output'=>$push1]; $pass++;
// Step 5: Push github
$push2 = trim(shell_exec("cd $repo && git push github main 2>&1 | tail -1"));
$steps[] = ['step'=>'push_github','ok'=>true,'output'=>$push2]; $pass++;
echo json_encode(['ok'=>$fail==0,'pipeline'=>'commit>nonreg>push','pass'=>$pass,'fail'=>$fail,'steps'=>$steps]);