@infly/libs 2.5.0 → 2.6.0

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.
@@ -7,10 +7,10 @@ const { composeRelease } = require("./compose-release");
7
7
  const { formatCicdLink, healthCheckImage } = require("./docker-build-push");
8
8
  const { loadDockerConfig } = require("./config-loader");
9
9
  const { detectReleaseContext, detectReleaseMode } = require("./release-mode");
10
- const { prepareMinimalMonorepoContext, normalizeMonorepoContextFiles } = require("./minimal-context");
11
- const { prepareProjectInstallContext, prepareStandaloneInstallContext } = require("./project-install");
12
10
  const { prepareWorkspaceSnapshot, verifyWorkspaceRemote } = require("./source-snapshot");
13
- const { createReleaseId, createBuildProvenance, readRegistryDigest } = require("./release-identity");
11
+ const { readRegistryDigest } = require("./release-identity");
12
+ const { compareVersions, normalizePreBuildCommand, resolveSourceDirectories, validateComponent, validateReleaseProfile } = require("./release-validation");
13
+ const { buildTargetImage, finishTargetImage } = require("./target-image");
14
14
 
15
15
  // Jenkins 构建页“镜像版本”与 Webhook 通知均按北京时间展示。
16
16
  function beijingDateTime(now = new Date()) {
@@ -84,44 +84,6 @@ function parseReleaseArgs(argv) {
84
84
  return options;
85
85
  }
86
86
 
87
- function inside(root, relative) {
88
- if (typeof relative !== "string" || !relative || path.isAbsolute(relative)) throw new Error(`必须配置相对路径: ${relative}`);
89
- const result = path.resolve(root, relative);
90
- const offset = path.relative(root, result);
91
- if (offset === ".." || offset.startsWith(`..${path.sep}`)) throw new Error(`路径越界: ${relative}`);
92
- return result;
93
- }
94
-
95
- function confinedPath(root, relative, io = fs) {
96
- const candidate = inside(root, relative);
97
- let existing = candidate;
98
- while (existing !== root && !io.existsSync(existing)) {
99
- if (io.lstatSync) {
100
- try {
101
- if (io.lstatSync(existing).isSymbolicLink()) throw new Error(`无法解析链接路径: ${relative}`);
102
- } catch (error) { if (error.code !== "ENOENT") throw error; }
103
- }
104
- existing = path.dirname(existing);
105
- }
106
- if (io.realpathSync && io.existsSync(existing)) {
107
- const offset = path.relative(io.realpathSync(root), io.realpathSync(existing));
108
- if (offset === ".." || offset.startsWith(`..${path.sep}`) || path.isAbsolute(offset)) throw new Error(`链接路径越界: ${relative}`);
109
- }
110
- return candidate;
111
- }
112
-
113
- function normalizeSourceDirectories(value, name) {
114
- const directories = Array.isArray(value) ? value : [value];
115
- if (!directories.length || directories.some((item) => typeof item !== "string" || !item.trim())) {
116
- throw new Error(`${name} source.directory 必须是非空路径字符串或非空路径数组`);
117
- }
118
- return [...new Set(directories.map((item) => item.trim()))];
119
- }
120
-
121
- function resolveSourceDirectories(projectDir, value, name) {
122
- return normalizeSourceDirectories(value, name).map((directory) => path.resolve(projectDir, directory));
123
- }
124
-
125
87
  function trimPathInput(value) {
126
88
  const trimmed = String(value || "").trim();
127
89
  return trimmed.length >= 2 && ((trimmed.startsWith('"') && trimmed.endsWith('"'))
@@ -130,69 +92,8 @@ function trimPathInput(value) {
130
92
  : trimmed;
131
93
  }
132
94
 
133
- const SAFE_GIT_NAME = /^[A-Za-z0-9][A-Za-z0-9._/-]*$/;
134
- const SAFE_DOCKER_PLATFORM = /^[a-z0-9]+\/[a-z0-9]+(?:\/[a-z0-9._-]+)?$/;
135
- const SAFE_VERSION_REQUIREMENT = /^>=(\d+)(?:\.(\d+))?(?:\.(\d+))?$/;
136
- const WINDOWS_PACKAGE_MANAGERS = new Set(["npm", "npx", "pnpm", "yarn"]);
137
95
  const UNSAFE_WINDOWS_SHELL_TOKEN = /[\r\n\0&|<>^%!"]/;
138
- const PRE_BUILD_MODES = new Set(["always", "monorepo", "standalone"]);
139
- const BUILD_STRATEGIES = new Set(["artifact", "source"]);
140
-
141
- function normalizePreBuildCommand(value, target) {
142
- const entry = Array.isArray(value) ? { command: value, when: "always" } : value;
143
- if (!entry || typeof entry !== "object" || Array.isArray(entry)
144
- || !Array.isArray(entry.command) || entry.command.length === 0
145
- || entry.command.some((arg) => typeof arg !== "string" || !arg || /[\r\n\0]/.test(arg))
146
- || (entry.when != null && !PRE_BUILD_MODES.has(entry.when))) {
147
- throw new Error(`${target} preBuild 必须是命令参数数组,或包含 command 与合法 when 的对象`);
148
- }
149
- return { command: entry.command, when: entry.when || "always" };
150
- }
151
-
152
- function validateReleaseProfile(profile, target) {
153
- if (profile.recordConfigurationRevision != null && typeof profile.recordConfigurationRevision !== "boolean") {
154
- throw new Error(`${target} recordConfigurationRevision 必须是布尔值`);
155
- }
156
- if (profile.pushBranch != null && (typeof profile.pushBranch !== "string"
157
- || !SAFE_GIT_NAME.test(profile.pushBranch) || profile.pushBranch.startsWith("-")
158
- || profile.pushBranch.includes(".."))) {
159
- throw new Error(`${target} pushBranch 必须是合法 Git 分支名`);
160
- }
161
- if (profile.pushRef != null && (typeof profile.pushRef !== "string"
162
- || !SAFE_GIT_NAME.test(profile.pushRef) || profile.pushRef.startsWith("-")
163
- || profile.pushRef.includes("..") || !profile.pushRef.includes("/"))) {
164
- throw new Error(`${target} pushRef 必须使用 remote/branch 格式`);
165
- }
166
- if ((profile.pushBranch == null) !== (profile.pushRef == null)) {
167
- throw new Error(`${target} pushBranch 和 pushRef 必须同时配置`);
168
- }
169
- if (profile.requirements != null) {
170
- if (!profile.requirements || typeof profile.requirements !== "object"
171
- || Array.isArray(profile.requirements)) throw new Error(`${target} requirements 必须是对象`);
172
- for (const [tool, requirement] of Object.entries(profile.requirements)) {
173
- if (!["node", "pnpm"].includes(tool) || typeof requirement !== "string"
174
- || !SAFE_VERSION_REQUIREMENT.test(requirement)) {
175
- throw new Error(`${target} requirements 只支持 node/pnpm 的 >=x.y.z 版本约束`);
176
- }
177
- }
178
- }
179
- if (profile.preBuild != null && (!Array.isArray(profile.preBuild) || profile.preBuild.length === 0)) {
180
- throw new Error(`${target} preBuild 必须是非空列表`);
181
- }
182
- for (const command of profile.preBuild || []) normalizePreBuildCommand(command, target);
183
- }
184
-
185
- function compareVersions(actual, required) {
186
- const actualMatch = String(actual).trim().replace(/^v/, "").match(/^(\d+)(?:\.(\d+))?(?:\.(\d+))?/);
187
- const requiredMatch = String(required).match(SAFE_VERSION_REQUIREMENT);
188
- if (!actualMatch || !requiredMatch) return false;
189
- for (let index = 1; index <= 3; index++) {
190
- const left = Number(actualMatch[index] || 0);
191
- const right = Number(requiredMatch[index] || 0);
192
- if (left !== right) return left > right;
193
- }
194
- return true;
195
- }
96
+ const WINDOWS_PACKAGE_MANAGERS = new Set(["npm", "npx", "pnpm", "yarn"]);
196
97
 
197
98
  function windowsExecutable(command, platform = process.platform) {
198
99
  return platform === "win32" && WINDOWS_PACKAGE_MANAGERS.has(command)
@@ -253,8 +154,7 @@ function runReleasePreparation(profile, {
253
154
  }
254
155
  }
255
156
  for (const [tool, requirement] of Object.entries(profile.requirements || {})) {
256
- const args = tool === "node" ? ["--version"] : ["--version"];
257
- const invocation = buildExecutableSpawn(tool, args, { platform, env });
157
+ const invocation = buildExecutableSpawn(tool, ["--version"], { platform, env });
258
158
  const actual = capture(invocation.command, invocation.args);
259
159
  if (!compareVersions(actual, requirement)) {
260
160
  throw new Error(`${tool} 必须满足 ${requirement},当前版本: ${actual || "无法识别"}`);
@@ -276,125 +176,168 @@ function runReleasePreparation(profile, {
276
176
  }
277
177
  }
278
178
 
279
- function validateComponent(component, name, guardedByProfile = false) {
280
- if (!component || !/^[a-z0-9][a-z0-9._:/-]*$/.test(component.repository || "") || component.repository.includes("@")) {
281
- throw new Error(`${name} 必须配置有效的镜像 repository(不含标签)`);
282
- }
283
- if (component.repository.split("/").at(-1).includes(":")) throw new Error(`${name} repository 不得包含标签`);
284
- if (!component.expectedRef && !component.source?.branch && !guardedByProfile) {
285
- throw new Error(`${name} 必须配置 expectedRef、source.branch 或 target pushRef`);
286
- }
287
- if (component.source) {
288
- normalizeSourceDirectories(component.source.directory, name);
289
- if (component.source.standalone != null && typeof component.source.standalone !== "boolean") {
290
- throw new Error(`${name} source.standalone 必须是布尔值`);
179
+ function execute(command, args, options = {}) {
180
+ return execFileSync(command, args, { stdio: "inherit", ...options });
181
+ }
182
+
183
+ function freezeReleaseSources(plan, {
184
+ profile, projectDir, releaseContext, push, dependencies,
185
+ sources, workspaces, publicSnapshots, resources, verifyFrozen, io, run, capture,
186
+ }) {
187
+ let configuration;
188
+ if (profile.recordConfigurationRevision || plan.some((item) => item.dockerfileFromConfig || item.contextFiles)) {
189
+ const commit = capture("git", ["-C", projectDir, "rev-parse", "HEAD"]).toLowerCase();
190
+ if (!/^[a-f0-9]{40}$/.test(commit)) throw new Error("无法冻结部署配置版本");
191
+ configuration = { sourceDir: projectDir, commit };
192
+ verifyFrozen(configuration, "部署配置");
193
+ workspaces.set(projectDir, configuration);
194
+ }
195
+ // 所有来源先冻结,再开始任何镜像构建。相同仓库和分支只 fetch 一次,
196
+ // worktree 使用完整 SHA,后续远端分支前移不会把同一组镜像拆成不同版本。
197
+ for (const item of plan) {
198
+ const directory = item.source?.directory || projectDir;
199
+ const sourceKey = JSON.stringify([directory, item.source?.branch || null]);
200
+ let frozen = sources.get(sourceKey);
201
+ if (!frozen) {
202
+ let sourceDir = projectDir;
203
+ let commit;
204
+ if (item.source) {
205
+ run("git", ["-C", directory, "fetch", "origin"], { cwd: projectDir });
206
+ commit = capture("git", ["-C", directory, "rev-parse", `origin/${item.source.branch}^{commit}`]).toLowerCase();
207
+ if (!/^[a-f0-9]{40}$/.test(commit)) throw new Error(`${item.name} 无法冻结合法的源码提交`);
208
+ const tempRoot = io.mkdtempSync(path.join(os.tmpdir(), "infly-image-"));
209
+ sourceDir = path.join(tempRoot, "source");
210
+ // add 失败时也保留清理记录;不能安全移除 worktree 时留下目录供人工恢复。
211
+ resources.push({ tempRoot, worktree: sourceDir, repository: directory });
212
+ run("git", ["-C", directory, "worktree", "add", "--detach", sourceDir, commit], { cwd: projectDir });
213
+ } else {
214
+ commit = capture("git", ["-C", sourceDir, "rev-parse", "HEAD"]).toLowerCase();
215
+ }
216
+ if (!/^[a-f0-9]{40}$/.test(commit)) throw new Error(`${item.name} 无法冻结合法的源码提交`);
217
+ frozen = { sourceDir, commit };
218
+ sources.set(sourceKey, frozen);
291
219
  }
292
- if (!component.source.branch || component.source.branch.startsWith("-")) {
293
- throw new Error(`${name} source 必须配置合法 branch`);
220
+ const git = (...args) => capture("git", ["-C", frozen.sourceDir, ...args]);
221
+ if (git("status", "--porcelain", "--untracked-files=all")) throw new Error(`${item.name} 仓库存在未提交改动`);
222
+ const expectedRef = item.source ? null : item.expectedRef;
223
+ if (git("rev-parse", "HEAD").toLowerCase() !== frozen.commit || (expectedRef
224
+ && frozen.commit !== git("rev-parse", `${expectedRef}^{commit}`).toLowerCase())) {
225
+ throw new Error(`${item.name} HEAD 与 ${expectedRef || "冻结提交"} 不一致,请先核对并 fetch 对应仓库`);
294
226
  }
295
- }
296
- inside("/config", component.dockerfile || "Dockerfile");
297
- if (component.dockerfileFromConfig != null) {
298
- inside("/config", component.dockerfileFromConfig);
299
- if (!component.source || component.buildStrategy !== "source" || component.dockerfile != null) {
300
- throw new Error(`${name} dockerfileFromConfig 只支持外部源码构建,不能同时配置 dockerfile`);
227
+ item.frozen = frozen;
228
+ item.releaseContext = item.source
229
+ ? ((!item.source.standalone && (item.dockerfileFromConfig || item.contextFiles))
230
+ ? (dependencies.detectReleaseContext || detectReleaseContext)({ projectDir: item.source.directory })
231
+ : { mode: "standalone", contextRoot: frozen.sourceDir, projectRelativeDir: "." })
232
+ : releaseContext;
233
+ if (item.source && item.releaseContext.mode === "standalone") {
234
+ item.releaseContext = { ...item.releaseContext, contextRoot: frozen.sourceDir, projectRelativeDir: "." };
301
235
  }
302
- }
303
- if (component.contextFiles != null) {
304
- if (!component.source || component.buildStrategy !== "source" || !Array.isArray(component.contextFiles)
305
- || !component.contextFiles.length) throw new Error(`${name} contextFiles 只支持外部源码构建的非空列表`);
306
- const destinations = new Set();
307
- for (const entry of component.contextFiles) {
308
- if (!entry || typeof entry !== "object" || Array.isArray(entry)
309
- || Object.keys(entry).some((key) => !["from", "to"].includes(key))) throw new Error(`${name} contextFiles 仅支持 from/to`);
310
- inside("/config", entry.from); inside("/config", entry.to);
311
- const destination = path.normalize(entry.to);
312
- if (destination === "." || destination.split(path.sep).includes(".git") || destinations.has(destination)) {
313
- throw new Error(`${name} contextFiles 目标不能为根、Git 元数据或重复路径`);
236
+ if (item.buildStrategy === "source" && item.releaseContext.mode === "monorepo") {
237
+ const contextRoot = item.releaseContext.contextRoot;
238
+ let workspace = workspaces.get(contextRoot);
239
+ if (!workspace) {
240
+ const revision = capture("git", ["-C", contextRoot, "rev-parse", "HEAD"]).toLowerCase();
241
+ if (!/^[a-f0-9]{40}$/.test(revision)) throw new Error(`${item.name} 无法解析合法的 monorepo revision`);
242
+ workspace = { sourceDir: contextRoot, commit: revision };
243
+ verifyFrozen(workspace, `${item.name} 的 monorepo 构建上下文`);
244
+ workspaces.set(contextRoot, workspace);
245
+ }
246
+ item.workspace = workspace;
247
+ if (item.projectInstall) {
248
+ const synchronized = dependencies.rootSynchronization;
249
+ if (synchronized?.verified && synchronized.workspaceRoot === contextRoot && synchronized.revision === workspace.commit) {
250
+ workspace.remote = { expectedRef: synchronized.expectedRef, revision: synchronized.revision, verified: true };
251
+ }
252
+ if (push && !workspace.remote) {
253
+ if (!item.workspaceRef) throw new Error(`${item.name} 正式源码发布必须配置 workspaceRef`);
254
+ workspace.remote = verifyWorkspaceRemote({ workspaceRoot: contextRoot, revision: workspace.commit,
255
+ expectedRef: item.workspaceRef, capture });
256
+ }
257
+ if (workspace.remote && item.workspaceRef !== workspace.remote.expectedRef) throw new Error("同一主仓不能使用不同的 workspaceRef");
258
+ if (!publicSnapshots.has(contextRoot)) {
259
+ const snapshot = (dependencies.prepareWorkspaceSnapshot || prepareWorkspaceSnapshot)({
260
+ workspaceRoot: contextRoot, revision: workspace.commit, run,
261
+ });
262
+ publicSnapshots.set(contextRoot, snapshot);
263
+ resources.push({ tempRoot: snapshot.contextRoot });
264
+ }
314
265
  }
315
- destinations.add(destination);
316
266
  }
317
267
  }
318
- inside("/config", component.context || ".");
319
- if (component.target != null && (typeof component.target !== "string" || !/^[a-zA-Z0-9_.-]+$/.test(component.target))) {
320
- throw new Error(`${name} target 必须是合法 Docker stage`);
321
- }
322
- if (component.platform != null && (typeof component.platform !== "string"
323
- || !SAFE_DOCKER_PLATFORM.test(component.platform))) {
324
- throw new Error(`${name} platform 必须是 linux/amd64 等合法 Docker 平台`);
325
- }
326
- if (component.mutableTags != null && typeof component.mutableTags !== "boolean") {
327
- throw new Error(`${name} mutableTags 必须是布尔值`);
328
- }
329
- if (component.tagPrefix != null && (typeof component.tagPrefix !== "string"
330
- || !/^[A-Za-z0-9_][A-Za-z0-9_.-]{0,87}$/.test(component.tagPrefix))) {
331
- throw new Error(`${name} tagPrefix 必须是 1 到 88 位合法 Docker 标签前缀`);
332
- }
333
- if (component.buildStrategy != null && !BUILD_STRATEGIES.has(component.buildStrategy)) {
334
- throw new Error(`${name} buildStrategy 只支持 artifact 或 source`);
335
- }
336
- if (component.buildStrategy === "source" && component.files != null) {
337
- throw new Error(`${name} source 构建不能同时配置 files 产物上下文`);
338
- }
339
- if (component.monorepoContextFiles != null) {
340
- if (component.buildStrategy !== "source") throw new Error(`${name} monorepoContextFiles 仅用于 source 构建`);
341
- normalizeMonorepoContextFiles(component.monorepoContextFiles);
342
- }
343
- if (component.projectInstall != null) {
344
- if (typeof component.projectInstall !== "boolean" || !component.source || component.buildStrategy !== "source" || component.monorepoContextFiles != null) {
345
- throw new Error(`${name} projectInstall 必须是布尔值,只用于外部源码构建,不能与 monorepoContextFiles 同时配置`);
268
+ return configuration;
269
+ }
270
+
271
+ function pushReleaseImages(results, { projectDir, run, capture }) {
272
+ // 整组构建及校验通过后才推送。Registry 的多次 push 不具备事务性,
273
+ // 网络失败可能留下部分镜像;不打印成功汇总,部署端仍需校验整组镜像齐备。
274
+ for (const result of results) {
275
+ run("docker", ["push", result.image], { cwd: projectDir });
276
+ if (result.releaseId) {
277
+ result.digest = readRegistryDigest(capture, result.image);
278
+ result.deployImage = `${result.image.slice(0, result.image.lastIndexOf(":"))}@${result.digest}`;
279
+ run("docker", ["pull", "--platform", result.provenance.platform, result.deployImage], { cwd: projectDir });
280
+ if (capture("docker", ["image", "inspect", "--format", "{{.Id}}", result.deployImage]) !== result.imageId) {
281
+ throw new Error("Registry digest 对应的内容与本地已验证镜像不一致");
282
+ }
346
283
  }
284
+ if (result.latestImage) run("docker", ["push", result.latestImage], { cwd: projectDir });
285
+ result.pushed = true;
347
286
  }
348
- if (component.releaseIdentity != null && (typeof component.releaseIdentity !== "boolean"
349
- || component.buildStrategy !== "source" || !component.source)) {
350
- throw new Error(`${name} releaseIdentity 仅支持外部 source 构建的布尔值`);
351
- }
352
- if (component.workspaceRef != null && (typeof component.workspaceRef !== "string"
353
- || !SAFE_GIT_NAME.test(component.workspaceRef) || !component.workspaceRef.includes("/") || component.workspaceRef.includes(".."))) {
354
- throw new Error(`${name} workspaceRef 必须使用 remote/branch`);
287
+ // 全组精确镜像均验证成功后才更新环境入口;部署端立即解析为 digest,之后不再读取可变标签。
288
+ for (const result of results.filter((entry) => entry.channelImage)) {
289
+ run("docker", ["tag", result.imageId, result.channelImage], { cwd: projectDir });
290
+ run("docker", ["push", result.channelImage], { cwd: projectDir });
291
+ if (readRegistryDigest(capture, result.channelImage) !== result.digest) throw new Error("环境最新镜像入口与本次发布内容不一致");
355
292
  }
356
- if (component.releaseIdentity && (component.tagPrefix || "").length > 74) throw new Error(`${name} 唯一发布标签的前缀过长`);
357
- if (component.releaseIdentity && !component.platform) throw new Error(`${name} 唯一发布必须明确声明 platform`);
358
- if (component.releaseChannel != null && (typeof component.releaseChannel !== "boolean" || !component.releaseIdentity)) {
359
- throw new Error(`${name} releaseChannel 仅支持启用 releaseIdentity 的布尔值`);
360
- }
361
- if (component.buildArgs != null && (!component.buildArgs || typeof component.buildArgs !== "object"
362
- || Array.isArray(component.buildArgs) || Object.entries(component.buildArgs).some(([key, value]) =>
363
- !/^[A-Z_][A-Z0-9_]*$/.test(key) || !["string", "number", "boolean"].includes(typeof value)))) {
364
- throw new Error(`${name} buildArgs 必须是合法构建参数对象`);
365
- }
366
- if (component.requiredFiles) {
367
- if (!Array.isArray(component.requiredFiles)) throw new Error(`${name} requiredFiles 必须是数组`);
368
- for (const file of component.requiredFiles) inside("/config", file);
369
- }
370
- if (component.files) {
371
- if (!Array.isArray(component.files) || component.files.length === 0) throw new Error(`${name} files 必须是非空数组`);
372
- for (const file of component.files) { inside("/config", file.from); inside("/config", file.to); }
373
- }
374
- if (component.check) {
375
- const { entrypoint, args, addHosts = [] } = component.check;
376
- if (typeof entrypoint !== "string" || !entrypoint || !Array.isArray(args)
377
- || !args.every((arg) => typeof arg === "string") || !Array.isArray(addHosts)
378
- || !addHosts.every((host) => typeof host === "string" && host.includes(":"))) {
379
- throw new Error(`${name} check 必须配置 entrypoint、args 数组及可选 addHosts 数组`);
293
+ }
294
+
295
+ function logReleaseSummary(results, { target, profile, push, cicdUrl, cicdLink, log, now }) {
296
+ // 构建结果汇总(排版与 build:docker 保持一致:✅ 完成 + 可用标签 + 可选发布系统链接)。
297
+ // 构建时已逐组件打印 frontend_commit= 等机器行,供失败前人工留档;这里汇总为可直接复制到
298
+ // 输出同时面向本地核对与 Jenkins 下拉部署,避免再手工复制提交参数。
299
+ if (results.length) {
300
+ const usesMutableTags = results.some((item) => item.latestImage);
301
+ const pushNote = push
302
+ ? profile.deployment?.ready === true
303
+ ? usesMutableTags
304
+ ? "已推送不可变提交标签和 latest 最新推送标签,可直接在 Jenkins 选择部署"
305
+ : "已推送不可变提交标签,可直接在 Jenkins 选择部署"
306
+ : usesMutableTags
307
+ ? "已推送不可变提交标签和 latest 最新推送标签;该平台尚未开放 Jenkins 部署"
308
+ : "已推送不可变提交标签;该平台尚未开放 Jenkins 部署"
309
+ : "仅本地生成,未推送镜像";
310
+ log("");
311
+ log("\x1b[0;34m==========================================");
312
+ log("✅ 完成");
313
+ log("==========================================\x1b[0m");
314
+ log(`可用标签(${pushNote}):`);
315
+ for (const r of results) {
316
+ log(` ${r.component}=${r.image} (${r.releaseId ? "唯一发布版本" : "不可变提交版本"})`);
317
+ if (r.pushed && r.channelImage) log(` ${r.component}_channel=${r.channelImage} (默认部署入口,部署时固定 digest)`);
318
+ if (r.latestImage) log(` ${r.component}_latest=${r.latestImage} (最新推送镜像,即所选平台 registry 的 latest)`);
319
+ if (r.pushed && profile.deployment?.ready === true && profile.deployment.instructions?.length) {
320
+ log("");
321
+ for (const line of profile.deployment.instructions) {
322
+ log(line.replace(/\{(releaseId|image)\}/g, (_, field) => r[field] || r.commit));
323
+ }
324
+ }
380
325
  }
381
- }
382
- if (component.health != null) {
383
- const health = component.health;
384
- if (!health || typeof health !== "object" || Array.isArray(health)
385
- || Object.keys(health).some((key) => !["timeoutSeconds", "addHost"].includes(key))
386
- || !Number.isInteger(health.timeoutSeconds) || health.timeoutSeconds < 1 || health.timeoutSeconds > 600
387
- || (health.addHost != null && (typeof health.addHost !== "string"
388
- || !/^[A-Za-z0-9][A-Za-z0-9._-]*:(?:[A-Fa-f0-9:.]+|host-gateway)$/.test(health.addHost)))) {
389
- throw new Error(`${name} health 必须声明 1 到 600 秒的 timeoutSeconds 及可选 addHost`);
326
+ if (cicdLink && profile.deployment?.ready === true) {
327
+ log("");
328
+ // 单组件推送成功后把平台与完整提交预填进 Jenkins 参数,新平台首次部署无需从历史下拉选项挑选;
329
+ // 多组件对应多个任务时保持原链接,非 /build 地址由 formatCicdLink 原样返回。
330
+ const deployLink = push && profile.deployment?.ready === true
331
+ && results.length === 1 && /^[a-z0-9]+$/.test(target)
332
+ ? formatCicdLink(cicdUrl, { platform: target, platformLabel: profile.label,
333
+ tag: results[0].commit, releaseVersion: results[0].releaseId,
334
+ date: beijingDateTime(now ? now() : undefined) })
335
+ : cicdLink;
336
+ log(deployLink);
390
337
  }
391
338
  }
392
339
  }
393
340
 
394
- function execute(command, args, options = {}) {
395
- return execFileSync(command, args, { stdio: "inherit", ...options });
396
- }
397
-
398
341
  async function runTargetRelease(options = {}, dependencies = {}) {
399
342
  const projectDir = path.resolve(options.projectDir || process.cwd());
400
343
  const config = loadDockerConfig({ projectDir, configPath: options.config,
@@ -404,11 +347,12 @@ async function runTargetRelease(options = {}, dependencies = {}) {
404
347
  const releaseScripts = config?.releaseScripts || {};
405
348
  const releaseContext = detectReleaseContext({ projectDir });
406
349
  const log = dependencies.log || console.log;
407
- const cicdLink = formatCicdLink(options.cicdUrl);
408
350
  const target = options.target || await (dependencies.selectOption || selectOption)("请选择构建平台",
409
351
  Object.entries(targets).map(([value, item]) => ({ value, label: item.label || value })));
410
352
  if (target === EXIT_SELECTION) return { cancelled: true };
411
353
  const profile = targets[target];
354
+ const cicdUrl = options.cicdUrl ?? profile?.cicdUrl ?? config.cicdUrl;
355
+ const cicdLink = formatCicdLink(cicdUrl);
412
356
  if (profile && !profile.components && profile.file) {
413
357
  // 旧目标只有 Compose 文件,保留既有镜像/版本语义,不把前端目标静默升级为前后端生产发布。
414
358
  const components = options.components || await (dependencies.selectOptions || selectOptions)("请选择构建范围",
@@ -419,8 +363,13 @@ async function runTargetRelease(options = {}, dependencies = {}) {
419
363
  }
420
364
  log(`平台 ${profile.label || target} 使用 Compose 配置中的镜像标签,不自动升级版本;不生成 qc 镜像。`);
421
365
  if (!options.dryRun) await checkDocker(dependencies.run || execute, projectDir, false, dependencies);
422
- return (dependencies.composeRelease || composeRelease)({ projectDir, file: profile.file,
366
+ const result = await (dependencies.composeRelease || composeRelease)({ projectDir, file: profile.file,
423
367
  bump: "none", push: Boolean(options.push), dryRun: Boolean(options.dryRun) });
368
+ if (!options.dryRun && cicdLink && profile.deployment?.ready !== false) {
369
+ log("");
370
+ log(cicdLink);
371
+ }
372
+ return result;
424
373
  }
425
374
  if (!profile?.components) throw new Error(`平台 ${target} 未配置 components`);
426
375
  validateReleaseProfile(profile, target);
@@ -521,271 +470,25 @@ async function runTargetRelease(options = {}, dependencies = {}) {
521
470
  };
522
471
  let releaseError;
523
472
  try {
524
- let configuration;
525
- if (profile.recordConfigurationRevision || plan.some((item) => item.dockerfileFromConfig || item.contextFiles)) {
526
- const commit = capture("git", ["-C", projectDir, "rev-parse", "HEAD"]).toLowerCase();
527
- if (!/^[a-f0-9]{40}$/.test(commit)) throw new Error("无法冻结部署配置版本");
528
- configuration = { sourceDir: projectDir, commit };
529
- verifyFrozen(configuration, "部署配置");
530
- workspaces.set(projectDir, configuration);
531
- }
532
- // 所有来源先冻结,再开始任何镜像构建。相同仓库和分支只 fetch 一次,
533
- // worktree 使用完整 SHA,后续远端分支前移不会把同一组镜像拆成不同版本。
534
- for (const item of plan) {
535
- const directory = item.source?.directory || projectDir;
536
- const sourceKey = JSON.stringify([directory, item.source?.branch || null]);
537
- let frozen = sources.get(sourceKey);
538
- if (!frozen) {
539
- let sourceDir = projectDir;
540
- let commit;
541
- if (item.source) {
542
- run("git", ["-C", directory, "fetch", "origin"], { cwd: projectDir });
543
- commit = capture("git", ["-C", directory, "rev-parse", `origin/${item.source.branch}^{commit}`]).toLowerCase();
544
- if (!/^[a-f0-9]{40}$/.test(commit)) throw new Error(`${item.name} 无法冻结合法的源码提交`);
545
- const tempRoot = io.mkdtempSync(path.join(os.tmpdir(), "infly-image-"));
546
- sourceDir = path.join(tempRoot, "source");
547
- // add 失败时也保留清理记录;不能安全移除 worktree 时留下目录供人工恢复。
548
- resources.push({ tempRoot, worktree: sourceDir, repository: directory });
549
- run("git", ["-C", directory, "worktree", "add", "--detach", sourceDir, commit], { cwd: projectDir });
550
- } else {
551
- commit = capture("git", ["-C", sourceDir, "rev-parse", "HEAD"]).toLowerCase();
552
- }
553
- if (!/^[a-f0-9]{40}$/.test(commit)) throw new Error(`${item.name} 无法冻结合法的源码提交`);
554
- frozen = { sourceDir, commit };
555
- sources.set(sourceKey, frozen);
556
- }
557
- const git = (...args) => capture("git", ["-C", frozen.sourceDir, ...args]);
558
- if (git("status", "--porcelain", "--untracked-files=all")) throw new Error(`${item.name} 仓库存在未提交改动`);
559
- const expectedRef = item.source ? null : item.expectedRef;
560
- if (git("rev-parse", "HEAD").toLowerCase() !== frozen.commit || (expectedRef
561
- && frozen.commit !== git("rev-parse", `${expectedRef}^{commit}`).toLowerCase())) {
562
- throw new Error(`${item.name} HEAD 与 ${expectedRef || "冻结提交"} 不一致,请先核对并 fetch 对应仓库`);
563
- }
564
- item.frozen = frozen;
565
- item.releaseContext = item.source
566
- ? ((!item.source.standalone && (item.dockerfileFromConfig || item.contextFiles))
567
- ? (dependencies.detectReleaseContext || detectReleaseContext)({ projectDir: item.source.directory })
568
- : { mode: "standalone", contextRoot: frozen.sourceDir, projectRelativeDir: "." })
569
- : releaseContext;
570
- if (item.source && item.releaseContext.mode === "standalone") {
571
- item.releaseContext = { ...item.releaseContext, contextRoot: frozen.sourceDir, projectRelativeDir: "." };
572
- }
573
- if (item.buildStrategy === "source" && item.releaseContext.mode === "monorepo") {
574
- const contextRoot = item.releaseContext.contextRoot;
575
- let workspace = workspaces.get(contextRoot);
576
- if (!workspace) {
577
- const revision = capture("git", ["-C", contextRoot, "rev-parse", "HEAD"]).toLowerCase();
578
- if (!/^[a-f0-9]{40}$/.test(revision)) throw new Error(`${item.name} 无法解析合法的 monorepo revision`);
579
- workspace = { sourceDir: contextRoot, commit: revision };
580
- verifyFrozen(workspace, `${item.name} 的 monorepo 构建上下文`);
581
- workspaces.set(contextRoot, workspace);
582
- }
583
- item.workspace = workspace;
584
- if (item.projectInstall) {
585
- const synchronized = dependencies.rootSynchronization;
586
- if (synchronized?.verified && synchronized.workspaceRoot === contextRoot && synchronized.revision === workspace.commit) {
587
- workspace.remote = { expectedRef: synchronized.expectedRef, revision: synchronized.revision, verified: true };
588
- }
589
- if (options.push && !workspace.remote) {
590
- if (!item.workspaceRef) throw new Error(`${item.name} 正式源码发布必须配置 workspaceRef`);
591
- workspace.remote = verifyWorkspaceRemote({ workspaceRoot: contextRoot, revision: workspace.commit,
592
- expectedRef: item.workspaceRef, capture });
593
- }
594
- if (workspace.remote && item.workspaceRef !== workspace.remote.expectedRef) throw new Error("同一主仓不能使用不同的 workspaceRef");
595
- if (!publicSnapshots.has(contextRoot)) {
596
- const snapshot = (dependencies.prepareWorkspaceSnapshot || prepareWorkspaceSnapshot)({
597
- workspaceRoot: contextRoot, revision: workspace.commit, run,
598
- });
599
- publicSnapshots.set(contextRoot, snapshot);
600
- resources.push({ tempRoot: snapshot.contextRoot });
601
- }
602
- }
603
- }
604
- }
473
+ const configuration = freezeReleaseSources(plan, {
474
+ profile, projectDir, releaseContext, push: options.push, dependencies,
475
+ sources, workspaces, publicSnapshots, resources, verifyFrozen, io, run, capture,
476
+ });
605
477
  for (const item of plan) {
606
- const { sourceDir, commit } = item.frozen;
607
- let tempRoot;
608
- verifyFrozen(item.frozen, item.name);
609
- if (item.source) {
610
- const sourceLabel = item.name === "backend" ? "后端" : (item.label || item.name);
611
- log(`\x1b[0;32m✓ ${sourceLabel}构建分支:${item.source.branch}\x1b[0m`);
612
- }
613
- const buildStrategy = item.buildStrategy || "artifact";
614
- const componentReleaseContext = item.releaseContext;
615
- let buildProjectDir = componentReleaseContext.projectRelativeDir;
616
- let context = buildStrategy === "source"
617
- ? componentReleaseContext.contextRoot
618
- : inside(sourceDir, item.context || ".");
619
- let dockerfile = inside(sourceDir, item.dockerfile || "Dockerfile");
620
- let workspaceRevision;
621
- let internalPackages;
622
- if (buildStrategy === "source" && componentReleaseContext.mode === "standalone" && item.projectInstall) {
623
- const prepared = (dependencies.prepareStandaloneInstallContext || prepareStandaloneInstallContext)({
624
- sourceDir,
625
- registryManifest: dependencies.registryManifest || ((name) => {
626
- const invocation = buildExecutableSpawn("pnpm", ["view", `${name}@latest`, "version", "dependencies", "optionalDependencies", "peerDependencies", "--json"],
627
- { platform: dependencies.platform, env: dependencies.env });
628
- return JSON.parse(capture(invocation.command, invocation.args));
629
- }),
630
- });
631
- context = prepared.contextRoot;
632
- tempRoot = context;
633
- resources.push({ tempRoot });
634
- internalPackages = prepared.packages;
635
- buildProjectDir = ".";
636
- }
637
- if (buildStrategy === "source" && componentReleaseContext.mode === "monorepo") {
638
- verifyFrozen(item.workspace, `${item.name} 的 monorepo 构建上下文`);
639
- workspaceRevision = item.workspace.commit;
640
- const prepared = item.projectInstall
641
- ? (dependencies.prepareProjectInstallContext || prepareProjectInstallContext)({
642
- workspaceRoot: publicSnapshots.get(componentReleaseContext.contextRoot).contextRoot,
643
- sourceDir,
644
- })
645
- : (dependencies.prepareMinimalMonorepoContext || prepareMinimalMonorepoContext)({
646
- workspaceRoot: componentReleaseContext.contextRoot,
647
- projectDir: item.source ? item.source.directory : sourceDir,
648
- additionalFiles: item.monorepoContextFiles || [],
649
- ...(item.source ? { sourceDir } : {}),
650
- io,
651
- });
652
- tempRoot = prepared.contextRoot;
653
- resources.push({ tempRoot });
654
- context = prepared.contextRoot;
655
- internalPackages = prepared.packages;
656
- buildProjectDir = prepared.projectRelativeDir;
657
- dockerfile = inside(context, `${prepared.projectRelativeDir}/${item.dockerfile || "Dockerfile"}`);
658
- log(item.projectInstall
659
- ? `项目安装上下文: 自身 workspace/lockfile + 临时源码安装锁 + ${prepared.packages.join(", ")}`
660
- : `最小上下文: ${prepared.projectRelativeDir} + packages + 根安装文件 + ${item.monorepoContextFiles?.length || 0} 个显式声明文件`);
661
- }
662
- // 部署仓提供 Dockerfile/运行配置;独立模式也先复制上下文,绝不改写冻结源码。
663
- if (item.contextFiles) {
664
- if (!tempRoot) {
665
- tempRoot = io.mkdtempSync(path.join(os.tmpdir(), "infly-image-context-"));
666
- resources.push({ tempRoot });
667
- context = path.join(tempRoot, "context");
668
- io.cpSync(sourceDir, context, { recursive: true, dereference: false,
669
- filter: (file) => !path.relative(sourceDir, file).split(path.sep).includes(".git") });
670
- }
671
- const destinationRoot = componentReleaseContext.mode === "monorepo"
672
- ? inside(context, buildProjectDir) : context;
673
- for (const entry of item.contextFiles) {
674
- const from = confinedPath(projectDir, entry.from, io);
675
- const to = confinedPath(destinationRoot, entry.to, io);
676
- if (!io.existsSync(from)) throw new Error(`缺少部署构建文件: ${entry.from}`);
677
- io.mkdirSync(path.dirname(to), { recursive: true });
678
- io.cpSync(from, to, { recursive: true, dereference: true,
679
- filter: (file) => { confinedPath(projectDir, path.relative(projectDir, file), io); return true; } });
680
- }
681
- }
682
- if (item.dockerfileFromConfig) dockerfile = confinedPath(projectDir, item.dockerfileFromConfig, io);
683
- const effectiveBuildArgs = {
684
- ...(item.buildArgs || {}),
685
- ...(buildStrategy === "source" ? { BUILD_MODE: componentReleaseContext.mode, PROJECT_DIR: buildProjectDir } : {}),
686
- ...(item.projectInstall && componentReleaseContext.mode === "standalone" ? { REFRESH_INTERNAL: true } : {}),
687
- };
688
- let provenance;
689
- const releaseId = item.releaseIdentity ? createReleaseId(commit, dependencies.releaseToken?.()) : commit;
690
- if (item.releaseIdentity) {
691
- if (!tempRoot) throw new Error("唯一发布标识必须使用隔离构建上下文");
692
- provenance = createBuildProvenance({ releaseId, component: item.name, businessRevision: commit,
693
- workspaceRevision, configurationRevision: configuration?.commit,
694
- workspaceRemote: item.workspace?.remote, platform: item.platform || "linux/amd64",
695
- mode: componentReleaseContext.mode, target, buildArgs: effectiveBuildArgs });
696
- provenance.internalPackages = internalPackages || [];
697
- io.writeFileSync(path.join(context, ".infly-release.json"), `${JSON.stringify(provenance, null, 2)}\n`);
698
- }
699
- for (const file of item.requiredFiles || []) {
700
- if (!io.existsSync(inside(sourceDir, file))) throw new Error(`缺少必需构建产物: ${file}`);
701
- }
702
- if (item.files) {
703
- if (!tempRoot) {
704
- tempRoot = io.mkdtempSync(path.join(os.tmpdir(), "infly-image-"));
705
- resources.push({ tempRoot });
706
- }
707
- context = path.join(tempRoot, "context");
708
- io.mkdirSync(context, { recursive: true });
709
- for (const file of item.files) {
710
- const from = inside(sourceDir, file.from);
711
- const to = inside(context, file.to);
712
- // 仅复制配置声明的产物,避免把整个 monorepo 发送给 Docker。
713
- io.mkdirSync(path.dirname(to), { recursive: true });
714
- io.cpSync(from, to, { recursive: true, dereference: false });
715
- }
716
- dockerfile = inside(context, item.dockerfile || "Dockerfile");
717
- }
718
- if (!io.existsSync(dockerfile)) throw new Error(`缺少 Dockerfile: ${dockerfile}`);
719
- const image = `${item.repository}:${item.tagPrefix || ""}${releaseId}`;
720
- const latestImage = item.mutableTags === false ? null : `${item.repository}:latest`;
721
- // --load 只把当前构建节点平台的镜像载入本地镜像存储;发布流程直接使用单平台镜像。
722
- const buildOptions = ["buildx", "build", "--load", "--file", dockerfile];
723
- if (item.platform) buildOptions.push("--platform", item.platform);
724
- if (item.target) buildOptions.push("--target", item.target);
725
- const buildArgs = effectiveBuildArgs;
726
- for (const [key, value] of Object.entries(buildArgs)) {
727
- buildOptions.push("--build-arg", `${key}=${value}`);
728
- }
729
- run("docker", [...buildOptions,
730
- "--label", `org.opencontainers.image.revision=${commit}`, "--label", `org.opencontainers.image.version=${releaseId}`,
731
- ...(item.releaseIdentity ? ["--label", `com.infly.release.id=${releaseId}`] : []),
732
- ...(workspaceRevision ? ["--label", `com.infly.workspace.revision=${workspaceRevision}`] : []),
733
- ...(configuration ? ["--label", `com.infly.deployment.revision=${configuration.commit}`] : []),
734
- "--label", `com.infly.platform=${target}`, "--tag", image,
735
- ...(latestImage ? ["--tag", latestImage] : []), context], { cwd: projectDir });
736
- if (capture("docker", ["image", "inspect", "--format", '{{ index .Config.Labels "org.opencontainers.image.revision" }}', image]) !== commit) {
737
- throw new Error(`${item.name} 镜像 revision 校验失败`);
738
- }
739
- if (item.check) {
740
- const hosts = (item.check.addHosts || []).flatMap((host) => ["--add-host", host]);
741
- run("docker", ["run", "--rm", ...hosts, "--entrypoint", item.check.entrypoint, image, ...item.check.args], { cwd: projectDir });
742
- }
478
+ const built = buildTargetImage(item, {
479
+ target, configuration, projectDir, publicSnapshots, resources, verifyFrozen,
480
+ io, run, capture, log, dependencies, buildExecutableSpawn,
481
+ });
743
482
  if (item.health) {
744
- await (dependencies.healthCheckImage || healthCheckImage)(image, {
483
+ await (dependencies.healthCheckImage || healthCheckImage)(built.image, {
745
484
  cwd: projectDir, healthTimeout: String(item.health.timeoutSeconds), healthAddHost: item.health.addHost,
746
485
  });
747
486
  }
748
- log(`${item.name}_commit=${commit}`);
749
- log(`${item.name}=${image}`);
750
- if (latestImage) log(`${item.name}_latest=${latestImage}`);
751
- const identity = {};
752
- if (item.releaseIdentity) {
753
- identity.releaseId = releaseId;
754
- identity.imageId = capture("docker", ["image", "inspect", "--format", "{{.Id}}", image]);
755
- if (!/^sha256:[0-9a-f]{64}$/.test(identity.imageId)) throw new Error("本地镜像内容 ID 无效");
756
- identity.provenance = provenance;
757
- }
758
- const channelImage = item.releaseChannel ? `${item.repository}:${item.tagPrefix || ""}${target}-latest` : null;
759
- if (channelImage && !/^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$/.test(channelImage.slice(channelImage.lastIndexOf(":") + 1))) {
760
- throw new Error("环境最新镜像标签无效");
761
- }
762
- results.push({ component: item.name, commit, image, latestImage, ...(channelImage ? { channelImage } : {}), pushed: false, ...identity });
487
+ results.push(finishTargetImage(item, built, { target, capture, log }));
763
488
  }
764
489
  for (const frozen of sources.values()) verifyFrozen(frozen, frozen.sourceDir);
765
490
  for (const frozen of workspaces.values()) verifyFrozen(frozen, "monorepo 构建上下文");
766
- // 整组构建及校验通过后才推送。Registry 的多次 push 不具备事务性,
767
- // 网络失败可能留下部分镜像;不打印成功汇总,部署端仍需校验整组镜像齐备。
768
- if (options.push) {
769
- for (const result of results) {
770
- run("docker", ["push", result.image], { cwd: projectDir });
771
- if (result.releaseId) {
772
- result.digest = readRegistryDigest(capture, result.image);
773
- result.deployImage = `${result.image.slice(0, result.image.lastIndexOf(":"))}@${result.digest}`;
774
- run("docker", ["pull", "--platform", result.provenance.platform, result.deployImage], { cwd: projectDir });
775
- if (capture("docker", ["image", "inspect", "--format", "{{.Id}}", result.deployImage]) !== result.imageId) {
776
- throw new Error("Registry digest 对应的内容与本地已验证镜像不一致");
777
- }
778
- }
779
- if (result.latestImage) run("docker", ["push", result.latestImage], { cwd: projectDir });
780
- result.pushed = true;
781
- }
782
- // 全组精确镜像均验证成功后才更新环境入口;部署端立即解析为 digest,之后不再读取可变标签。
783
- for (const result of results.filter((entry) => entry.channelImage)) {
784
- run("docker", ["tag", result.imageId, result.channelImage], { cwd: projectDir });
785
- run("docker", ["push", result.channelImage], { cwd: projectDir });
786
- if (readRegistryDigest(capture, result.channelImage) !== result.digest) throw new Error("环境最新镜像入口与本次发布内容不一致");
787
- }
788
- }
491
+ if (options.push) pushReleaseImages(results, { projectDir, run, capture });
789
492
  } catch (error) {
790
493
  releaseError = error;
791
494
  } finally {
@@ -816,43 +519,7 @@ async function runTargetRelease(options = {}, dependencies = {}) {
816
519
  log(`release_record=${record}`);
817
520
  }
818
521
 
819
- // 构建结果汇总(排版与 build:docker 保持一致:✅ 完成 + 可用标签 + 可选发布系统链接)。
820
- // 构建时已逐组件打印 frontend_commit= 等机器行,供失败前人工留档;这里汇总为可直接复制到
821
- // 输出同时面向本地核对与 Jenkins 下拉部署,避免再手工复制提交参数。
822
- if (results.length) {
823
- const usesMutableTags = results.some((item) => item.latestImage);
824
- const pushNote = options.push
825
- ? profile.deployment?.ready === true
826
- ? usesMutableTags
827
- ? "已推送不可变提交标签和 latest 最新推送标签,可直接在 Jenkins 选择部署"
828
- : "已推送不可变提交标签,可直接在 Jenkins 选择部署"
829
- : usesMutableTags
830
- ? "已推送不可变提交标签和 latest 最新推送标签;该平台尚未开放 Jenkins 部署"
831
- : "已推送不可变提交标签;该平台尚未开放 Jenkins 部署"
832
- : "仅本地生成,未推送镜像";
833
- log("");
834
- log("\x1b[0;34m==========================================");
835
- log("✅ 完成");
836
- log("==========================================\x1b[0m");
837
- log(`可用标签(${pushNote}):`);
838
- for (const r of results) {
839
- log(` ${r.component}=${r.image} (${r.releaseId ? "唯一发布版本" : "不可变提交版本"})`);
840
- if (r.pushed && r.channelImage) log(` ${r.component}_channel=${r.channelImage} (默认部署入口,部署时固定 digest)`);
841
- if (r.latestImage) log(` ${r.component}_latest=${r.latestImage} (最新推送镜像,即所选平台 registry 的 latest)`);
842
- }
843
- if (cicdLink && profile.deployment?.ready === true) {
844
- log("");
845
- // 单组件推送成功后把平台与完整提交预填进 Jenkins 参数,新平台首次部署无需从历史下拉选项挑选;
846
- // 多组件对应对应多个任务时保持原链接,非 /build 地址由 formatCicdLink 原样返回。
847
- const deployLink = options.push && profile.deployment?.ready === true
848
- && results.length === 1 && /^[a-z0-9]+$/.test(target)
849
- ? formatCicdLink(options.cicdUrl, { platform: target, platformLabel: profile.label,
850
- tag: results[0].commit, releaseVersion: results[0].releaseId,
851
- date: beijingDateTime((dependencies.now || (() => new Date()))()) })
852
- : cicdLink;
853
- log(deployLink);
854
- }
855
- }
522
+ logReleaseSummary(results, { target, profile, push: options.push, cicdUrl, cicdLink, log, now: dependencies.now });
856
523
  return { target, results };
857
524
  }
858
525