mirror of
https://github.com/dream-pep/koring-launcher.git
synced 2026-09-12 05:45:18 +08:00
feat(auto-update): 实现全流程自动更新功能与配套界面
- 新增主进程更新服务,支持GitHub官方源与加速源兜底的检查、下载、安装全流程 - 新增独立更新日志页面,支持查看更新说明与更新全流程管理 - 实现更新状态持久化,重启应用可恢复上次未完成的下载进度 - 完善版本管理与构建元数据脚本,优化CI发布流水线 - 补充VersionCard的构建信息展示与更新页跳转逻辑 - 新增更新相关IPC接口、类型定义与全局状态管理 - 清理旧的无用配置项,升级相关依赖包
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* 生成构建元数据文件 src/lib/buildInfo.ts(CI 构建时调用)。
|
||||
*
|
||||
* 用法:
|
||||
* node scripts/gen-build-info.js <mode> # mode: dev | beta | run
|
||||
*
|
||||
* 环境变量:
|
||||
* BUILD_ID 编译号(CI 传 GITHUB_RUN_NUMBER;缺省 "local")
|
||||
* 本地 git HEAD 短哈希作为构建来源 commit。
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
const { execSync } = require('child_process');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const mode = process.argv[2] || 'run';
|
||||
|
||||
let commit = '';
|
||||
try {
|
||||
commit = execSync('git rev-parse --short HEAD').toString().trim();
|
||||
} catch {
|
||||
/* 非 git 环境,保持空 */
|
||||
}
|
||||
|
||||
const buildId = process.env.BUILD_ID || process.env.GITHUB_RUN_NUMBER || 'local';
|
||||
|
||||
const content = `// 构建元数据:由 scripts/gen-build-info.js 自动生成(CI 覆盖;本地开发为默认值)
|
||||
export const BUILD_COMMIT: string = ${JSON.stringify(commit)};
|
||||
export const BUILD_ID: string = ${JSON.stringify(buildId)};
|
||||
`;
|
||||
|
||||
fs.writeFileSync(path.join(__dirname, '..', 'src', 'lib', 'buildInfo.ts'), content);
|
||||
console.log(`[build-info] mode=${mode} commit=${commit || '(none)'} buildId=${buildId}`);
|
||||
@@ -16,10 +16,12 @@ param(
|
||||
[Parameter(Mandatory = $true)][string] $FullVersion,
|
||||
[Parameter(Mandatory = $true)][string] $Mode,
|
||||
[string] $SigningStatus = "已签名",
|
||||
[string] $Commit = "",
|
||||
[string] $OutputPath = "release-notes.md"
|
||||
)
|
||||
|
||||
$status = if ($Mode -eq 'beta') { 'BETA' } else { 'RUN' }
|
||||
$commitShort = if ($Commit) { $Commit.Substring(0, [Math]::Min(7, $Commit.Length)) } else { '' }
|
||||
|
||||
$rec = [char]0x1e # 记录分隔符(每个 commit 一条)
|
||||
$sep = [char]0x1f # 字段分隔符(hash / subject / body)
|
||||
@@ -68,6 +70,7 @@ $content = @"
|
||||
当前版本 $FullVersion
|
||||
编译状态:$status
|
||||
签名状态:$SigningStatus
|
||||
$(if ($commitShort) { "构建来源:commit $commitShort" })
|
||||
|
||||
## 更新了什么内容
|
||||
$commitsSection
|
||||
|
||||
+34
-5
@@ -9,14 +9,11 @@ function getCurrentVersion() {
|
||||
return pkg.version;
|
||||
}
|
||||
|
||||
/** 仅写文件,不打印(stdout 纯净,供脚本/CI 捕获) */
|
||||
function setVersion(version) {
|
||||
// Update package.json
|
||||
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
|
||||
pkg.version = version;
|
||||
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
|
||||
|
||||
console.log(`Version updated to ${version}`);
|
||||
console.log(` - package.json`);
|
||||
}
|
||||
|
||||
// Parse args
|
||||
@@ -27,15 +24,45 @@ if (args.length === 0) {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// 输出裸版本号(供脚本/CI 使用)
|
||||
if (args[0] === 'get') {
|
||||
console.log(getCurrentVersion());
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// 构建版本:统一「base + 构建号」规则,消除本地/CI 版本双轨
|
||||
// version.js build ci [buildId] [base] CI:base 缺省读 package.json → 设置并输出 base-buildId
|
||||
// version.js build local 本地:输出当前 base(不修改)
|
||||
if (args[0] === 'build') {
|
||||
const kind = args[1];
|
||||
if (kind === 'ci') {
|
||||
const buildId = args[2] || process.env.GITHUB_RUN_NUMBER || '0';
|
||||
const base = args[3] || getCurrentVersion();
|
||||
const full = `${base}-${buildId}`;
|
||||
setVersion(full);
|
||||
console.log(full); // stdout 仅版本号
|
||||
process.exit(0);
|
||||
}
|
||||
if (kind === 'local') {
|
||||
console.log(getCurrentVersion());
|
||||
process.exit(0);
|
||||
}
|
||||
console.error('Usage: node scripts/version.js build ci [buildId] [base] | node scripts/version.js build local');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (args[0] === '--help' || args[0] === '-h') {
|
||||
console.log('Usage:');
|
||||
console.log(' node scripts/version.js <version> Set version');
|
||||
console.log(' node scripts/version.js Show current version');
|
||||
console.log(' node scripts/version.js get Print raw version');
|
||||
console.log(' node scripts/version.js build ci [buildId] [base] CI build version (base-buildId)');
|
||||
console.log(' node scripts/version.js build local Print local base version');
|
||||
console.log('');
|
||||
console.log('Examples:');
|
||||
console.log(' node scripts/version.js 1.0.0');
|
||||
console.log(' node scripts/version.js 1.1.0-beta.1');
|
||||
console.log(' node scripts/version.js 2.0.0-rc.1');
|
||||
console.log(' node scripts/version.js build ci 12');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
@@ -51,3 +78,5 @@ if (!/^\d+\.\d+\.\d+/.test(newVersion)) {
|
||||
const current = getCurrentVersion();
|
||||
console.log(`Current version: ${current}`);
|
||||
setVersion(newVersion);
|
||||
console.log(`Version updated to ${newVersion}`);
|
||||
console.log(' - package.json');
|
||||
|
||||
Reference in New Issue
Block a user