feat: готовый бренд ZoomStage и минимальный доменный подвал (refs #12)
deploy-preland / deploy zoomstage.online (push) Successful in 44s
deploy-preland / deploy zoomstage.online (push) Successful in 44s
This commit is contained in:
1 parent
a2c3197a16
commit
ec087ea636
24 files changed
+365
-237
No files matched your search
+12
-23
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
/** preland#11: проверенный состав ресурсов; исполняется до SFTP. */
|
||||
declare(strict_types=1);
|
||||
require_once __DIR__ . '/brand-contract.php';
|
||||
|
||||
function releaseAssetBytes(string $path, string $bytes): string
|
||||
{
|
||||
@@ -20,7 +21,7 @@ function releaseStaticFiles(string $root): array
|
||||
if ($name === 'docs' && !preg_match('~^docs/[^/]+\.(svg|pdf)$~', $path)) continue;
|
||||
if ($entry->isFile()) $files[] = $path;
|
||||
}
|
||||
} elseif (preg_match('/\.css$/', $name) || $name === 'requisites.html') {
|
||||
} elseif (preg_match('/\.css$/', $name)) {
|
||||
$files[] = $name;
|
||||
}
|
||||
}
|
||||
@@ -32,7 +33,9 @@ function validateReleaseAssets(string $root): array
|
||||
{
|
||||
$manifest = json_decode((string) file_get_contents($root . '/release/assets.json'), true, 512, JSON_THROW_ON_ERROR);
|
||||
$files = $manifest['files'] ?? [];
|
||||
$required = ['docs/logo.svg', 'docs/logo-alt.svg', 'docs/privacy_policy.pdf', 'docs/public_offer.pdf', 'docs/tariffs.pdf', 'docs/user_agreement.pdf', 'requisites.html'];
|
||||
$brands = json_decode(file_get_contents($root . '/release/brands.json'), true, 512, JSON_THROW_ON_ERROR);
|
||||
foreach (array_keys($brands) as $domain) prelandBrand($root, $domain);
|
||||
$required = ['docs/logo.svg', 'docs/logo-alt.svg', 'docs/privacy_policy.pdf', 'docs/public_offer.pdf', 'docs/tariffs.pdf', 'docs/user_agreement.pdf'];
|
||||
foreach ($required as $path) {
|
||||
if (!isset($files[$path])) throw new RuntimeException('В manifest отсутствует обязательный ресурс ' . $path);
|
||||
}
|
||||
@@ -52,7 +55,7 @@ function validateReleaseAssets(string $root): array
|
||||
|
||||
function releaseFiles(string $root): array
|
||||
{
|
||||
$files = array_values(array_filter(releaseStaticFiles($root), static fn(string $path): bool => !preg_match('~^[0-9]+/~', $path)));
|
||||
$files = array_values(array_filter(releaseStaticFiles($root), static fn(string $path): bool => !preg_match('~^(?:[0-9]+/|docs/logo(?:-alt)?\.svg$)~', $path)));
|
||||
foreach (['.htaccess', 'index.php', 'i18n.php', 'template.php'] as $path) $files[] = $path;
|
||||
foreach (['components', 'messages'] as $directory) {
|
||||
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root . '/' . $directory, FilesystemIterator::SKIP_DOTS));
|
||||
@@ -67,6 +70,10 @@ function releaseFiles(string $root): array
|
||||
function verifyRemoteReleaseAssets(array $files, string $base, bool $setsOnly): void
|
||||
{
|
||||
if (!preg_match('~^https://[A-Za-z0-9.-]+$~', $base)) throw new RuntimeException('Требуется HTTPS origin');
|
||||
if (!$setsOnly) {
|
||||
$brand = prelandBrand(dirname(__DIR__), (string) parse_url($base, PHP_URL_HOST));
|
||||
foreach ($brand['logos'] as $path => $record) $files[$path]['sha256'] = $record['sha256'];
|
||||
}
|
||||
$count = 0;
|
||||
foreach ($files as $path => $record) {
|
||||
if ($setsOnly && !preg_match('~^[0-9]+/~', $path)) continue;
|
||||
@@ -88,6 +95,7 @@ function verifyPrimaryAssets(string $root, array $files): void
|
||||
$html = @file_get_contents($origin . '/?theme=light&preland_asset_check=1', false, $context);
|
||||
if ($html === false) throw new RuntimeException('Основной сайт недоступен для сверки ресурсов');
|
||||
foreach ($files as $path => $record) {
|
||||
if (str_starts_with($path, 'docs/logo')) continue;
|
||||
if (!str_starts_with($path, 'docs/') && !str_starts_with($path, 'favicon/')) continue;
|
||||
$name = basename($path === 'docs/logo.svg' ? 'logo-light.svg' : $path);
|
||||
$pattern = '~(?:src|href)=["\']([^"\']*/' . preg_quote($name, '~') . '(?:\?[^"\']*)?)["\']~';
|
||||
@@ -103,17 +111,7 @@ function verifyPrimaryAssets(string $root, array $files): void
|
||||
throw new RuntimeException('Основной сайт обновлён: синхронизируйте ' . $path . ' в Git перед выпуском');
|
||||
}
|
||||
}
|
||||
if (!preg_match('~<div[^>]*class=["\'][^"\']*\bh5\b[^"\']*["\'][^>]*>\s*Наши реквизиты\s*</div>(.*?)</div>~su', $html, $block)) throw new RuntimeException('Не найдены текущие реквизиты основного сайта');
|
||||
preg_match_all('~<p\b[^>]*>(.*?)</p>~su', $block[1], $paragraphs);
|
||||
$actual = [];
|
||||
foreach ($paragraphs[1] as $paragraph) {
|
||||
$paragraph = preg_replace('/\s+/u', ' ', $paragraph);
|
||||
$text = html_entity_decode(strip_tags(preg_replace('~</?br\b[^>]*>~i', "\n", $paragraph)), ENT_QUOTES, 'UTF-8');
|
||||
foreach (explode("\n", $text) as $line) if (trim($line) !== '') $actual[] = trim($line);
|
||||
}
|
||||
$expected = json_decode(file_get_contents($root . '/release/requisites.json'), true, 512, JSON_THROW_ON_ERROR);
|
||||
if ($actual !== $expected) throw new RuntimeException('Основной сайт обновил реквизиты; сначала синхронизируйте Git');
|
||||
fwrite(STDERR, "OK: primary logos/PDF/favicon/requisites актуальны\n");
|
||||
fwrite(STDERR, "OK: primary PDF/favicon актуальны\n");
|
||||
}
|
||||
|
||||
if (realpath($_SERVER['SCRIPT_FILENAME'] ?? '') === __FILE__) {
|
||||
@@ -123,15 +121,6 @@ if (realpath($_SERVER['SCRIPT_FILENAME'] ?? '') === __FILE__) {
|
||||
$mode = $argv[1] ?? '--check';
|
||||
if ($mode === '--files') echo implode("\n", releaseFiles($root)), "\n";
|
||||
elseif ($mode === '--primary') verifyPrimaryAssets($root, $files);
|
||||
elseif ($mode === '--stage-requisites') {
|
||||
$base = $argv[2] ?? '';
|
||||
if (!preg_match('~^https://[A-Za-z0-9.-]+$~', $base)) throw new RuntimeException('Требуется HTTPS origin');
|
||||
$context = stream_context_create(['http' => ['timeout' => 30, 'header' => "Cache-Control: no-cache\r\n"]]);
|
||||
$actual = json_decode((string) file_get_contents($base . '/config.json?requisites_check=1', false, $context), true, 512, JSON_THROW_ON_ERROR);
|
||||
$expected = json_decode(file_get_contents($root . '/release/requisites.json'), true, 512, JSON_THROW_ON_ERROR);
|
||||
if (($actual['requisites'] ?? null) !== $expected) throw new RuntimeException('Host config не получил актуальные requisites');
|
||||
echo "OK: runtime requisites актуальны\n";
|
||||
}
|
||||
elseif ($mode === '--remote' || $mode === '--stage-sets') verifyRemoteReleaseAssets($files, $argv[2] ?? '', $mode === '--stage-sets');
|
||||
elseif ($mode === '--check') echo 'OK: release assets ', count($files), "\n";
|
||||
else throw new RuntimeException('Неизвестный режим');
|
||||
|
||||
Reference in new issue
Block a user