Files
compras/scripts/purchasing-release.php
T
2026-11-02 08:08:05 +02:00

51 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
use Symfony\Component\Process\Process;
use Tempo\Distribution\Release;
// Identical tooling in both compositions; distribution artifacts are pinned copies.
require_once dirname(__DIR__).'/packages/module-updates/Release.php';
try {
$action = $argv[1] ?? '';
if ($action === 'publish' && count($argv) === 4) {
$result = Release::publish($argv[2], $argv[3]);
} elseif ($action === 'inspect' && count($argv) === 4) {
$result = Release::inspect($argv[2], $argv[3])['manifest'];
} elseif ($action === 'install' && count($argv) === 5) {
require_once dirname(__DIR__).'/vendor/autoload.php';
$host = realpath($argv[2]);
$archive = realpath($argv[3]);
if ($host === false || $archive === false) {
throw new RuntimeException('Instalação ou pacote inexistente.');
}
// Execute only the approved candidate, in an isolated PHP process, before switching.
$probe = new Process([PHP_BINARY, dirname(__DIR__).'/scripts/purchasing-probe.php', $archive, $argv[4]], dirname(__DIR__), timeout: 30);
$probe->mustRun();
$result = Release::install($argv[2], $argv[3], $argv[4]);
$result['runtime_probe'] = json_decode($probe->getOutput(), true, 32, JSON_THROW_ON_ERROR);
} elseif ($action === 'status' && count($argv) === 3) {
$result = Release::current($argv[2]) ?? ['installed' => false];
} elseif ($action === 'rollback' && count($argv) === 3) {
$result = Release::rollback($argv[2]);
} elseif ($action === 'check' && count($argv) === 5) {
$candidate = Release::inspect($argv[3], $argv[4])['manifest'];
$current = Release::current($argv[2]);
if ($current !== null && $current['version'] === $candidate['version'] && $current['manifest_sha256'] !== $argv[4]) {
throw new RuntimeException('A mesma versão tem conteúdo diferente; reconcilie o canal antes de actualizar.');
}
$result = ['installed_version' => $current['version'] ?? null, 'candidate_version' => $candidate['version'],
'available' => $current === null || version_compare($candidate['version'], $current['version'], '>'),
'same_source' => ($current['source_sha256'] ?? null) === $candidate['source_sha256'],
'database_changes' => false, 'permissions_changed' => false];
} else {
throw new RuntimeException('Uso: publish <pacote-origem> <canal>; inspect <zip> <sha-manifesto>; check <host> <zip> <sha-manifesto>; install <host> <zip> <sha-manifesto>; status <host>.');
}
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR)."\n";
} catch (Throwable $error) {
fwrite(STDERR, $error->getMessage()."\n");
exit(1);
}