fix: address review findings in deploy-and-verify.php
Universal: PR Check / Branch Policy (pull_request) Failing after 2s
Generic: Repo Health / Access control (pull_request) Successful in 2s
Generic: Repo Health / Site Health (pull_request) Has been skipped
Universal: PR Check / Validate PR (pull_request) Failing after 9s
Universal: PR Check / Secret Scan (pull_request) Successful in 10s
Universal: Auto Version Bump / Version Bump (push) Successful in 11s
Platform: mokoplatform CI / Gate 1: Code Quality (pull_request) Failing after 56s
Platform: mokoplatform CI / Gate 2: Unit Tests (8.1) (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 2: Unit Tests (8.2) (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 2: Unit Tests (8.3) (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 3: Self-Health Check (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 4: Governance (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 5: Template Integrity (pull_request) Has been cancelled
Platform: mokoplatform CI / CI Summary (pull_request) Has been cancelled
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Universal: PR Check / Report Issues (pull_request) Has been cancelled
Generic: Repo Health / Scripts governance (pull_request) Has been cancelled
Generic: Repo Health / Repository health (pull_request) Has been cancelled
Generic: Repo Health / Report Issues (pull_request) Has been cancelled

- Fix #1: replace rm -rf with cross-platform PHP removeDirectory()
- Fix #2: sanitize URL in audit log (log hostname only)
- Fix #3: remove unused buildHealthArgs() and $healthArgs
- Fix #4: add random suffix to snapshot dir name for uniqueness
- Fix #5: fix constructor to match CliFramework pattern (no args)
- Fix #6: trigger rollback on deploy failure (partial deploy risk)
This commit is contained in:
Jonathan Miller
2026-06-20 23:40:54 -05:00
parent 19aa0111f0
commit 4fc3d0a4a9
+24 -11
View File
@@ -70,15 +70,14 @@ class DeployAndVerify extends CliFramework
// Non-fatal — proceed without audit logging
}
$this->audit('start', ['path' => $path, 'env' => $env, 'url' => $url]);
$this->audit('start', ['path' => $path, 'env' => $env, 'url' => parse_url($url, PHP_URL_HOST) ?? $url]);
// ── Build subprocess args ────────────────────────────────────
$deployArgs = $this->buildDeployArgs($path, $env, $config);
$healthArgs = $this->buildHealthArgs($url, $checks, $timeout);
// ── Step 1: Backup ───────────────────────────────────────────
$this->section('Step 1: Pre-deploy backup');
$snapshotDir = sys_get_temp_dir() . '/moko_deploy_snapshot_' . date('Ymd_His') . '_' . getmypid();
$snapshotDir = sys_get_temp_dir() . '/moko_deploy_snapshot_' . date('Ymd_His') . '_' . getmypid() . '_' . bin2hex(random_bytes(4));
if ($this->dryRun) {
$this->log('INFO', "[dry-run] Would create snapshot at {$snapshotDir}");
@@ -104,8 +103,11 @@ class DeployAndVerify extends CliFramework
$deployExit = $this->runSubprocess('deploy-sftp.php', $deployArgs);
if ($deployExit !== 0) {
$this->log('ERROR', 'Deploy failed — no rollback needed (files unchanged)');
$this->log('ERROR', 'Deploy failed — rolling back to pre-deploy state');
$this->audit('deploy_failed', ['exit_code' => $deployExit]);
$this->runSubprocess('rollback-joomla.php', array_merge(
$deployArgs, ['--snapshot-dir', $snapshotDir]
));
$this->cleanup($snapshotDir);
return self::EXIT_FAILURE;
}
@@ -297,11 +299,6 @@ class DeployAndVerify extends CliFramework
return $args;
}
private function buildHealthArgs(string $url, string $checks, int $timeout): array
{
return ['--url', $url, '--checks', $checks, '--timeout', (string) $timeout];
}
// ── Audit ────────────────────────────────────────────────────────
private function audit(string $event, array $data): void
@@ -321,11 +318,27 @@ class DeployAndVerify extends CliFramework
private function cleanup(string $snapshotDir): void
{
if (is_dir($snapshotDir)) {
exec(sprintf('rm -rf %s', escapeshellarg($snapshotDir)));
$this->removeDirectory($snapshotDir);
$this->log('DEBUG', "Cleaned up snapshot: {$snapshotDir}");
}
}
private function removeDirectory(string $dir): void
{
$entries = scandir($dir);
if ($entries === false) {
return;
}
foreach ($entries as $entry) {
if ($entry === '.' || $entry === '..') {
continue;
}
$path = $dir . DIRECTORY_SEPARATOR . $entry;
is_dir($path) ? $this->removeDirectory($path) : unlink($path);
}
rmdir($dir);
}
}
$app = new DeployAndVerify('deploy_and_verify', 'Deploy with automatic health check and rollback');
$app = new DeployAndVerify();
exit($app->execute());