diff --git a/.github/workflows/macos-intel-package.yml b/.github/workflows/macos-intel-package.yml index 5bf1b2f484..285dd5df3c 100644 --- a/.github/workflows/macos-intel-package.yml +++ b/.github/workflows/macos-intel-package.yml @@ -214,14 +214,34 @@ jobs: - name: Archive verified retained build id: archive working-directory: artifact-archiver - run: node --import tsx apps/desktop/scripts/archive-desktop-ci.ts - - name: Retain installers for the selected mode + run: node --import tsx apps/desktop/scripts/archive-desktop-ci.ts --split-macos + - name: Retain package metadata if: success() uses: actions/upload-artifact@v7.0.1 with: - name: ${{ env.DESKTOP_ARCHIVE_NAME }} + name: ${{ steps.archive.outputs.metadata-name }} path: ${{ steps.archive.outputs.path }} archive: false if-no-files-found: error retention-days: 14 overwrite: true + - name: Retain DMG installer + if: success() + uses: actions/upload-artifact@v7.0.1 + with: + name: ${{ steps.archive.outputs.dmg-name }} + path: ${{ steps.archive.outputs.dmg-path }} + archive: false + if-no-files-found: error + retention-days: 14 + overwrite: true + - name: Retain update ZIP + if: success() + uses: actions/upload-artifact@v7.0.1 + with: + name: ${{ steps.archive.outputs.update-name }} + path: ${{ steps.archive.outputs.update-path }} + archive: false + if-no-files-found: error + retention-days: 14 + overwrite: true diff --git a/.github/workflows/macos-package.yml b/.github/workflows/macos-package.yml index 7b9022bbfb..1094ff4ab1 100644 --- a/.github/workflows/macos-package.yml +++ b/.github/workflows/macos-package.yml @@ -211,14 +211,34 @@ jobs: - name: Archive verified retained build id: archive working-directory: artifact-archiver - run: node --import tsx apps/desktop/scripts/archive-desktop-ci.ts - - name: Retain installers for the selected mode + run: node --import tsx apps/desktop/scripts/archive-desktop-ci.ts --split-macos + - name: Retain package metadata if: success() uses: actions/upload-artifact@v7.0.1 with: - name: ${{ env.DESKTOP_ARCHIVE_NAME }} + name: ${{ steps.archive.outputs.metadata-name }} path: ${{ steps.archive.outputs.path }} archive: false if-no-files-found: error retention-days: 14 overwrite: true + - name: Retain DMG installer + if: success() + uses: actions/upload-artifact@v7.0.1 + with: + name: ${{ steps.archive.outputs.dmg-name }} + path: ${{ steps.archive.outputs.dmg-path }} + archive: false + if-no-files-found: error + retention-days: 14 + overwrite: true + - name: Retain update ZIP + if: success() + uses: actions/upload-artifact@v7.0.1 + with: + name: ${{ steps.archive.outputs.update-name }} + path: ${{ steps.archive.outputs.update-path }} + archive: false + if-no-files-found: error + retention-days: 14 + overwrite: true diff --git a/apps/desktop-publisher/src/preflight-desktop-publish.mjs b/apps/desktop-publisher/src/preflight-desktop-publish.mjs index fbe6947398..f04780a284 100644 --- a/apps/desktop-publisher/src/preflight-desktop-publish.mjs +++ b/apps/desktop-publisher/src/preflight-desktop-publish.mjs @@ -27,7 +27,7 @@ export function preflightDesktopPublish(repository, inputs, api) { throw new Error('desktop publish: GitHub returned invalid artifact metadata') } for (const { name } of pages.flatMap(page => page.artifacts)) { - if (!name.replace(/\.zip$/u, '').endsWith(`-${inputs.package_run_id}-${attempt}`)) continue + if (!name.replace(/\.(?:zip|dmg)$/u, '').replace(/-(?:metadata|update)$/u, '').endsWith(`-${inputs.package_run_id}-${attempt}`)) continue const qualification = name.startsWith('windows-x64-unsigned-') ? 'unsigned' : /^macos-(?:arm64|x64)-unnotarized-debug-/u.test(name) ? 'unnotarized' : '' const diagnostic = desktopPublishQualificationError(qualification) diff --git a/apps/desktop/packaging/README.i18n.yaml b/apps/desktop/packaging/README.i18n.yaml index 03b0be6f6c..c2e2352165 100644 --- a/apps/desktop/packaging/README.i18n.yaml +++ b/apps/desktop/packaging/README.i18n.yaml @@ -27,8 +27,8 @@ en: b39449c2f945cab9 zh: a742ba9efa282be8 /desktop-packaging/macos-self-hosted-packaging: - en: 08619f0e26782636 - zh: 7c236cbe46be4a47 + en: 2f083f7868cf2c93 + zh: 231c50b4e7e667e5 /desktop-packaging/unsigned-windows-test-installer: en: f429bc0c280e2dfa zh: 4adbcc9e906bdf80 diff --git a/apps/desktop/packaging/README.md b/apps/desktop/packaging/README.md index a58322aacf..b98ffcdffc 100644 --- a/apps/desktop/packaging/README.md +++ b/apps/desktop/packaging/README.md @@ -127,7 +127,7 @@ Installer uploads store the already-compressed release files without ZIP recompr ## macOS self-hosted packaging -The [Apple Silicon workflow](../../../.github/workflows/macos-package.yml) and [Intel workflow](../../../.github/workflows/macos-intel-package.yml) produce separate arm64 and x64 packages on the Apple Silicon runner labeled `dsh-mac-package-trial`. Both share one concurrency group. The Intel workflow checks Rosetta execution before dependency installation; its selected source must include the target-aware macOS CI adapter. Both select `test` or `production` and use the existing signing, notarization and packaged-runtime checks. When the selected source's dsh ships the Computer Use bundle, each workflow builds, notarizes and stages the helper for both architectures with `scripts/cua-helper/package.ts` and `stage.ts` after the configuration check, the steps npm publication uses; `skip_notarization` does not skip the helper's notarization. A source that predates helper packaging only emits a warning, and Computer Use cannot prepare its helper in that package. Successful DMG/ZIP files and diagnostic logs are retained for 14 days without publishing a release. Installer uploads disable redundant ZIP compression. Artifacts are named `macos-----.zip`, with `arch` set to `arm64` or `x64`; entry timestamps record each retained copy’s modification time as local time in the DOS field and absolute time in the Unix field; this is not a guarantee of the original build time. The operator must verify a complete Actions run and installation on the target architecture before release qualification. The `compression_level` dropdown defaults to `3` and also offers `7`; it overrides the machine preset for this run and affects only ZIP and automatic-update downloads, not DMG. +The [Apple Silicon workflow](../../../.github/workflows/macos-package.yml) and [Intel workflow](../../../.github/workflows/macos-intel-package.yml) produce separate arm64 and x64 packages on the Apple Silicon runner labeled `dsh-mac-package-trial`. Both share one concurrency group. The Intel workflow checks Rosetta execution before dependency installation; its selected source must include the target-aware macOS CI adapter. Both select `test` or `production` and use the existing signing, notarization and packaged-runtime checks. When the selected source's dsh ships the Computer Use bundle, each workflow builds, notarizes and stages the helper for both architectures with `scripts/cua-helper/package.ts` and `stage.ts` after the configuration check, the steps npm publication uses; `skip_notarization` does not skip the helper's notarization. A source that predates helper packaging only emits a warning, and Computer Use cannot prepare its helper in that package. DMG, update ZIP, metadata ZIP and diagnostic logs are independently downloadable and retained for 14 days without publishing a release. The three package artifacts share the prefix `macos-----` (`arch` is `arm64` or `x64`), followed by `.dmg`, `-update.zip` or `-metadata.zip`. Download only the DMG for installation. The DMG and update ZIP are byte-identical copies with download names carrying the original build identity; no additional ZIP wraps them, and local download modification times are not preserved. The metadata ZIP contains the unchanged manifest and, when present, blockmap, update YAML and release record; its manifest names refer to the original retained files. COS publication and rollout continue to use those original files on the packaging machine. The operator must verify a complete Actions run and installation on the target architecture before release qualification. The `compression_level` dropdown defaults to `3` and also offers `7`; it overrides the machine preset for this run and affects only ZIP and automatic-update downloads, not DMG. Both macOS workflows require the repository variable `DESKTOP_PUBLISH_RUNNERS`, including test and unnotarized modes. Their independent `upload-artifact` job retains installer names with the original build attempt; if archival fails after packaging succeeds, rerun only that job. See [original-machine routing and recovery](../publishing/ci/README.md#recovery-and-records). diff --git a/apps/desktop/packaging/README.zh.md b/apps/desktop/packaging/README.zh.md index a96fd49b59..fbe66568b9 100644 --- a/apps/desktop/packaging/README.zh.md +++ b/apps/desktop/packaging/README.zh.md @@ -127,7 +127,7 @@ runner 的受监督启动和恢复见 [Windows runner 机器准备](../windows-s ## macOS 自托管打包 -[Apple Silicon 工作流](../../../.github/workflows/macos-package.yml)与 [Intel 工作流](../../../.github/workflows/macos-intel-package.yml)在带有 `dsh-mac-package-trial` 标签的 Apple Silicon runner 上分别生成 arm64 和 x64 安装包,两者共用一个并发组。Intel 工作流在安装依赖前检查 Rosetta 能否执行;所选源码必须包含按目标架构校验的 macOS CI 适配脚本。两者均选择 `test` 或 `production`,并复用现有签名、公证和打包运行时检查。所选源码的 dsh 随附 Computer Use 组合包时,两者都在配置检查之后用 `scripts/cua-helper/package.ts` 和 `stage.ts` 构建、公证并放入两种架构的 helper,与 npm 发布的步骤相同;`skip_notarization` 不会跳过 helper 的公证。源码早于 helper 打包支持时只输出警告,该安装包中的 Computer Use 无法准备 helper。成功的 DMG/ZIP 与诊断日志保留 14 天,不发布 release;安装包上传关闭重复 ZIP 压缩。产物名为 `macos-----.zip`,其中 `arch` 为 `arm64` 或 `x64`;条目时间以 DOS 字段的本地时间和 Unix 字段的绝对时间记录留存副本的修改时间,不保证是原始构建时间。操作人员须验收完整 Actions 运行及目标架构上的安装,才能确认可交付。`compression_level` 下拉选项默认为 `3`,也可选择 `7`;本次运行以该选项覆盖机器预设,只影响 ZIP 和自动升级下载,不影响 DMG。 +[Apple Silicon 工作流](../../../.github/workflows/macos-package.yml)与 [Intel 工作流](../../../.github/workflows/macos-intel-package.yml)在带有 `dsh-mac-package-trial` 标签的 Apple Silicon runner 上分别生成 arm64 和 x64 安装包,两者共用一个并发组。Intel 工作流在安装依赖前检查 Rosetta 能否执行;所选源码必须包含按目标架构校验的 macOS CI 适配脚本。两者均选择 `test` 或 `production`,并复用现有签名、公证和打包运行时检查。所选源码的 dsh 随附 Computer Use 组合包时,两者都在配置检查之后用 `scripts/cua-helper/package.ts` 和 `stage.ts` 构建、公证并放入两种架构的 helper,与 npm 发布的步骤相同;`skip_notarization` 不会跳过 helper 的公证。源码早于 helper 打包支持时只输出警告,该安装包中的 Computer Use 无法准备 helper。DMG、更新 ZIP、元数据 ZIP 和诊断日志可独立下载,保留 14 天,不发布 release。三个安装包相关产物共用前缀 `macos-----`(`arch` 为 `arm64` 或 `x64`),分别追加 `.dmg`、`-update.zip` 或 `-metadata.zip`。安装时只需下载 DMG。DMG 和更新 ZIP 的字节与原件一致,下载名包含原构建身份,不再套额外 ZIP,不保留下载副本的本地修改时间。元数据 ZIP 包含未修改的 manifest,以及当前模式生成的 blockmap、更新 YAML 和发布记录;manifest 中的名称指向原始留存文件。COS 发布和 rollout 继续使用打包机器上的这些原始文件。操作人员须验收完整 Actions 运行及目标架构上的安装,才能确认可交付。`compression_level` 下拉选项默认为 `3`,也可选择 `7`;本次运行以该选项覆盖机器预设,只影响 ZIP 和自动升级下载,不影响 DMG。 两个 macOS 工作流都要求仓库变量 `DESKTOP_PUBLISH_RUNNERS`,包括 test 和未公证模式。独立 `upload-artifact` job 的安装包名称保留原构建 attempt;打包成功但归档失败时,仅重跑该 job。参见[原机器路由与恢复](../publishing/ci/README.zh.md#recovery-and-records)。 diff --git a/apps/desktop/publishing/ci/README.i18n.yaml b/apps/desktop/publishing/ci/README.i18n.yaml index b660a2c29f..8a4f3036d3 100644 --- a/apps/desktop/publishing/ci/README.i18n.yaml +++ b/apps/desktop/publishing/ci/README.i18n.yaml @@ -30,8 +30,8 @@ en: ee7a9ab8c66df979 zh: c355668bc9bdb635 /desktop-ci-publication/recovery-and-records: - en: 43d8c0ca778691a4 - zh: 1823ea4b68081617 + en: 4e9784a7cc6c95d8 + zh: 06e683a65ccab295 /desktop-ci-publication/restore-a-channel: en: d82e2ccf70cce397 zh: d93dcb77cc4b463e diff --git a/apps/desktop/publishing/ci/README.md b/apps/desktop/publishing/ci/README.md index df8e8eca71..ab52fc15ea 100644 --- a/apps/desktop/publishing/ci/README.md +++ b/apps/desktop/publishing/ci/README.md @@ -93,7 +93,7 @@ Website upload reuses the original retained installer, hashes that installer alo ## Recovery and records -The archival job creates a store-mode ZIP with system bsdtar: `%SystemRoot%\System32\tar.exe` on Windows, or `/usr/bin/tar` on macOS. `invalid ZIP output settings` rejects a missing or malformed archive name and missing retained-directory, temporary-directory or `GITHUB_OUTPUT` settings before file verification. `desktop archival: SystemRoot is required to locate Windows bsdtar` reports a missing Windows system directory setting. `ZIP creation failed with ` identifies the failed archive tool; inspect its stderr, tool availability and free space in `RUNNER_TEMP`. +The archival job creates the Windows installer ZIP or macOS metadata ZIP in store mode with system bsdtar: `%SystemRoot%\System32\tar.exe` on Windows, or `/usr/bin/tar` on macOS. `invalid ZIP output settings` rejects a missing or malformed archive name and missing retained-directory, temporary-directory or `GITHUB_OUTPUT` settings before file verification. `desktop archival: SystemRoot is required to locate Windows bsdtar` reports a missing Windows system directory setting. `ZIP creation failed with ` identifies the failed archive tool; inspect its stderr, tool availability and free space in `RUNNER_TEMP`. The packaging workflows separate `package` from `upload-artifact` (GitHub artifact archival). All packaging modes, including test and unsigned builds, require `DESKTOP_PUBLISH_RUNNERS` before packaging; it routes archival to the original machine. Rerun only `upload-artifact` after an archival failure; it verifies the original manifest and hashes without rebuilding, signing or notarizing. Packaging diagnostics are best effort and do not change package success. If an archival retry stays queued without a runner, inspect the resolved runner label and upstream package outputs before treating the runner as offline. Missing outputs require operator recovery of the original retained directory and manifest; rerunning the whole workflow rebuilds the package and is not archival-only recovery. Verify output reuse in the Actions acceptance test. diff --git a/apps/desktop/publishing/ci/README.zh.md b/apps/desktop/publishing/ci/README.zh.md index ba79c1a106..596bc78765 100644 --- a/apps/desktop/publishing/ci/README.zh.md +++ b/apps/desktop/publishing/ci/README.zh.md @@ -93,7 +93,7 @@ Environment 审批限制此工作流,不限制同一机器账户运行的任 ## 恢复与记录 -归档 job 使用系统 bsdtar 创建 store 模式 ZIP:Windows 为 `%SystemRoot%\System32\tar.exe`,macOS 为 `/usr/bin/tar`。`invalid ZIP output settings` 表示归档名称缺失或格式非法,或保留目录、临时目录、`GITHUB_OUTPUT` 缺失,会在校验文件前拒绝。`desktop archival: SystemRoot is required to locate Windows bsdtar` 表示缺失 Windows 系统目录设置。`ZIP creation failed with ` 指明失败的归档工具;检查其 stderr、工具是否可用,以及 `RUNNER_TEMP` 剩余空间。 +归档 job 使用系统 bsdtar 创建 store 模式的 Windows 安装包 ZIP 或 macOS 元数据 ZIP:Windows 为 `%SystemRoot%\System32\tar.exe`,macOS 为 `/usr/bin/tar`。`invalid ZIP output settings` 表示归档名称缺失或格式非法,或保留目录、临时目录、`GITHUB_OUTPUT` 缺失,会在校验文件前拒绝。`desktop archival: SystemRoot is required to locate Windows bsdtar` 表示缺失 Windows 系统目录设置。`ZIP creation failed with ` 指明失败的归档工具;检查其 stderr、工具是否可用,以及 `RUNNER_TEMP` 剩余空间。 打包 workflow 将 `package` 与 `upload-artifact`(GitHub 产物归档)分开。所有打包模式(包括 test 和 unsigned)都要求在打包前配置 `DESKTOP_PUBLISH_RUNNERS`,用于将归档路由到原机器。归档失败后仅重跑 `upload-artifact`;它校验原始 manifest 和 hash,不重新构建、签名或公证。打包诊断归档尽力执行,不改变构建成功状态。归档重跑若一直排队且未分配 runner,应先检查解析出的 runner 标签和上游 package 输出,不能直接认定机器离线。输出缺失时需由操作者从原留存目录和 manifest 恢复文件;重跑整个 workflow 会重新构建,不属于仅归档恢复。Actions 验收须验证输出复用。 diff --git a/apps/desktop/scripts/archive-desktop-ci.ts b/apps/desktop/scripts/archive-desktop-ci.ts index 3d36b4fcc6..d292e7e8f7 100644 --- a/apps/desktop/scripts/archive-desktop-ci.ts +++ b/apps/desktop/scripts/archive-desktop-ci.ts @@ -1,6 +1,6 @@ -/** Create the verified installer ZIP and expose its path to the Actions upload step. */ +/** Prepare verified installer artifacts and expose their paths to Actions upload steps. */ import { execFileSync } from 'node:child_process' -import { appendFile, mkdtemp } from 'node:fs/promises' +import { appendFile, copyFile, mkdtemp } from 'node:fs/promises' import { join, resolve } from 'node:path' import { desktopPublicationFailure } from '@deepseek-ai/dsh-desktop-publisher/desktop-publication-failure.ts' import { desktopReleasesRoot } from './retain-desktop-ci.ts' @@ -29,19 +29,37 @@ if (process.argv[1] !== undefined && resolve(process.argv[1]) === import.meta.fi try { const { DESKTOP_ARCHIVE_NAME: name, DESKTOP_RETAINED_DIRECTORY: directory, RUNNER_TEMP: temp, GITHUB_OUTPUT: output } = process.env if (!name || !/^[a-zA-Z0-9][a-zA-Z0-9.+_-]*\.zip$/u.test(name) || !directory || !temp || !output) throw new Error('desktop archival: invalid ZIP output settings') + const split = process.argv[2] === '--split-macos' + if (process.argv.length !== (split ? 3 : 2)) throw new Error('Usage: archive-desktop-ci.ts [--split-macos]') const files = await verifyDesktopArchive(process.env) + const installers = split ? files.filter(file => /\.(?:dmg|zip)$/u.test(file)) : [] + if (split && (installers.length !== 2 || !installers.some(file => file.endsWith('.dmg')) || !installers.some(file => file.endsWith('.zip')))) { + throw new Error('desktop archival: split macOS artifacts require one DMG and one update ZIP') + } // archive: false uses the file basename; keep it equal to the upload step's name used for overwrite deletion. - const path = join(await mkdtemp(join(temp, 'desktop-archive-')), name) + const staging = await mkdtemp(join(temp, 'desktop-archive-')) + const base = name.slice(0, -4) + const path = join(staging, split ? `${base}-metadata.zip` : name) + const outputs = [`path=${path}`] + for (const file of installers) { + const kind = file.endsWith('.dmg') ? 'dmg' : 'update' + const filename = `${base}${kind === 'dmg' ? '.dmg' : '-update.zip'}` + const destination = join(staging, filename) + await copyFile(join(directory, file), destination) + outputs.push(`${kind}-path=${destination}`, `${kind}-name=${filename}`) + } + if (split) outputs.push(`metadata-name=${base}-metadata.zip`) + const archived = files.filter(file => !installers.includes(file)) const windows = process.platform === 'win32' if (windows && !process.env.SystemRoot) throw new Error('desktop archival: SystemRoot is required to locate Windows bsdtar') const tar = windows ? join(process.env.SystemRoot!, 'System32', 'tar.exe') : '/usr/bin/tar' const metadata = process.platform === 'darwin' ? ['--no-mac-metadata', '--no-xattrs'] : [] try { - execFileSync(tar, ['--format', 'zip', '--options', 'zip:compression=store', ...metadata, '-cf', path, '--', ...files], { cwd: directory, stdio: 'inherit' }) + execFileSync(tar, ['--format', 'zip', '--options', 'zip:compression=store', ...metadata, '-cf', path, '--', ...archived], { cwd: directory, stdio: 'inherit' }) } catch (cause) { throw new Error(`desktop archival: ZIP creation failed with ${tar}. Check system bsdtar availability, its stderr and free space in RUNNER_TEMP.`, { cause }) } - await appendFile(output, `path=${path}\n`) + await appendFile(output, `${outputs.join('\n')}\n`) } catch (error) { process.stderr.write(`${JSON.stringify(desktopPublicationFailure(error, 'artifact archival'))}\n`) process.exitCode = 1 diff --git a/apps/desktop/tests/desktop-publish-preflight.spec.ts b/apps/desktop/tests/desktop-publish-preflight.spec.ts index 0398d58b81..8c4b8bb724 100644 --- a/apps/desktop/tests/desktop-publish-preflight.spec.ts +++ b/apps/desktop/tests/desktop-publish-preflight.spec.ts @@ -5,6 +5,8 @@ it.each([ ['macos-x64-unnotarized-debug-1.0.0-42-2', '跳过了公证'], ['macos-arm64-unnotarized-debug-1.0.0-42-2', '跳过了公证'], ['macos-arm64-unnotarized-debug-1.0.0-42-2.zip', '跳过了公证'], + ...['arm64', 'x64'].flatMap(arch => ['.dmg', '-update.zip', '-metadata.zip'].map(suffix => + [`macos-${arch}-unnotarized-debug-1.0.0-42-2${suffix}`, '跳过了公证'])), ['windows-x64-unsigned-1.0.0-42-2.zip', '未签名'], ['windows-x64-unsigned-1.0.0-42-2', '未签名'], ])('rejects %s from paginated artifact metadata with rebuilding instructions', (name, reason) => { @@ -37,3 +39,12 @@ it.each([{ response: {} }, { response: [{ artifacts: [{}] }] }])('rejects invali expect(() => preflightDesktopPublish('owner/repo', { package_run_id: '42', package_run_attempt: '2' }, () => response)) .toThrow(/invalid artifact metadata/u) }) + +it.each(['arm64', 'x64'])('accepts notarized split %s artifacts and ignores debugging artifacts from other attempts', (arch) => { + const artifacts = ['.dmg', '-update.zip', '-metadata.zip'].flatMap(suffix => [ + { name: `macos-${arch}-notarized-1.0.0-42-2${suffix}` }, + { name: `macos-${arch}-unnotarized-debug-1.0.0-42-1${suffix}` }, + { name: `macos-${arch}-unnotarized-debug-1.0.0-142-2${suffix}` }, + ]) + expect(preflightDesktopPublish('owner/repo', { package_run_id: '42', package_run_attempt: '2' }, () => [{ artifacts }])).toBe('2') +}) diff --git a/apps/desktop/tests/retain-desktop-ci.spec.ts b/apps/desktop/tests/retain-desktop-ci.spec.ts index 48d204e522..dfdf5bb104 100644 --- a/apps/desktop/tests/retain-desktop-ci.spec.ts +++ b/apps/desktop/tests/retain-desktop-ci.spec.ts @@ -27,7 +27,7 @@ async function retainedFixture(target: 'win-x64' | 'mac-x64' | 'mac-arm64', qual : [`deepseek-harness-1.0.0-${target}-${qualification}.dmg`, `deepseek-harness-1.0.0-${target}-${qualification}.zip`]) : target === 'win-x64' ? ['deepseek-harness-1.0.0-win-x64.exe', 'deepseek-harness-1.0.0-win-x64.exe.blockmap', 'win-x64-release.json', 'nightly.yml'] : [`deepseek-harness-1.0.0-${target}.dmg`, `deepseek-harness-1.0.0-${target}.zip`, `deepseek-harness-1.0.0-${target}.zip.blockmap`, `${target}-release.json`, 'nightly-mac.yml'] - await Promise.all(names.map(name => writeFile(join(artifacts, name), 'fixture'))) + await Promise.all(names.map(name => writeFile(join(artifacts, name), `fixture ${name}`))) const env = { DSH_DESKTOP_RELEASES_DIR: '', DSH_PACKAGING_CONFIG_DIR: config, DSH_PACKAGING_PRESET: 'test', DSH_DESKTOP_TARGET_PLATFORM: target === 'win-x64' ? 'win32' : 'darwin', DSH_DESKTOP_TARGET_ARCH: target === 'mac-arm64' ? 'arm64' : 'x64', PACKAGE_SOURCE_REF: 'master', PACKAGE_SOURCE_SHA: 'b'.repeat(40), PACKAGE_VERSION: '1.0.0', @@ -124,3 +124,48 @@ it('rejects missing or ambiguous archival routing before packaging starts', () = dedicated: { label: 'dsh-shared', target: 'mac-arm64' }, other: { label: 'dsh-shared', target: 'mac-arm64' }, }) })).toThrow('unique artifact routing label') }) + +it.runIf(process.platform === 'darwin' || process.platform === 'win32').each([ + ['mac-arm64', 'notarized'], ['mac-x64', 'notarized'], ['mac-arm64', 'unnotarized'], ['mac-x64', 'unnotarized'], +] as const)('splits %s %s installers without changing retained publication inputs', async (target, qualification) => { + const { root, directory, archiveEnv, names, env } = await retainedFixture(target, qualification) + const original = await verifyRetainedDesktopRelease(desktopReleasesRoot(env), '123', '2') + const base = `macos-${target.slice(4)}-${qualification}-1.0.0-123-2` + for (const attempt of ['3', '4']) { + const output = join(root, `archive-output-${attempt}`) + execFileSync(process.execPath, ['--import', 'tsx', archiveScript, '--split-macos'], { + env: { ...process.env, ...archiveEnv, GITHUB_RUN_ATTEMPT: attempt, + DESKTOP_ARCHIVE_NAME: `${base}.zip`, GITHUB_OUTPUT: output, RUNNER_TEMP: root }, + }) + const outputs = Object.fromEntries((await readFile(output, 'utf8')).trim().split('\n').map((line) => { + const separator = line.indexOf('=') + return [line.slice(0, separator), line.slice(separator + 1)] + })) + expect(outputs['dmg-name']).toBe(`${base}.dmg`) + expect(outputs['update-name']).toBe(`${base}-update.zip`) + expect(outputs['metadata-name']).toBe(`${base}-metadata.zip`) + for (const [kind, extension] of [['dmg', '.dmg'], ['update', '.zip']]) { + const name = names.find(file => file.endsWith(extension!))! + expect(await readFile(outputs[`${kind}-path`]!)).toEqual(await readFile(join(directory, name))) + } + const metadata = unzipSync(await readFile(outputs.path!)) + expect(Object.keys(metadata)).toEqual(['manifest.json', ...names.filter(name => !/\.(?:dmg|zip)$/u.test(name))]) + for (const [name, bytes] of Object.entries(metadata)) expect(Buffer.from(bytes)).toEqual(await readFile(join(directory, name))) + expect(await verifyRetainedDesktopRelease(desktopReleasesRoot(env), '123', '2')).toEqual(original) + } +}) + +it.each(['wrong-runner', 'corrupted-installer', 'windows'] as const)('emits no split upload paths for %s', async (failure) => { + const { root, directory, names, archiveEnv } = await retainedFixture(failure === 'windows' ? 'win-x64' : 'mac-arm64', failure === 'windows' ? 'signed' : 'notarized') + if (failure === 'corrupted-installer') await writeFile(join(directory, names[0]!), 'corrupted') + const output = join(root, 'archive-output') + const result = spawnSync(process.execPath, ['--import', 'tsx', archiveScript, '--split-macos'], { encoding: 'utf8', + env: { ...process.env, ...archiveEnv, RUNNER_NAME: failure === 'wrong-runner' ? 'other' : archiveEnv.RUNNER_NAME, + DESKTOP_ARCHIVE_NAME: 'fixture.zip', GITHUB_OUTPUT: output, RUNNER_TEMP: root } }) + expect(result.error).toBeUndefined() + expect(result.signal).toBeNull() + expect(result.status).toBe(1) + expect(result.stderr).toContain(failure === 'wrong-runner' ? 'wrong original machine' + : failure === 'windows' ? 'one DMG and one update ZIP' : 'changed file') + await expect(readFile(output)).rejects.toMatchObject({ code: 'ENOENT' }) +}) diff --git a/scripts/desktop-archive-workflow-test.ts b/scripts/desktop-archive-workflow-test.ts index d0928e36a5..85ede1493e 100644 --- a/scripts/desktop-archive-workflow-test.ts +++ b/scripts/desktop-archive-workflow-test.ts @@ -18,11 +18,9 @@ export function expectDesktopArchive step.uses?.startsWith('actions/upload-artifact@')) expect(uploads).toHaveLength(count) - for (const step of uploads) { - expect(step.with?.name).toBe('${{ env.DESKTOP_ARCHIVE_NAME }}') - expect(job.env.DESKTOP_ARCHIVE_NAME).toContain('${{ needs.package.outputs.version }}') - expect(job.env.DESKTOP_ARCHIVE_NAME).toContain('${{ needs.package.outputs.attempt }}') - expect(job.env.DESKTOP_ARCHIVE_NAME).not.toContain('github.run_attempt') - } + if (count === 1) expect(uploads[0]?.with?.name).toBe('${{ env.DESKTOP_ARCHIVE_NAME }}') + expect(job.env.DESKTOP_ARCHIVE_NAME).toContain('${{ needs.package.outputs.version }}') + expect(job.env.DESKTOP_ARCHIVE_NAME).toContain('${{ needs.package.outputs.attempt }}') + expect(job.env.DESKTOP_ARCHIVE_NAME).not.toContain('github.run_attempt') return uploads } diff --git a/scripts/macos-package-workflow.spec.ts b/scripts/macos-package-workflow.spec.ts index 4f707cb99c..5c715e2842 100644 --- a/scripts/macos-package-workflow.spec.ts +++ b/scripts/macos-package-workflow.spec.ts @@ -52,7 +52,7 @@ describe.each(['arm64', 'x64'])('macOS %s packaging', (arch) => { expect(uploads[0]?.if).toBe("always() && steps.checkout.outcome == 'success'") expect(installer.if).toBe('success()') expect(installer.with?.path).toBe('${{ steps.archive.outputs.path }}') - expect(installer.with).toMatchObject({ archive: false, overwrite: true, name: '${{ env.DESKTOP_ARCHIVE_NAME }}' }) + expect(installer.with).toMatchObject({ archive: false, overwrite: true, name: '${{ steps.archive.outputs.metadata-name }}' }) }) it('defaults to notarization and labels the explicit debugging option', () => { @@ -97,7 +97,16 @@ describe.each(['arm64', 'x64'])('macOS %s packaging', (arch) => { it('passes the same target to preparation, packaging and retention', () => { const archive = workflow.jobs['upload-artifact']! - expectDesktopArchive(archive, 1) + const uploads = expectDesktopArchive(archive, 3) + expect(archive.steps.find(step => step.id === 'archive')?.run).toContain('archive-desktop-ci.ts --split-macos') + for (const [index, kind] of ['metadata', 'dmg', 'update'].entries()) { + expect(uploads[index]?.with).toMatchObject({ + name: '${{ steps.archive.outputs.' + kind + '-name }}', + path: '${{ steps.archive.outputs.' + (kind === 'metadata' ? 'path' : kind + '-path') + ' }}', + archive: false, overwrite: true, 'if-no-files-found': 'error', 'retention-days': 14, + }) + expect(uploads[index]?.if).toBe('success()') + } const job = workflow.jobs.package! expect(job.env.DSH_DESKTOP_TARGET_PLATFORM).toBe('darwin') expect(job.env.DSH_DESKTOP_TARGET_ARCH).toBe(arch)