jbc-dssi 1.1.107 → 1.1.108
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/proc-commands.js +82 -5
- package/package.json +1 -1
package/lib/proc-commands.js
CHANGED
|
@@ -59,6 +59,38 @@ export const PROC_DEFAULTS = [
|
|
|
59
59
|
args: [],
|
|
60
60
|
builtin: 'health',
|
|
61
61
|
},
|
|
62
|
+
{
|
|
63
|
+
id: 'release.preflight',
|
|
64
|
+
name: '发版预检',
|
|
65
|
+
desc: '发版前自检:changelog / perf / tag / 插件版本号 / 身份与配置闸门,缺什么直接报出来',
|
|
66
|
+
danger: 'low',
|
|
67
|
+
timeoutMs: 120_000,
|
|
68
|
+
args: [{ name: 'version', label: '版本号', required: true, pattern: '^\\d+\\.\\d+\\.\\d+$' }],
|
|
69
|
+
script: {
|
|
70
|
+
rel: 'scripts/release-preflight.py',
|
|
71
|
+
exec: 'python3',
|
|
72
|
+
argv: ['--version', '{version}'],
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
id: 'release.publish',
|
|
77
|
+
name: '发版',
|
|
78
|
+
desc: '按 release-fast 发版:构建 → 发布插件与安装包 → 六项自检(约 3–5 分钟,不可取消)',
|
|
79
|
+
danger: 'high',
|
|
80
|
+
confirmText:
|
|
81
|
+
'发版会构建 APK、发布插件与安装包、跑六项自检,约 3–5 分钟且不可取消。' +
|
|
82
|
+
'前提:changelog/perf 文案已审、tag 已打(可先跑「发版预检」)。',
|
|
83
|
+
timeoutMs: 900_000,
|
|
84
|
+
args: [
|
|
85
|
+
{ name: 'version', label: '版本号', required: true, pattern: '^\\d+\\.\\d+\\.\\d+$' },
|
|
86
|
+
{ name: 'code', label: 'versionCode', required: true, pattern: '^\\d+$' },
|
|
87
|
+
],
|
|
88
|
+
script: {
|
|
89
|
+
rel: 'scripts/release-fast.sh',
|
|
90
|
+
exec: 'bash',
|
|
91
|
+
argv: ['--version', '{version}', '--code', '{code}'],
|
|
92
|
+
},
|
|
93
|
+
},
|
|
62
94
|
{
|
|
63
95
|
id: 'env.restart_dsh',
|
|
64
96
|
name: '重启dsh',
|
|
@@ -138,6 +170,34 @@ export function resolveScript(cmd, repoRoot) {
|
|
|
138
170
|
return null;
|
|
139
171
|
}
|
|
140
172
|
|
|
173
|
+
/** 解释器解析:白名单显式 `exec` 优先,否则按扩展名推断;推不出来 = 不可执行。 */
|
|
174
|
+
export function resolveExec(cmd, scriptPath) {
|
|
175
|
+
const explicit = typeof cmd.script?.exec === 'string' ? cmd.script.exec.trim() : '';
|
|
176
|
+
if (explicit) return explicit;
|
|
177
|
+
const m = /\.[a-z0-9]+$/i.exec(scriptPath ?? '');
|
|
178
|
+
return EXEC_BY_EXT[(m?.[0] ?? '').toLowerCase()] ?? null;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 把命令参数套进脚本 argv 模板(白名单里声明,例:`['--version', '{version}']`)。
|
|
183
|
+
*
|
|
184
|
+
* 只替换模板里声明过的占位符;手机传来的参数**只能落进模板位置**,
|
|
185
|
+
* 拼不出新参数 —— 这是"手机传不了任意命令行"的同一条边界。
|
|
186
|
+
*/
|
|
187
|
+
export function buildArgv(cmd, args) {
|
|
188
|
+
const tpl = Array.isArray(cmd.script?.argv) ? cmd.script.argv : [];
|
|
189
|
+
return tpl.map((tok) =>
|
|
190
|
+
String(tok).replace(/\{([a-zA-Z][a-zA-Z0-9_-]{0,31})\}/g, (_, name) => {
|
|
191
|
+
const v = args?.[name];
|
|
192
|
+
if (v == null) throw new Error(`参数模板引用了未提供的参数:${name}`);
|
|
193
|
+
return String(v);
|
|
194
|
+
}),
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** 脚本扩展名 → 默认解释器。 */
|
|
199
|
+
const EXEC_BY_EXT = { '.sh': 'bash', '.py': 'python3', '.mjs': 'node', '.js': 'node' };
|
|
200
|
+
|
|
141
201
|
/* ------------------------------------------------------------ 默认探针 */
|
|
142
202
|
|
|
143
203
|
/** TCP 端口探测(默认实现;测试可注入)。 */
|
|
@@ -330,6 +390,16 @@ export function createProcEngine(opts = {}) {
|
|
|
330
390
|
}
|
|
331
391
|
}
|
|
332
392
|
|
|
393
|
+
/** 取日志最后一行有效内容(失败原因 / 发版结论通常就在最后一行)。 */
|
|
394
|
+
function lastLogLine(text) {
|
|
395
|
+
const lines = String(text ?? '')
|
|
396
|
+
.split('\n')
|
|
397
|
+
.map((l) => l.trim())
|
|
398
|
+
.filter(Boolean);
|
|
399
|
+
if (lines.length === 0) return '';
|
|
400
|
+
return lines[lines.length - 1].slice(0, 200);
|
|
401
|
+
}
|
|
402
|
+
|
|
333
403
|
function releaseLocks(record) {
|
|
334
404
|
activeByCmd.delete(record.cmdId);
|
|
335
405
|
if (activeHigh === record.runId) activeHigh = null;
|
|
@@ -428,9 +498,9 @@ export function createProcEngine(opts = {}) {
|
|
|
428
498
|
return child;
|
|
429
499
|
}
|
|
430
500
|
|
|
431
|
-
function spawnForeground(
|
|
501
|
+
function spawnForeground(exec, argv, record) {
|
|
432
502
|
return new Promise((resolve) => {
|
|
433
|
-
const child = spawnFn(
|
|
503
|
+
const child = spawnFn(exec, argv, {
|
|
434
504
|
cwd: repoRoot || undefined,
|
|
435
505
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
436
506
|
env: { ...process.env },
|
|
@@ -490,12 +560,19 @@ export function createProcEngine(opts = {}) {
|
|
|
490
560
|
});
|
|
491
561
|
return;
|
|
492
562
|
}
|
|
493
|
-
const
|
|
563
|
+
const exec = resolveExec(cmd, scriptPath);
|
|
564
|
+
if (!exec) {
|
|
565
|
+
finish(record, { exitCode: -1, summary: `${cmd.name} 失败:不认识脚本类型(请在白名单里写 exec)` });
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
const argv = buildArgv(cmd, record.args ?? {});
|
|
569
|
+
const { exitCode, signal, logText } = await spawnForeground(exec, [scriptPath, ...argv], record);
|
|
570
|
+
const tail = lastLogLine(logText);
|
|
494
571
|
finish(record, {
|
|
495
572
|
exitCode,
|
|
496
573
|
summary: exitCode === 0
|
|
497
|
-
? `${cmd.name} 完成`
|
|
498
|
-
: `${cmd.name} 失败(${signal ? `signal ${signal}` : `exit ${exitCode}`}
|
|
574
|
+
? (tail ? `${cmd.name} 完成 · ${tail}` : `${cmd.name} 完成`)
|
|
575
|
+
: `${cmd.name} 失败(${signal ? `signal ${signal}` : `exit ${exitCode}`}):${tail || "没有输出"}`,
|
|
499
576
|
logText,
|
|
500
577
|
});
|
|
501
578
|
} catch (err) {
|