diff --git a/packages/experimental/cua-macos/native/README.i18n.yaml b/packages/experimental/cua-macos/native/README.i18n.yaml index f18e0b3af6..d7f6930b1b 100644 --- a/packages/experimental/cua-macos/native/README.i18n.yaml +++ b/packages/experimental/cua-macos/native/README.i18n.yaml @@ -15,8 +15,8 @@ en: e8cbc43d38786c40 zh: 52b3ba85d98011b9 /dsh-cua-native-helper/build-and-service: - en: 8989d7b8892102a8 - zh: be51752344d011fa + en: f29d74be684f5840 + zh: 67233850329d1db1 /dsh-cua-native-helper/request-protocol: en: 21d92283c084d8bb zh: 7a29731b9f58c709 diff --git a/packages/experimental/cua-macos/native/README.md b/packages/experimental/cua-macos/native/README.md index 779370290d..738a852b52 100644 --- a/packages/experimental/cua-macos/native/README.md +++ b/packages/experimental/cua-macos/native/README.md @@ -41,7 +41,7 @@ The manual **Package CUA helper · macOS · arm64 + x64** [workflow](../../../.. The workflow retains `cua-helper.tgz` and `cua-helper.json`. The manifest records the original build's product version, commit and Team ID, both application digests, the source digest and the build key. [Release publish](../../../../.github/workflows/release-publish.yml) always calls this workflow, then downloads its selected run ID and artifact ID before packing the provider for npm. Staging verifies the current helper source digest and selected build key, both architectures, application generations, file bytes and executable permissions. npm publication rechecks the exact provider tarball before any registry write. Reuse preserves the original manifest and signed bytes across unrelated commits or product versions. Ordinary PR release rehearsals have no signing credentials. -**Release publish (dsh)** accepts an optional `cua_macos_run_id`: enter the numeric run ID after `/actions/runs/` in the producer's GitHub URL, not its job ID. The publisher enables `reuse` and passes this selection through the helper's `workflow_call` inputs; neither reuse input appears on the manual helper form. Leave `cua_macos_run_id` empty for automatic discovery, which searches completed runs of these two workflows created within the last 14 days for an unexpired matching artifact. Selection runs on the Mac before pnpm setup or dependency installation. A match skips installation, compilation, signing and notarization; an automatic miss rebuilds. An explicit run pins its latest attempt and selects its last executed helper job across the run history. A pack/publish-only rerun keeps the original helper artifact eligible; a newer failed helper execution blocks reuse of earlier successes. Missing or expired artifacts and mismatched inputs fail without choosing another run. A later npm failure does not invalidate a successful helper job. GitHub API failures stop selection. The summary links the actual producer; a run that only reuses an artifact does not upload another copy, so use its linked producer run for manual selection. Artifacts are retained for 14 days. Expiry or deletion after selection stops the download; it does not silently select or build different bytes. Follow the retry instructions below. +**Release publish (dsh)** accepts an optional `cua_macos_run_id`: enter the numeric run ID after `/actions/runs/` in the producer's GitHub URL, not its job ID. The publisher enables `reuse` and passes this selection through the helper's `workflow_call` inputs; neither reuse input appears on the manual helper form. Leave `cua_macos_run_id` empty for automatic discovery, which searches completed runs of these two workflows created within the last 14 days for an unexpired matching artifact. Runs with only an unqualified `cua-helper---` artifact cannot be reused. For a new release, leave the field empty to find a matching `cua-helper-macos---` artifact or build one. Selection runs on the Mac before pnpm setup or dependency installation. A match skips installation, compilation, signing and notarization; an automatic miss rebuilds. An explicit run pins its latest attempt and selects its last executed helper job across the run history. A pack/publish-only rerun keeps the original helper artifact eligible; a newer failed helper execution blocks reuse of earlier successes. Missing or expired artifacts and mismatched inputs fail without choosing another run. A later npm failure does not invalidate a successful helper job. GitHub API failures stop selection. The summary links the actual producer; a run that only reuses an artifact does not upload another copy, so use its linked producer run for manual selection. Artifacts are retained for 14 days. Expiry or deletion after selection stops the download; it does not silently select or build different bytes. Follow the retry instructions below. The [source digest](../../../../scripts/cua-helper/build-inputs.ts) covers tracked helper sources, resources, CUA/Desktop packaging scripts, both workflows, package and compiler configuration, locked dependencies, pnpm settings and patches. Tracked `node_modules` entries are also compared. Package manifest version fields are excluded; other manifest fields are retained. The build key additionally includes the preset, Node/Swift/Clang/Python versions, macOS SDK build, signing identity, Team ID and certificate-container digest; passwords are excluded. Selection independently compares the producer run's GitHub `head_sha` tree and package blobs with the current checkout, including paths, bytes and executable modes; artifact-supplied hashes cannot establish source equality. Helper dependency installation disables lifecycle scripts and pnpmfile hooks. Missing inputs or unreadable GitHub evidence fail. Artifacts without matching records require a new build. Selection still requires a Mac runner and checkout; the consuming pack job validates the downloaded application bytes. diff --git a/packages/experimental/cua-macos/native/README.zh.md b/packages/experimental/cua-macos/native/README.zh.md index ee18017d30..4bb22baabb 100644 --- a/packages/experimental/cua-macos/native/README.zh.md +++ b/packages/experimental/cua-macos/native/README.zh.md @@ -41,7 +41,7 @@ kind: "package-reference" 工作流保留 `cua-helper.tgz` 和 `cua-helper.json`。清单记录原始构建的产品版本、commit、Team ID、两份应用摘要、源码摘要和构建摘要。[Release publish](../../../../.github/workflows/release-publish.yml)始终调用该工作流,再按返回的 run ID 和 artifact ID 下载所选产物,生成 provider 的 npm 包。准备步骤校验当前 helper 的源码摘要、选定的构建摘要、两种架构、应用目录、文件字节和执行权限。npm 发布在写入注册表前重新检查实际 provider tarball。无关 commit 或产品版本变化时,复用保留原始清单和已签名字节。普通 PR 发布检查不使用签名凭据。 -**Release publish (dsh)** 接受可选的 `cua_macos_run_id`:填写构建运行页面 URL 中 `/actions/runs/` 后的数字,不填 job ID。发布工作流开启 `reuse`,并通过 helper 的 `workflow_call` 参数传入这个选择;这两个复用参数均不出现在 helper 的手动表单中。`cua_macos_run_id` 留空时自动查找,查询这两个工作流最近 14 天创建且已结束的运行,选择未过期的匹配产物。选择在 Mac 上执行,早于 pnpm 准备和依赖安装。命中时跳过安装、编译、签名和公证,自动查找未命中时重新构建。手动指定 run ID 时先固定最新 attempt,再选取该 run 历史中最后一次实际执行的 helper job。仅重跑 pack/publish 时仍可使用原 helper 产物;若更新的 helper 执行失败,则不复用更早的成功产物。产物缺失或过期、输入不匹配时直接失败,不改选其他运行。后续 npm 失败不影响成功的 helper job。GitHub API 读取失败会停止选择。运行摘要链接实际构建者;只复用产物的运行不重新上传副本,手动选择时填写摘要所链接的构建 run ID。产物保留 14 天。选择后过期或被删除会使下载失败,不自动改选或构建不同字节;按下方重试说明处理。 +**Release publish (dsh)** 接受可选的 `cua_macos_run_id`:填写构建运行页面 URL 中 `/actions/runs/` 后的数字,不填 job ID。发布工作流开启 `reuse`,并通过 helper 的 `workflow_call` 参数传入这个选择;这两个复用参数均不出现在 helper 的手动表单中。`cua_macos_run_id` 留空时自动查找,查询这两个工作流最近 14 天创建且已结束的运行,选择未过期的匹配产物。只有旧格式产物 `cua-helper---` 的运行无法复用。发起新版本发布时,将该字段留空即可查找匹配的 `cua-helper-macos---` 产物,找不到时会重新构建。选择在 Mac 上执行,早于 pnpm 准备和依赖安装。命中时跳过安装、编译、签名和公证,自动查找未命中时重新构建。手动指定 run ID 时先固定最新 attempt,再选取该 run 历史中最后一次实际执行的 helper job。仅重跑 pack/publish 时仍可使用原 helper 产物;若更新的 helper 执行失败,则不复用更早的成功产物。产物缺失或过期、输入不匹配时直接失败,不改选其他运行。后续 npm 失败不影响成功的 helper job。GitHub API 读取失败会停止选择。运行摘要链接实际构建者;只复用产物的运行不重新上传副本,手动选择时填写摘要所链接的构建 run ID。产物保留 14 天。选择后过期或被删除会使下载失败,不自动改选或构建不同字节;按下方重试说明处理。 [源码摘要](../../../../scripts/cua-helper/build-inputs.ts)覆盖受跟踪的 helper 源码、资源、CUA/Desktop 打包脚本、两份工作流、包与编译器配置、锁定依赖、pnpm 配置和补丁;受跟踪的 `node_modules` 文件也参与比较。包清单只排除版本字段,其余字段保留。构建摘要还包含 preset、Node/Swift/Clang/Python 版本、macOS SDK build、签名身份、Team ID 和证书容器摘要,不包含密码。选择时使用生产运行的 GitHub `head_sha`,独立比较对应 Git 树与包清单 blob 和当前 checkout 的路径、字节及执行权限,不能仅凭产物自报摘要认定源码一致。helper 依赖安装禁用生命周期脚本和 pnpmfile hooks。输入缺失或 GitHub 证据无法读取时失败。没有匹配记录的旧产物需要重新构建。选择仍需等待 Mac runner 并检出代码,消费产物的 pack job 再校验下载的应用字节。 diff --git a/scripts/cua-helper/select-artifact.spec.ts b/scripts/cua-helper/select-artifact.spec.ts index 002ee62fe4..cdbfc69f5d 100644 --- a/scripts/cua-helper/select-artifact.spec.ts +++ b/scripts/cua-helper/select-artifact.spec.ts @@ -72,12 +72,21 @@ it.each(['workflow', 'event', 'repository', 'head_repository', 'id', 'attempt', }, ) -it.each(['failure', 'cancelled', 'skipped', 'missing', 'duplicate'])( +it('identifies a release run missing the macOS packaging job', async () => { + const f = fixture() + f.run.path = '.github/workflows/release-publish.yml' + f.jobs[0]!.jobs = [{ name: 'cua-helper / package', conclusion: 'success', run_attempt: 2 }] + await expect(selectCuaHelperArtifact(repository, '123', key, f.api, f.matchesSource)) + .rejects.toThrow('this run contains no cua-helper-macos / package job') + expect(f.api.mock.calls.some(([path]) => path.includes('/artifacts'))).toBe(false) +}) + +it.each(['failure', 'cancelled', 'skipped', 'duplicate'])( 'rejects %s helper jobs without falling back to attempt 1', async (status) => { const f = fixture() f.run.path = '.github/workflows/release-publish.yml' f.run.conclusion = 'failure' - f.jobs[0]!.jobs = status === 'missing' ? [] : status === 'duplicate' + f.jobs[0]!.jobs = status === 'duplicate' ? [{ name: 'cua-helper-macos / package', conclusion: 'success', run_attempt: 2 }, { name: 'cua-helper-macos / package', conclusion: 'success', run_attempt: 2 }] : [{ name: 'cua-helper-macos / package', conclusion: status, run_attempt: 2 }] await expect(selectCuaHelperArtifact(repository, '123', key, f.api, f.matchesSource)).rejects.toThrow('last executed cua-helper-macos / package job did not succeed') @@ -85,15 +94,12 @@ it.each(['failure', 'cancelled', 'skipped', 'missing', 'duplicate'])( }, ) -it.each(['missing', 'expired', 'empty', 'mismatch', 'windows', 'legacy'] as const)( +it.each(['missing', 'expired', 'empty'] as const)( 'rebuilds on automatic %s but rejects the same explicit selection', async (change) => { const f = fixture() if (change === 'missing') f.artifacts.pop() if (change === 'expired') f.artifact.expired = true if (change === 'empty') f.artifact.size_in_bytes = 0 - if (change === 'mismatch') f.artifact.name = `cua-helper-macos-123-2-${'b'.repeat(64)}` - if (change === 'windows') f.artifact.name = `cua-helper-windows-123-2-${key}` - if (change === 'legacy') f.artifact.name = 'cua-helper-macos-123-2' expect(await selectCuaHelperArtifact(repository, '', key, f.api, f.matchesSource)).toBeUndefined() await expect(selectCuaHelperArtifact(repository, '123', key, f.api, f.matchesSource)).rejects.toThrow('CUA reuse: run 123:') }, @@ -129,13 +135,20 @@ it.each(['', '123'])('propagates unavailable GitHub evidence with selection %j', expect(api).toHaveBeenCalledTimes(1) }) -it('does not query job or attempt details when artifact names exclude the requested build key', async () => { +it.each([ + ['another build key', `cua-helper-macos-123-2-${'b'.repeat(64)}`], + ['no build key', 'cua-helper-macos-123-2'], + ['Windows', `cua-helper-windows-123-2-${key}`], + ['no platform', `cua-helper-123-2-${key}`], +] as const)('skips an artifact with %s in discovery and rejects it by run ID', async (_case, name) => { const f = fixture() - f.artifact.name = 'cua-helper-macos-123-2-legacy' f.artifacts.shift() + f.artifact.name = name expect(await selectCuaHelperArtifact(repository, '', key, f.api, f.matchesSource)).toBeUndefined() expect(f.api.mock.calls.map(([path]) => path).filter(path => !path.includes('/workflows/'))) .toEqual([`${base}/artifacts?per_page=100`]) + await expect(selectCuaHelperArtifact(repository, '123', key, f.api, f.matchesSource)) + .rejects.toThrow('no artifact matches') }) it.each(['123', ''])('retains the original helper after a publish-only rerun with selection %j', async (runId) => { diff --git a/scripts/cua-helper/select-artifact.ts b/scripts/cua-helper/select-artifact.ts index a935f02518..87a6996224 100644 --- a/scripts/cua-helper/select-artifact.ts +++ b/scripts/cua-helper/select-artifact.ts @@ -65,9 +65,10 @@ export async function selectCuaHelperArtifact(repository: string, runId: string, const jobName = workflow === 'cua-helper-package-macos.yml' ? 'package' : 'cua-helper-macos / package' const jobs = rows(await api(`${base}/runs/${candidate}/jobs?filter=all&per_page=100`, true), 'jobs') .filter(job => job.name === jobName) + if (jobs.length === 0) return `this run contains no ${jobName} job. Select a run that built the macOS helper` const attempts = jobs.map(job => Number(id(job.run_attempt))) assert(attempts.every(value => value <= Number(attempt)), 'CUA reuse: run advanced during selection; retry with the same run ID') - const producerAttempt = Math.max(0, ...attempts) + const producerAttempt = Math.max(...attempts) const producers = jobs.filter(job => job.run_attempt === producerAttempt) if (producers.length !== 1 || producers[0]?.conclusion !== 'success') return `the last executed ${jobName} job did not succeed` const name = `cua-helper-macos-${candidate}-${producerAttempt}-${buildKey}`