Обновление ядра: база от ядра, core:resolve, --remote через codeload, версия при sync
This commit is contained in:
1 parent
99e1d9431c
commit
470db48bce
14 files changed
+647
-191
No files matched your search
@@ -90,6 +90,7 @@ final class Application
|
||||
Commands\CoreCheckCommand::class,
|
||||
Commands\CoreDiffCommand::class,
|
||||
Commands\CoreSyncCommand::class,
|
||||
Commands\CoreResolveCommand::class,
|
||||
Commands\CoreLatestCommand::class,
|
||||
],
|
||||
];
|
||||
|
||||
@@ -8,10 +8,12 @@ use Rsgrinko\Proton\Console\Command;
|
||||
use Rsgrinko\Proton\Core\Updater;
|
||||
|
||||
/**
|
||||
* проверяет framework/ на локальные правки в обход правила «ядро не патчим».
|
||||
* показывает, чем framework/ отличается от ядра последней синхронизации.
|
||||
*/
|
||||
final class CoreCheckCommand extends Command
|
||||
{
|
||||
use UsesCoreSource;
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'core:check';
|
||||
@@ -19,12 +21,12 @@ final class CoreCheckCommand extends Command
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'сверяет framework/ со своей последней синхронизацией; --baseline фиксирует текущее состояние как доверенное';
|
||||
return 'сверяет framework/ с ядром последней синхронизации; --baseline заводит базу (от ядра через --path/--remote)';
|
||||
}
|
||||
|
||||
public function usage(): string
|
||||
{
|
||||
return 'core:check [--baseline]';
|
||||
return 'core:check [--baseline [--path=<ядро той версии, от которой заведён проект> | --remote]]';
|
||||
}
|
||||
|
||||
public function run(): int
|
||||
@@ -32,14 +34,11 @@ final class CoreCheckCommand extends Command
|
||||
$updater = new Updater(APP_ROOT);
|
||||
|
||||
if ($this->hasOption('baseline')) {
|
||||
$updater->saveBaseline();
|
||||
$this->ok('Текущее состояние framework/ сохранено как доверенное (framework/.checksums.json)');
|
||||
|
||||
return 0;
|
||||
return $this->baseline($updater);
|
||||
}
|
||||
|
||||
if ($updater->storedBaseline() === []) {
|
||||
$this->fail('Доверенного состояния ещё нет — сначала: php bin/proton core:check --baseline');
|
||||
$this->fail('Доверенного состояния ещё нет — сначала: php bin/proton core:check --baseline --path=<ядро>');
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -47,12 +46,12 @@ final class CoreCheckCommand extends Command
|
||||
$changed = $updater->check();
|
||||
|
||||
if ($changed === []) {
|
||||
$this->ok('framework/ не менялся с последней синхронизации');
|
||||
$this->ok('framework/ совпадает с ядром последней синхронизации');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->fail('Локально изменены (в обход правила «не трогать ядро руками»):');
|
||||
$this->fail('Отличаются от ядра (свои правки или неразобранное ручное слияние):');
|
||||
|
||||
foreach ($changed as $path) {
|
||||
$this->line(' ' . $path);
|
||||
@@ -60,4 +59,31 @@ final class CoreCheckCommand extends Command
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
private function baseline(Updater $updater): int
|
||||
{
|
||||
if (!$this->hasOption('path') && !$this->hasOption('remote')) {
|
||||
$updater->saveBaseline();
|
||||
$this->ok('База — текущий framework/ (framework/.checksums.json)');
|
||||
$this->line('Верно, только если в framework/ нет своих правок: иначе они станут невидимы');
|
||||
$this->line('и следующее обновление ядра их затрёт. С правками — --path=<ядро той же версии>.');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$path = $this->coreSource($updater);
|
||||
|
||||
if ($path === null) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
$updater->saveBaseline($path);
|
||||
$this->ok('База — ядро ' . $updater->readVersion($path) . ' (framework/.checksums.json)');
|
||||
} finally {
|
||||
$this->releaseCoreSource($updater);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,6 @@ namespace Rsgrinko\Proton\Console\Commands;
|
||||
|
||||
use Rsgrinko\Proton\Console\Command;
|
||||
use Rsgrinko\Proton\Core\Updater;
|
||||
use Rsgrinko\Proton\Support\Config;
|
||||
use Rsgrinko\Proton\Support\ProtonException;
|
||||
|
||||
/**
|
||||
* что можно взять из ядра, что требует ручного слияния, что ядро больше не
|
||||
@@ -15,6 +13,8 @@ use Rsgrinko\Proton\Support\ProtonException;
|
||||
*/
|
||||
final class CoreDiffCommand extends Command
|
||||
{
|
||||
use UsesCoreSource;
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'core:diff';
|
||||
@@ -35,37 +35,21 @@ final class CoreDiffCommand extends Command
|
||||
$updater = new Updater(APP_ROOT);
|
||||
|
||||
if ($updater->storedBaseline() === []) {
|
||||
$this->fail('Доверенного состояния ещё нет — сначала: php bin/proton core:check --baseline');
|
||||
$this->fail('Доверенного состояния ещё нет — сначала: php bin/proton core:check --baseline --path=<ядро>');
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$path = $this->option('path', '');
|
||||
$temporary = null;
|
||||
$path = $this->coreSource($updater);
|
||||
|
||||
if ($path === null || $path === '') {
|
||||
if (!$this->hasOption('remote')) {
|
||||
$this->fail('Нужен --path=<каталог> или --remote');
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
$path = $temporary = $updater->downloadRemote(
|
||||
(string) Config::get('core.repo'),
|
||||
(string) Config::get('core.branch')
|
||||
);
|
||||
} catch (ProtonException $e) {
|
||||
$this->fail($e->getMessage());
|
||||
|
||||
return 1;
|
||||
}
|
||||
if ($path === null) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
$report = $updater->diff($path);
|
||||
|
||||
if ($temporary !== null) {
|
||||
$updater->cleanupRemote($temporary);
|
||||
try {
|
||||
$report = $updater->diff($path);
|
||||
} finally {
|
||||
$this->releaseCoreSource($updater);
|
||||
}
|
||||
|
||||
$this->printReport($report);
|
||||
@@ -88,6 +72,10 @@ final class CoreDiffCommand extends Command
|
||||
$this->line('Требуют ручного слияния:');
|
||||
$this->printList($report['manual'], 'пусто');
|
||||
|
||||
if ($report['manual'] !== []) {
|
||||
$this->line(' слили руками — php bin/proton core:resolve <файл> с тем же --path/--remote');
|
||||
}
|
||||
|
||||
$this->line();
|
||||
$this->line('Ядро больше не содержит:');
|
||||
$this->printList($report['removed'], 'пусто');
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rsgrinko\Proton\Console\Commands;
|
||||
|
||||
use Rsgrinko\Proton\Console\Command;
|
||||
use Rsgrinko\Proton\Core\Updater;
|
||||
|
||||
/**
|
||||
* отмечает файлы из ручного слияния разобранными: предком для них становится
|
||||
* версия ядра, и diff перестаёт их показывать, пока ядро не поменяет файл снова.
|
||||
*/
|
||||
final class CoreResolveCommand extends Command
|
||||
{
|
||||
use UsesCoreSource;
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'core:resolve';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'отмечает файлы ручного слияния разобранными (--path=<каталог> или --remote)';
|
||||
}
|
||||
|
||||
public function usage(): string
|
||||
{
|
||||
return 'core:resolve <файл> [<файл>...] --path=<каталог с ядром рядом> | --remote';
|
||||
}
|
||||
|
||||
public function run(): int
|
||||
{
|
||||
$files = [];
|
||||
|
||||
for ($i = 0; $this->arg($i) !== ''; $i++) {
|
||||
$files[] = $this->arg($i);
|
||||
}
|
||||
|
||||
if ($files === []) {
|
||||
$this->fail('Укажите файлы из списка ручного слияния: core:resolve framework/Support/Csv.php --path=../proton');
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$updater = new Updater(APP_ROOT);
|
||||
$path = $this->coreSource($updater);
|
||||
|
||||
if ($path === null) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
$unknown = $updater->resolve($path, $files);
|
||||
|
||||
foreach ($unknown as $file) {
|
||||
$this->fail('Нет ни в ядре, ни в базе, пропущен: ' . $file);
|
||||
}
|
||||
|
||||
$manual = $updater->diff($path)['manual'];
|
||||
|
||||
if ($manual !== []) {
|
||||
$this->line('Ещё ждут ручного слияния:');
|
||||
|
||||
foreach ($manual as $file) {
|
||||
$this->line(' ' . $file);
|
||||
}
|
||||
|
||||
return $unknown === [] ? 0 : 1;
|
||||
}
|
||||
|
||||
$this->ok('Ручное слияние разобрано, версия ядра: ' . $updater->adoptVersion($path));
|
||||
$this->line('Дальше: php bin/proton test');
|
||||
|
||||
return $unknown === [] ? 0 : 1;
|
||||
} finally {
|
||||
$this->releaseCoreSource($updater);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,6 @@ namespace Rsgrinko\Proton\Console\Commands;
|
||||
|
||||
use Rsgrinko\Proton\Console\Command;
|
||||
use Rsgrinko\Proton\Core\Updater;
|
||||
use Rsgrinko\Proton\Support\Config;
|
||||
use Rsgrinko\Proton\Support\ProtonException;
|
||||
|
||||
/**
|
||||
* копирует из ядра то, что безопасно копировать. Без --apply — тот же план,
|
||||
@@ -15,6 +13,8 @@ use Rsgrinko\Proton\Support\ProtonException;
|
||||
*/
|
||||
final class CoreSyncCommand extends Command
|
||||
{
|
||||
use UsesCoreSource;
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'core:sync';
|
||||
@@ -35,42 +35,34 @@ final class CoreSyncCommand extends Command
|
||||
$updater = new Updater(APP_ROOT);
|
||||
|
||||
if ($updater->storedBaseline() === []) {
|
||||
$this->fail('Доверенного состояния ещё нет — сначала: php bin/proton core:check --baseline');
|
||||
$this->fail('Доверенного состояния ещё нет — сначала: php bin/proton core:check --baseline --path=<ядро>');
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$path = $this->option('path', '');
|
||||
$temporary = null;
|
||||
$path = $this->coreSource($updater);
|
||||
|
||||
if ($path === null || $path === '') {
|
||||
if (!$this->hasOption('remote')) {
|
||||
$this->fail('Нужен --path=<каталог> или --remote');
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
$path = $temporary = $updater->downloadRemote(
|
||||
(string) Config::get('core.repo'),
|
||||
(string) Config::get('core.branch')
|
||||
);
|
||||
} catch (ProtonException $e) {
|
||||
$this->fail($e->getMessage());
|
||||
|
||||
return 1;
|
||||
}
|
||||
if ($path === null) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->sync($updater, $path, $this->hasOption('apply'));
|
||||
} finally {
|
||||
$this->releaseCoreSource($updater);
|
||||
}
|
||||
}
|
||||
|
||||
private function sync(Updater $updater, string $path, bool $apply): int
|
||||
{
|
||||
$report = $updater->diff($path);
|
||||
$apply = $this->hasOption('apply');
|
||||
|
||||
if (!$apply) {
|
||||
$this->line('Только план — для записи добавьте --apply. Что было бы скопировано:');
|
||||
$this->printList($report['safe']);
|
||||
} else {
|
||||
$copied = $updater->copyFiles($path, $report['safe']);
|
||||
$updater->markSynced($copied);
|
||||
$updater->markSynced($path, $report['manual']);
|
||||
|
||||
$this->ok('Скопировано файлов: ' . count($copied));
|
||||
$this->printList($copied);
|
||||
@@ -82,6 +74,12 @@ final class CoreSyncCommand extends Command
|
||||
$this->printList($report['manual']);
|
||||
}
|
||||
|
||||
if ($report['removed'] !== []) {
|
||||
$this->line();
|
||||
$this->line('Ядро больше не содержит (не удалены, решать вам):');
|
||||
$this->printList($report['removed']);
|
||||
}
|
||||
|
||||
if ($report['broken'] !== []) {
|
||||
$this->line();
|
||||
$this->line('Возможно сломается в вашем коде — проверьте после слияния:');
|
||||
@@ -91,13 +89,18 @@ final class CoreSyncCommand extends Command
|
||||
}
|
||||
}
|
||||
|
||||
if ($temporary !== null) {
|
||||
$updater->cleanupRemote($temporary);
|
||||
if (!$apply) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($apply) {
|
||||
$this->line();
|
||||
$this->line('Дальше: php bin/proton test, затем php bin/proton core:bump, когда список ручного слияния разобран.');
|
||||
$this->line();
|
||||
|
||||
if ($report['manual'] === []) {
|
||||
$this->ok('Версия ядра: ' . $updater->adoptVersion($path));
|
||||
$this->line('Дальше: php bin/proton test');
|
||||
} else {
|
||||
$this->line('Версия осталась ' . $updater->localVersion() . ' — станет ' . $report['version_core']
|
||||
. ', когда core:resolve отметит последний файл из ручного слияния.');
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rsgrinko\Proton\Console\Commands;
|
||||
|
||||
use Rsgrinko\Proton\Core\Updater;
|
||||
use Rsgrinko\Proton\Support\Config;
|
||||
use Rsgrinko\Proton\Support\ProtonException;
|
||||
|
||||
/**
|
||||
* Откуда взять ядро для сверки: --path=<каталог> или --remote (архив ветки
|
||||
* из PROTON_CORE_REPO). Скачанное убирает releaseCoreSource() — звать его
|
||||
* из finally, иначе при ошибке в var/tmp копятся распакованные архивы.
|
||||
*/
|
||||
trait UsesCoreSource
|
||||
{
|
||||
private ?string $downloadedCore = null;
|
||||
|
||||
/** Путь к ядру или null, если причину отказа уже напечатали */
|
||||
private function coreSource(Updater $updater): ?string
|
||||
{
|
||||
$path = (string) $this->option('path', '');
|
||||
|
||||
if ($path !== '') {
|
||||
if (!is_dir(rtrim($path, '/\\') . '/framework')) {
|
||||
$this->fail('В ' . $path . ' нет каталога framework/');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
if (!$this->hasOption('remote')) {
|
||||
$this->fail('Нужен --path=<каталог> или --remote');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->downloadedCore = $updater->downloadRemote(
|
||||
(string) Config::get('core.repo'),
|
||||
(string) Config::get('core.branch')
|
||||
);
|
||||
} catch (ProtonException $e) {
|
||||
$this->fail($e->getMessage());
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private function releaseCoreSource(Updater $updater): void
|
||||
{
|
||||
if ($this->downloadedCore !== null) {
|
||||
$updater->cleanupRemote($this->downloadedCore);
|
||||
$this->downloadedCore = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user