feat(self-update): resolve latest via Forgejo/gitea releases API

This commit is contained in:
kj
2026-10-05 15:50:13 -03:00
parent 0220e97109
commit 7025ccf553
7 changed files with 316 additions and 9 deletions
@@ -4,6 +4,7 @@ namespace Toolbox\Commands;
use Toolbox\Config;
use Toolbox\SelfUpdater;
use Toolbox\Semver;
use Toolbox\ToolboxException;
final class SelfUpdateCommand extends Command
@@ -19,14 +20,24 @@ final class SelfUpdateCommand extends Command
$from = $this->option($parsed['options'], 'from', Config::updateUrl());
$target = $this->option($parsed['options'], 'target', Config::binPath());
$temp = $this->option($parsed['options'], 'temp', sys_get_temp_dir());
$force = $this->flag($parsed['options'], 'force');
if ($from === null || $target === null) {
$this->console->error('Faltan --from o --target.');
return 1;
}
$updater = new SelfUpdater($this->console);
try {
(new SelfUpdater($this->console))->update($from, $target, $temp);
if ($this->flag($parsed['options'], 'check')) {
$tag = $updater->available($from);
$this->console->out(' actual: v' . Config::VERSION);
$this->console->out(' disponible: ' . ($tag !== null ? 'v' . ltrim($tag, 'vV') : '(desconocido)'));
return $tag === null || Semver::compare(Config::VERSION, ltrim($tag, 'vV')) >= 0 ? 0 : 1;
}
$updater->update($from, $target, $temp, $force);
} catch (ToolboxException $e) {
$this->console->error($e->getMessage());
return 1;