mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-08 19:12:48 +08:00
perf(update): clone 一次仓库并本地复制替代第二次网络 clone; 排除 public/storage 和 public/build
This commit is contained in:
@@ -55,8 +55,8 @@ class AdminUpdateServiceBase
|
|||||||
|
|
||||||
$current_version = $this->useVersion;
|
$current_version = $this->useVersion;
|
||||||
|
|
||||||
$current_version_dir = App::getRuntimePath() . '/update/' . $current_version;
|
$current_version_dir = App::getRuntimePath() . '/update/current';
|
||||||
$last_version_dir = App::getRuntimePath() . '/update/last';
|
$last_version_dir = App::getRuntimePath() . '/update/repo';
|
||||||
$now_dir = App::getRootPath();
|
$now_dir = App::getRootPath();
|
||||||
|
|
||||||
$output->writeln('获取最新代码');
|
$output->writeln('获取最新代码');
|
||||||
@@ -118,11 +118,12 @@ class AdminUpdateServiceBase
|
|||||||
$last_version_repo->checkout($last_version);
|
$last_version_repo->checkout($last_version);
|
||||||
}
|
}
|
||||||
|
|
||||||
$current_version_git = new Git();
|
$output->writeln('复制当前版本代码');
|
||||||
$output->writeln('获取当前版本代码');
|
$output->writeln('切换到当前版本' . $current_version);
|
||||||
$current_version_repo = $current_version_git->cloneRepository($this->useRepo, $current_version_dir);
|
$last_version_repo->checkout($current_version);
|
||||||
$output->writeln('切换版本' . $current_version);
|
$this->copyDirectory($last_version_dir, $current_version_dir);
|
||||||
$current_version_repo->checkout($current_version);
|
$output->writeln('切换回最新版本' . $last_version);
|
||||||
|
$last_version_repo->checkout($last_version);
|
||||||
|
|
||||||
$output->writeln('开始比较版本差异');
|
$output->writeln('开始比较版本差异');
|
||||||
|
|
||||||
@@ -142,6 +143,8 @@ class AdminUpdateServiceBase
|
|||||||
'runtime',
|
'runtime',
|
||||||
'vendor',
|
'vendor',
|
||||||
'.git',
|
'.git',
|
||||||
|
'public/storage',
|
||||||
|
'public/build',
|
||||||
];
|
];
|
||||||
|
|
||||||
// 当前版本的应该被处理所有文件
|
// 当前版本的应该被处理所有文件
|
||||||
@@ -426,4 +429,36 @@ class AdminUpdateServiceBase
|
|||||||
$this->output->writeln('清理目录 ' . $dir);
|
$this->output->writeln('清理目录 ' . $dir);
|
||||||
PathTools::removeDir($dir);
|
PathTools::removeDir($dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 递归复制目录
|
||||||
|
* Windows 兼容,使用 PHP 原生 opendir/readdir 实现
|
||||||
|
*/
|
||||||
|
protected function copyDirectory(string $src, string $dst): void
|
||||||
|
{
|
||||||
|
if (!is_dir($src)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_dir($dst)) {
|
||||||
|
mkdir($dst, 0755, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$handle = opendir($src);
|
||||||
|
while (false !== ($file = readdir($handle))) {
|
||||||
|
if ($file === '.' || $file === '..') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$srcPath = $src . '/' . $file;
|
||||||
|
$dstPath = $dst . '/' . $file;
|
||||||
|
|
||||||
|
if (is_dir($srcPath)) {
|
||||||
|
$this->copyDirectory($srcPath, $dstPath);
|
||||||
|
} else {
|
||||||
|
copy($srcPath, $dstPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir($handle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user