Files
preland/tests/check-versioned-stage-config.php
T
Panfilov Konstantin dfbb086e2b
deploy-preland / deploy zoomstage.online (push) Skipped
deploy-preland / deploy barbariskatest (push) Successful in 19s
deploy-preland / deploy zoompixel.online (push) Successful in 19s
deploy-preland / deploy zoompixel.ru (push) Successful in 20s
chore: version single preland config
2026-10-17 07:00:16 +03:00

75 lines
3.2 KiB
PHP

<?php
/**
* Регрессия единственного рабочего конфига приленда.
*
* Stage-конфиг — единственный канонический конфиг каждого приленда. Он должен
* быть в репозитории и попадать во все FTP/SFTP-доставки без исключений.
*/
declare(strict_types=1);
$failures = [];
$root = dirname(__DIR__);
$configPath = $root . '/config.json';
$config = is_file($configPath) ? json_decode((string) file_get_contents($configPath), true) : null;
if (!is_array($config)) {
$failures[] = 'Рабочий config.json должен существовать в корне приленда и содержать валидный JSON.';
} else {
$expected = [
'host' => 'zoomzilla.ru',
'indpic' => ['1' => 1, '2' => 0, 'default' => '1'],
'theme' => ['light' => 0, 'dark' => 1, 'default' => 'dark'],
'degr' => ['1' => 1, '2' => 0, 'default' => '1'],
'registration' => ['before' => 0, 'after' => 1, 'default' => 'after'],
'bchoice' => ['a' => 1, 'b' => 0, 'default' => 'a'],
'chb' => ['a' => 1, 'b' => 0, 'default' => 'b'],
'tp' => ['1' => 0, '2' => 1, 'default' => '1'],
];
if (($config['host'] ?? null) !== $expected['host']) {
$failures[] = 'Рабочий config.json обязан направлять загрузку на zoomzilla.ru.';
}
foreach (array_diff_key($expected, ['host' => true]) as $key => $settings) {
$actual = $config['utm'][$key] ?? [];
if (($actual['weights'] ?? null) !== array_diff_key($settings, ['default' => true])
|| ($actual['default'] ?? null) !== $settings['default']) {
$failures[] = "Рабочий config.json должен сохранять stage-настройку UTM {$key}.";
}
}
}
$workflow = (string) file_get_contents($root . '/.gitea/workflows/deploy.yml');
$legacyStart = strpos($workflow, ' deploy:');
$stageStart = strpos($workflow, 'deploy-zoomstage:');
$productionStart = strpos($workflow, 'deploy-zoompixel-production:');
$legacyBlock = $legacyStart === false || $stageStart === false
? ''
: substr($workflow, $legacyStart, $stageStart - $legacyStart);
$stageBlock = $stageStart === false || $productionStart === false
? ''
: substr($workflow, $stageStart, $productionStart - $stageStart);
$productionBlock = $productionStart === false ? '' : substr($workflow, $productionStart);
foreach ([
'legacy FTP' => $legacyBlock,
'deploy-zoomstage' => $stageBlock,
'deploy-zoompixel-production' => $productionBlock,
] as $delivery => $block) {
if ($block === '' || str_contains($block, 'config\\.json$')) {
$failures[] = "{$delivery} обязан доставлять единый версионируемый config.json.";
}
}
if (is_file($root . '/config.json.example')) {
$failures[] = 'config.json.example не должен существовать: рабочий config.json единственный.';
}
if ($failures !== []) {
fwrite(STDERR, "FAILED\n- " . implode("\n- ", $failures) . "\n");
exit(1);
}
fwrite(STDOUT, "OK: versioned stage config and ZoomPixel delivery\n");