From 37c8142721ca154388832d67e5dc06c971824c00 Mon Sep 17 00:00:00 2001 From: augushong Date: Thu, 7 May 2026 22:59:19 +0800 Subject: [PATCH] =?UTF-8?q?feat(update):=20=E6=94=AF=E6=8C=81=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=88=B0=20ulthon=5Fadmin=20=E7=9A=84=20master=20?= =?UTF-8?q?=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增 `--update-master` 选项,允许用户选择更新到远程仓库的 master 分支,而非默认的最新标签版本。这为需要最新开发版代码的场景提供了灵活性。 --- .../admin/service/AdminUpdateServiceBase.php | 76 ++++++++++++------- .../base/common/command/admin/UpdateBase.php | 3 +- 2 files changed, 49 insertions(+), 30 deletions(-) diff --git a/extend/base/admin/service/AdminUpdateServiceBase.php b/extend/base/admin/service/AdminUpdateServiceBase.php index 8a2345d..5281090 100644 --- a/extend/base/admin/service/AdminUpdateServiceBase.php +++ b/extend/base/admin/service/AdminUpdateServiceBase.php @@ -64,41 +64,59 @@ class AdminUpdateServiceBase $last_version_repo = $last_version_git->cloneRepository($this->useRepo, $last_version_dir); - $tags = $last_version_repo->getTags(); + $is_update_master = (bool)$input->getOption('update-master'); + $last_version = null; - $update_level = Env::get('adminsystem.update_level', 'production'); - - if ($update_level == 'production') { - $tags = array_filter($tags, function ($value) { - if (strpos($value, '-')) { - return false; - } - - return true; - }); - } - - usort($tags, function ($a, $b) { - return version_compare($a, $b); - }); - - $last_version = $tags[count($tags) - 1]; - - if ($last_version == $current_version) { - $output->writeln('当前版本为最新版本'); - - if ($input->hasOption('reinstall')) { - $output->writeln('重装代码'); - } else { + if ($is_update_master) { + $output->writeln('当前更新源:master'); + $output->writeln('切换最新代码到 master 分支'); + try { + $last_version_repo->checkout('master'); + } catch (\Throwable $e) { + $output->error('切换 master 分支失败,请检查远程分支名是否为 master'); $this->cleanWorkpaceDir(); return; } - } + $last_version = 'master'; + } else { + $output->writeln('当前更新源:latest tag'); + $tags = $last_version_repo->getTags(); - // 将最新代码切换到最新版本,因为最新的提交可能没有发布版本 - $output->writeln('切换最新代码的最新版本'); - $last_version_repo->checkout($last_version); + $update_level = Env::get('adminsystem.update_level', 'production'); + + if ($update_level == 'production') { + $tags = array_filter($tags, function ($value) { + if (strpos($value, '-')) { + return false; + } + + return true; + }); + } + + usort($tags, function ($a, $b) { + return version_compare($a, $b); + }); + + $last_version = $tags[count($tags) - 1]; + + if ($last_version == $current_version) { + $output->writeln('当前版本为最新版本'); + + if ((bool)$input->getOption('reinstall')) { + $output->writeln('重装代码'); + } else { + $this->cleanWorkpaceDir(); + + return; + } + } + + // 将最新代码切换到最新版本,因为最新的提交可能没有发布版本 + $output->writeln('切换最新代码的最新版本'); + $last_version_repo->checkout($last_version); + } $current_version_git = new Git(); $output->writeln('获取当前版本代码'); diff --git a/extend/base/common/command/admin/UpdateBase.php b/extend/base/common/command/admin/UpdateBase.php index 72d7f8f..8a584d2 100644 --- a/extend/base/common/command/admin/UpdateBase.php +++ b/extend/base/common/command/admin/UpdateBase.php @@ -23,6 +23,7 @@ class UpdateBase extends Command $this->setName('admin:update') ->addOption('reinstall', null, Option::VALUE_NONE, '重装版本') ->addOption('update-ulthon', null, Option::VALUE_NONE, '更新 ulthon_admin') + ->addOption('update-master', null, Option::VALUE_NONE, '更新 ulthon_admin 的 master 分支') ->setDescription('更新系统代码'); } @@ -33,7 +34,7 @@ class UpdateBase extends Command $repo = static::REPO; - if($input->hasOption('update-ulthon')){ + if ((bool)$input->getOption('update-ulthon')) { $repo = 'ulthon_admin'; }