From ac73afdad9f1ea29057e69e253ebd0ad40e900e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=8D=9A=E6=9D=91=E5=AA=B7?= Date: Mon, 16 Nov 2026 21:30:54 +0800 Subject: [PATCH 01/13] ci: harden community multi-platform release --- .github/workflows/community-package.yml | 234 +++++++++++++++--- tools/__tests__/community-package.test.mjs | 95 +++++++ .../publish-community-build.test.mjs | 119 ++++++++- tools/ci/prepare-electron.mjs | 28 +++ tools/ci/prepare-installer.mjs | 6 +- tools/ci/stage-posix-device-plugin.mjs | 39 +++ tools/ci/verify-posix-installer.mjs | 145 +++++++++++ tools/publish-community-build.cjs | 86 +++++-- 8 files changed, 698 insertions(+), 54 deletions(-) create mode 100644 tools/__tests__/community-package.test.mjs create mode 100644 tools/ci/prepare-electron.mjs create mode 100644 tools/ci/stage-posix-device-plugin.mjs create mode 100644 tools/ci/verify-posix-installer.mjs diff --git a/.github/workflows/community-package.yml b/.github/workflows/community-package.yml index f8b53c0f..eb5c7fa6 100644 --- a/.github/workflows/community-package.yml +++ b/.github/workflows/community-package.yml @@ -1,6 +1,6 @@ name: community-package -# Builds the unsigned Windows community installer: OpenTest plus the plugins from -# crysound/OpenTest-Plugins (the public business plugins and the SonoDAQ device plugin). It verifies a silent install and publishes to GitHub Releases. +# 构建 Windows、Linux、macOS 社区安装包,验证安装后统一发布。 +# 三个平台共用版本;发布任务等待所有安装验证成功。 # push to main -> daily build A.B.C-dev.[.N] (prerelease, tag created on publish) # push tag vA.B.C-rc.N -> release candidate (prerelease) # push tag vA.B.C -> release (latest) @@ -20,6 +20,16 @@ on: - tools/default-plugins.mjs - tools/package.mjs - tools/packaging.mjs + - tools/packaging-platforms.mjs + - tools/package-posix-native.mjs + - tools/package-java.mjs + - tools/macos-signing.mjs + - tools/__tests__/** + - apps/** + - sdks/** + - vendor/** + - package.json + - pnpm-lock.yaml - tools/publish-community-build.cjs - tools/ci/** workflow_dispatch: @@ -34,7 +44,71 @@ concurrency: group: community-package-${{ github.ref }} cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: + version: + runs-on: ubuntu-24.04 + timeout-minutes: 10 + outputs: + version: ${{ steps.version.outputs.version }} + plugins-ref: ${{ steps.plugins.outputs.ref }} + plugins-sha: ${{ steps.plugins.outputs.sha }} + steps: + - uses: actions/checkout@v7 + with: + persist-credentials: false + - uses: actions/setup-node@v7 + with: + node-version: 22 + package-manager-cache: false + - name: Resolve package version + id: version + env: + GH_TOKEN: ${{ github.token }} + REF: ${{ github.ref }} + REF_TYPE: ${{ github.ref_type }} + shell: pwsh + run: | + if ($env:REF_TYPE -eq 'tag') { + node tools/build-version.mjs --tag $env:REF + } else { + $base = (Get-Content -LiteralPath package.json -Raw | ConvertFrom-Json).version + $existing = Join-Path $env:RUNNER_TEMP 'dev-tags.txt' + # Write the file even when no daily tag exists yet; an empty pipeline would not create it. + $tags = @(gh api "repos/$env:GITHUB_REPOSITORY/git/matching-refs/tags/v$base-dev." --paginate --jq '.[].ref') + if ($LASTEXITCODE -ne 0) { throw 'Could not list existing daily tags.' } + [System.IO.File]::WriteAllLines($existing, [string[]]$tags) + node tools/build-version.mjs --dev --existing-file $existing + } + if ($LASTEXITCODE -ne 0) { throw 'Version resolution failed.' } + - name: Resolve public plugin revision + id: plugins + env: + REF_TYPE: ${{ github.ref_type }} + REF_NAME: ${{ github.ref_name }} + REQUESTED_REF: ${{ inputs.plugins_ref }} + run: | + $repo = 'https://github.com/crysound/OpenTest-Plugins.git' + $requested = if ($env:REQUESTED_REF) { $env:REQUESTED_REF } elseif ($env:REF_TYPE -eq 'tag') { $env:REF_NAME } else { 'main' } + $ref = $requested + $sha = '' + if ($env:REF_TYPE -eq 'tag' -and -not $env:REQUESTED_REF) { + $sha = (git ls-remote $repo "refs/tags/$requested^{}" | ForEach-Object { ($_ -split '\s+')[0] } | Select-Object -First 1) + if (-not $sha) { $sha = (git ls-remote $repo "refs/tags/$requested" | ForEach-Object { ($_ -split '\s+')[0] } | Select-Object -First 1) } + if (-not $sha) { + $ref = 'main' + $sha = (git ls-remote $repo 'refs/heads/main' | ForEach-Object { ($_ -split '\s+')[0] } | Select-Object -First 1) + Write-Host "OpenTest-Plugins has no tag $requested; using main at $sha." + } + } else { + $sha = (git ls-remote $repo "refs/heads/$requested" | ForEach-Object { ($_ -split '\s+')[0] } | Select-Object -First 1) + if (-not $sha) { $sha = (git ls-remote $repo "refs/tags/$requested^{}" | ForEach-Object { ($_ -split '\s+')[0] } | Select-Object -First 1) } + if (-not $sha) { $sha = (git ls-remote $repo "refs/tags/$requested" | ForEach-Object { ($_ -split '\s+')[0] } | Select-Object -First 1) } + } + if ($sha -notmatch '^[0-9a-f]{40}$') { throw "Could not resolve OpenTest-Plugins ref: $requested" } + "ref=$ref" >> $env:GITHUB_OUTPUT + "sha=$sha" >> $env:GITHUB_OUTPUT + Write-Host "OpenTest-Plugins: $ref ($sha)" build: + needs: version name: build-community-installer runs-on: windows-latest timeout-minutes: 120 @@ -48,7 +122,6 @@ jobs: PLUGIN_PACKAGES: ${{ github.workspace }}/.runtime/ci-plugin-packages NATIVE_PLUGIN_BIN: ${{ github.workspace }}/.runtime/ci-native-plugins outputs: - version: ${{ steps.version.outputs.version }} installer-name: ${{ steps.verify.outputs.installer-name }} installer-sha256: ${{ steps.verify.outputs.installer-sha256 }} artifact-id: ${{ steps.upload.outputs.artifact-id }} @@ -62,9 +135,15 @@ jobs: uses: actions/checkout@v7 with: repository: crysound/OpenTest-Plugins - ref: ${{ inputs.plugins_ref || (github.ref_type == 'tag' && github.ref_name) || 'main' }} + ref: ${{ needs.version.outputs.plugins-ref }} path: .runtime/opentest-plugins persist-credentials: false + - name: Verify public plugin revision + env: + EXPECTED_PLUGINS_SHA: ${{ needs.version.outputs.plugins-sha }} + run: | + $actual = (git -C $env:PLUGINS_ROOT rev-parse HEAD).Trim() + if ($actual -ne $env:EXPECTED_PLUGINS_SHA) { throw "OpenTest-Plugins revision mismatch: $actual" } - uses: actions/setup-node@v7 with: node-version: 22 @@ -83,25 +162,6 @@ jobs: corepack enable corepack prepare pnpm@10.6.5 --activate pnpm --version - - name: Resolve package version - id: version - env: - GH_TOKEN: ${{ github.token }} - REF: ${{ github.ref }} - REF_TYPE: ${{ github.ref_type }} - run: | - if ($env:REF_TYPE -eq 'tag') { - node tools/build-version.mjs --tag $env:REF - } else { - $base = (Get-Content -LiteralPath package.json -Raw | ConvertFrom-Json).version - $existing = Join-Path $env:RUNNER_TEMP 'dev-tags.txt' - # Write the file even when no daily tag exists yet; an empty pipeline would not create it. - $tags = @(gh api "repos/$env:GITHUB_REPOSITORY/git/matching-refs/tags/v$base-dev." --paginate --jq '.[].ref') - if ($LASTEXITCODE -ne 0) { throw 'Could not list existing daily tags.' } - [System.IO.File]::WriteAllLines($existing, [string[]]$tags) - node tools/build-version.mjs --dev --existing-file $existing - } - if ($LASTEXITCODE -ne 0) { throw 'Version resolution failed.' } - name: Install dependencies run: pnpm install --frozen-lockfile - name: Prepare Electron runtime @@ -165,7 +225,7 @@ jobs: - name: Package community installer env: OPENTEST_ENV_FILE: .runtime/ci-installer/runtime.env - VERSION: ${{ steps.version.outputs.version }} + VERSION: ${{ needs.version.outputs.version }} # CI has no Crowdin CLI or credentials; use the translations committed in the repository. MAVEN_ARGS: -ntp -Dskip.crowdin.download=true run: | @@ -191,12 +251,115 @@ jobs: dist/releases/windows-x64/test/unsigned/installer-verification.json if-no-files-found: error retention-days: 14 + build-posix: + name: build-community-${{ matrix.platform }} + needs: version + strategy: + fail-fast: false + matrix: + include: + - platform: linux + runner: ubuntu-24.04 + arch: x64 + extension: deb + - platform: mac + runner: macos-26 + arch: arm64 + extension: dmg + runs-on: ${{ matrix.runner }} + timeout-minutes: 120 + defaults: + run: + shell: bash + env: + COREPACK_ENABLE_DOWNLOAD_PROMPT: '0' + NODE_OPTIONS: --max-old-space-size=6144 + PLUGIN_PACKAGES: ${{ github.workspace }}/.runtime/ci-plugin-packages + NATIVE_PLUGIN_BIN: ${{ github.workspace }}/.runtime/ci-native-plugins + PACKAGE_PLATFORM: ${{ matrix.platform }} + VERSION: ${{ needs.version.outputs.version }} + OPENTEST_ENV_FILE: .runtime/ci-installer/runtime.env + MAVEN_ARGS: -ntp -Dskip.crowdin.download=true + steps: + - uses: actions/checkout@v7 + with: + persist-credentials: false + - name: Check out public plugins + uses: actions/checkout@v7 + with: + repository: crysound/OpenTest-Plugins + ref: ${{ needs.version.outputs.plugins-ref }} + path: .runtime/opentest-plugins + persist-credentials: false + - name: Verify public plugin revision + env: + EXPECTED_PLUGINS_SHA: ${{ needs.version.outputs.plugins-sha }} + run: | + actual=$(git -C .runtime/opentest-plugins rev-parse HEAD) + test "$actual" = "$EXPECTED_PLUGINS_SHA" + - uses: actions/setup-node@v7 + with: + node-version: 22 + package-manager-cache: false + - uses: actions/setup-java@v6 + with: + distribution: zulu + java-version: '21' + cache: maven + - uses: actions/setup-python@v7 + with: + python-version: '3.12' + - name: Prepare Linux dependencies + if: matrix.platform == 'linux' + run: | + sudo apt-get update + sudo apt-get install -y build-essential patchelf libasound2t64 libgtk-3-0t64 libnotify4 libnss3 libxss1 libxtst6 libatspi2.0-0t64 libpulse0 libudev1 libblkid1 libssl3t64 libhidapi-hidraw0 xdg-utils + - name: Prepare pnpm and dependencies + run: | + corepack enable + corepack prepare pnpm@10.6.5 --activate + pnpm install --frozen-lockfile + node tools/ci/prepare-electron.mjs + - name: Install the host plugin SDK into Maven + run: mvn -B --no-transfer-progress -DskipTests -f apps/backend/pom.xml -pl ':crydaq-dependencies,:opentest-plugin-api,:opentest-dashboard-standard-processors' -am install + - name: Build public plugins + run: | + names=$(node --input-type=module -e "import { editionPluginNames } from './tools/default-plugins.mjs'; console.log(editionPluginNames({ edition: 'community' }).join('\n'))") + test -n "$names" + plugins=() + while IFS= read -r name; do plugins+=("$name"); done <<< "$names" + mv .runtime/opentest-plugins "$RUNNER_TEMP/opentest-plugins" + export OPENTEST_PLUGIN_PACKAGE_OUTPUT="$PLUGIN_PACKAGES" + cd "$RUNNER_TEMP/opentest-plugins" + node tools/build.mjs "${plugins[@]}" --platform "$PACKAGE_PLATFORM" --skip-tests -Dskip.crowdin.download=true + - name: Build and stage SonoDAQ device plugin + run: node tools/ci/stage-posix-device-plugin.mjs + - name: Prepare installer settings + env: + OPENTEST_CI_NATIVE_PLUGIN_BIN_ROOT: ${{ env.NATIVE_PLUGIN_BIN }} + run: node tools/ci/prepare-installer.mjs + - name: Package community installer + run: | + node tools/package.mjs --platform "$PACKAGE_PLATFORM" --mode production --kind installer --edition community \ + --version "$VERSION" --plugins-dir "$PLUGIN_PACKAGES" --config .runtime/ci-installer/packaging.json + - name: Verify silent install + run: node tools/ci/verify-posix-installer.mjs + - name: Upload installer + uses: actions/upload-artifact@v7 + with: + name: opentest-community-${{ matrix.platform }}-${{ matrix.arch }}-${{ github.sha }} + path: | + dist/releases/${{ matrix.platform }}-${{ matrix.arch }}/production/unsigned/installer/*.${{ matrix.extension }} + dist/releases/${{ matrix.platform }}-${{ matrix.arch }}/production/unsigned/delivery.json + dist/releases/${{ matrix.platform }}-${{ matrix.arch }}/production/unsigned/installer-verification.json + if-no-files-found: error + retention-days: 14 publish: name: publish-community-release - needs: build + needs: [version, build, build-posix] if: github.event_name == 'push' runs-on: ubuntu-latest - timeout-minutes: 15 + timeout-minutes: 30 permissions: contents: write actions: read @@ -209,11 +372,21 @@ jobs: - uses: actions/download-artifact@v8 with: name: opentest-community-windows-x64-${{ github.sha }} - path: release + path: release/windows + - uses: actions/download-artifact@v8 + with: + name: opentest-community-linux-x64-${{ github.sha }} + path: release/linux + - uses: actions/download-artifact@v8 + with: + name: opentest-community-mac-arm64-${{ github.sha }} + path: release/mac - name: Publish GitHub release uses: actions/github-script@v9 env: - VERSION: ${{ needs.build.outputs.version }} + VERSION: ${{ needs.version.outputs.version }} + PLUGINS_REF: ${{ needs.version.outputs.plugins-ref }} + PLUGINS_SHA: ${{ needs.version.outputs.plugins-sha }} ARTIFACT_ID: ${{ needs.build.outputs.artifact-id }} ARTIFACT_DIGEST: ${{ needs.build.outputs.artifact-digest }} INSTALLER_NAME: ${{ needs.build.outputs.installer-name }} @@ -227,7 +400,10 @@ jobs: version: process.env.VERSION, artifactId: process.env.ARTIFACT_ID, artifactDigest: process.env.ARTIFACT_DIGEST, - installerPath: path.join(process.env.GITHUB_WORKSPACE, 'release/installer', process.env.INSTALLER_NAME), + installerPath: path.join(process.env.GITHUB_WORKSPACE, 'release/windows/installer', process.env.INSTALLER_NAME), installerDigest: process.env.INSTALLER_SHA256, + posixRoot: path.join(process.env.GITHUB_WORKSPACE, 'release'), + pluginsRef: process.env.PLUGINS_REF, + pluginsSha: process.env.PLUGINS_SHA, }) core.notice(`Published ${release.html_url}`) diff --git a/tools/__tests__/community-package.test.mjs b/tools/__tests__/community-package.test.mjs new file mode 100644 index 00000000..d320b90f --- /dev/null +++ b/tools/__tests__/community-package.test.mjs @@ -0,0 +1,95 @@ +import assert from 'node:assert/strict'; +import { createRequire } from 'node:module'; +import { execFileSync } from 'node:child_process'; +import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; +import test from 'node:test'; +import { assertBinary, assertSameTree } from '../ci/verify-posix-installer.mjs'; +import { loadPackagingConfig } from '../packaging.mjs'; +import { repositoryRoot } from '../runtime.mjs'; + +// 使用现有打包依赖的 YAML 解析器,不为工作流检查另加产品依赖。 +const desktopRequire = createRequire(path.join(repositoryRoot, 'apps/desktop/package.json')); +const builderRequire = createRequire(desktopRequire.resolve('electron-builder/package.json')); +const yaml = createRequire(builderRequire.resolve('app-builder-lib/package.json'))('js-yaml'); + +test('工作流为三平台共用版本,只有推送且全部构建成功才进入单一发布任务', () => { + const workflow = yaml.load(readFileSync(path.join(repositoryRoot, '.github/workflows/community-package.yml'), 'utf8')); + assert.deepEqual(workflow.on.push.branches, ['main']); + assert.ok(workflow.on.push.tags.includes('!v*-dev.*')); + assert.ok(workflow.on.pull_request); + assert.ok(workflow.on.workflow_dispatch); + assert.equal(workflow.jobs.build.needs, 'version'); + assert.equal(workflow.jobs.version.outputs['plugins-ref'], '${{ steps.plugins.outputs.ref }}'); + assert.equal(workflow.jobs.version.outputs['plugins-sha'], '${{ steps.plugins.outputs.sha }}'); + assert.equal(workflow.jobs['build-posix'].needs, 'version'); + assert.deepEqual(workflow.jobs.publish.needs, ['version', 'build', 'build-posix']); + assert.equal(workflow.jobs.publish.if, "github.event_name == 'push'"); + assert.equal(workflow.jobs.publish['timeout-minutes'], 30); + assert.equal(workflow.concurrency.group, 'community-package-${{ github.ref }}'); + assert.equal(workflow.concurrency['cancel-in-progress'], "${{ github.event_name == 'pull_request' }}"); + assert.equal(workflow.jobs['build-posix'].strategy['fail-fast'], false); + assert.deepEqual(workflow.jobs['build-posix'].strategy.matrix.include.map(m => [m.platform, m.runner, m.arch]), + [['linux', 'ubuntu-24.04', 'x64'], ['mac', 'macos-26', 'arm64']]); + const writers = Object.entries(workflow.jobs).filter(([, job]) => job.permissions?.contents === 'write'); + assert.deepEqual(writers.map(([name]) => name), ['publish']); + assert.equal(JSON.stringify(workflow).includes('secrets.'), false); + const windows = workflow.jobs.build.steps; + assert.ok(windows.some(s => s.run?.includes('verify-installer.ps1'))); + assert.ok(windows.some(s => s.run?.includes('--platform windows --mode test'))); + assert.ok(windows.some(s => s.name === 'Verify public plugin revision')); + assert.ok(workflow.jobs['build-posix'].steps.some(s => s.name === 'Verify public plugin revision')); + const posix = workflow.jobs['build-posix'].steps; + const verify = posix.findIndex(s => s.run?.includes('verify-posix-installer.mjs')); + const upload = posix.findIndex(s => s.uses?.startsWith('actions/upload-artifact@')); + assert.ok(verify > 0 && upload > verify); +}); + +test('安装配置在生产模式也使用自动构建生成的公开配置', () => { + const temporary = mkdtempSync(path.join(os.tmpdir(), 'opentest-ci-installer-')); + execFileSync(process.execPath, ['tools/ci/prepare-installer.mjs'], { + cwd: repositoryRoot, env: { ...process.env, OPENTEST_CI_NATIVE_PLUGIN_BIN_ROOT: '', OPENTEST_CI_INSTALLER_DIRECTORY: temporary }, + }); + for (const platform of ['windows', 'linux', 'mac']) { + const config = loadPackagingConfig(platform === 'windows' ? 'test' : 'production', + path.join(temporary, 'packaging.json'), platform); + assert.equal(config.backendConfig, path.join(temporary, 'application.properties')); + assert.equal(config.desktopConfig, path.join(temporary, 'local-settings.json')); + assert.equal(JSON.parse(readFileSync(config.desktopConfig, 'utf8')).updates.enabled, false); + } + rmSync(temporary, { recursive: true, force: true }); +}); + +test('安装文件检查拒绝缺失、额外或内容被修改的文件', t => { + const root = mkdtempSync(path.join(os.tmpdir(), 'opentest-tree-')); + t.after(() => rmSync(root, { recursive: true, force: true })); + const source = path.join(root, 'source'), installed = path.join(root, 'installed'); + mkdirSync(source); mkdirSync(installed); + writeFileSync(path.join(source, 'runtime'), 'expected'); + writeFileSync(path.join(installed, 'runtime'), 'expected'); + assert.equal(assertSameTree(source, installed), 1); + writeFileSync(path.join(installed, 'runtime'), 'changed'); + assert.throws(() => assertSameTree(source, installed)); + writeFileSync(path.join(installed, 'runtime'), 'expected'); + writeFileSync(path.join(installed, 'unexpected'), 'extra'); + assert.throws(() => assertSameTree(source, installed)); + rmSync(path.join(installed, 'unexpected')); rmSync(path.join(installed, 'runtime')); + assert.throws(() => assertSameTree(source, installed)); +}); + +test('安装程序架构检查区分 Linux x64 与 macOS ARM64,拒绝错误架构', t => { + const root = mkdtempSync(path.join(os.tmpdir(), 'opentest-binary-')); + t.after(() => rmSync(root, { recursive: true, force: true })); + const file = path.join(root, 'binary'); + const linux = Buffer.alloc(64); + linux.write('\x7fELF'); linux[4] = 2; linux[5] = 1; linux.writeUInt16LE(62, 18); + writeFileSync(file, linux); assertBinary(file, 'linux'); + linux.writeUInt16LE(183, 18); writeFileSync(file, linux); + assert.throws(() => assertBinary(file, 'linux')); + const mac = Buffer.alloc(64); + mac.writeUInt32LE(0xfeedfacf); mac.writeUInt32LE(0x0100000c, 4); + writeFileSync(file, mac); assertBinary(file, 'mac'); + mac.writeUInt32LE(0x01000007, 4); writeFileSync(file, mac); + assert.throws(() => assertBinary(file, 'mac')); +}); diff --git a/tools/__tests__/publish-community-build.test.mjs b/tools/__tests__/publish-community-build.test.mjs index 648bc3c6..d822397b 100644 --- a/tools/__tests__/publish-community-build.test.mjs +++ b/tools/__tests__/publish-community-build.test.mjs @@ -1,6 +1,6 @@ import assert from 'node:assert/strict'; import { createHash } from 'node:crypto'; -import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'; +import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import test, { after } from 'node:test'; @@ -36,7 +36,8 @@ function fixture(version = '2.5.0-dev.20261114.2', ref = 'refs/heads/main') { return { artifact, calls, installer, options: { github, context, version, artifactId: '456', artifactDigest, installerPath, - installerDigest: createHash('sha256').update(installer).digest('hex') }, + installerDigest: createHash('sha256').update(installer).digest('hex'), + pluginsRef: 'main', pluginsSha: 'b'.repeat(40) }, }; } @@ -141,3 +142,117 @@ test('rejects invalid inputs without creating a release', async () => { assert.equal(calls.length, 0); } }); + +function multiplatformFixture(version, ref) { + const f = fixture(version, ref); + const { options } = f; + options.posixRoot = mkdtempSync(path.join(temporary, 'posix-')); + f.reports = []; + for (const [platform, arch, extension] of [['linux', 'x64', '.deb'], ['mac', 'arm64', '.dmg']]) { + const directory = path.join(options.posixRoot, platform); + mkdirSync(path.join(directory, 'installer'), { recursive: true }); + const installer = Buffer.alloc(1024); + if (platform === 'linux') installer.write('!\n'); + else installer.write('koly', installer.length - 512); + const name = `OpenTest-Community-${options.version}-production-installer-${platform}-${arch}${extension}`; + const digest = createHash('sha256').update(installer).digest('hex'); + writeFileSync(path.join(directory, 'installer', name), installer); + const reportPath = path.join(directory, 'installer-verification.json'); + writeFileSync(reportPath, JSON.stringify({ status: 'pass', installationVerification: 'pass', cleanup: 'pass', + javaRuntime: 'pass', automaticUpdates: 'disabled', mode: 'production', version: options.version, + platform, architecture: arch, installer: name, sha256: digest })); + f.reports.push(reportPath); + writeFileSync(path.join(directory, 'delivery.json'), JSON.stringify({ version: options.version, + platform, arch, edition: 'community', mode: 'production', signed: false, + artifacts: [{ file: `installer/${name}`, sha256: digest }] })); + } + options.github.rest.actions.downloadArtifact = async () => { throw new Error('POSIX artifacts must use the files already downloaded by the workflow'); }; + return f; +} + +test('three verified platforms create one release and publish only after all six uploads', async () => { + const { options, calls } = multiplatformFixture(); + await publish(options); + assert.equal(calls.filter(c => c.name === 'createRelease').length, 1); + const uploads = calls.filter(c => c.name === 'uploadReleaseAsset'); + assert.equal(uploads.length, 6); + assert.equal(new Set(uploads.map(c => c.args.name)).size, 6); + assert.match(uploads[2].args.name, /linux-x64-setup\.deb$/); + assert.match(uploads[4].args.name, /macos-arm64-setup\.dmg$/); + assert.equal(calls.at(-1).name, 'updateRelease'); + assert.equal(calls.at(-1).args.prerelease, true); + assert.match(calls[0].args.body, /Source commit:/); + assert.match(calls[0].args.body, /Successful build:/); + assert.match(calls[0].args.body, /OpenTest-Plugins commit: b{40}/); + assert.match(calls[0].args.body, /Includes OpenTest/); +}); + +test('all-platform release and RC retain channel semantics', async () => { + for (const version of ['2.5.0', '2.5.0-rc.1']) { + const f = multiplatformFixture(version, `refs/tags/v${version}`); + await publish(f.options); + assert.equal(f.calls.at(-1).args.make_latest, version === '2.5.0' ? 'true' : 'false'); + } +}); + +test('missing or invalid downloaded POSIX files block release creation', async () => { + for (const damage of ['missing', 'report', 'delivery', 'digest', 'format']) { + const f = multiplatformFixture(); + if (damage === 'missing') rmSync(path.join(f.options.posixRoot, 'mac'), { recursive: true, force: true }); + if (damage === 'report') rmSync(f.reports[1]); + if (damage === 'delivery') rmSync(path.join(f.options.posixRoot, 'mac/delivery.json')); + if (damage === 'digest') { + const report = JSON.parse(readFileSync(f.reports[1], 'utf8')); + report.sha256 = '0'.repeat(64); + writeFileSync(f.reports[1], JSON.stringify(report)); + } + if (damage === 'format') { + const report = JSON.parse(readFileSync(f.reports[1], 'utf8')); + const installer = path.join(f.options.posixRoot, 'mac/installer', report.installer); + writeFileSync(installer, Buffer.alloc(1024)); + report.sha256 = createHash('sha256').update(readFileSync(installer)).digest('hex'); + writeFileSync(f.reports[1], JSON.stringify(report)); + const deliveryPath = path.join(f.options.posixRoot, 'mac/delivery.json'); + const delivery = JSON.parse(readFileSync(deliveryPath, 'utf8')); + delivery.artifacts[0].sha256 = report.sha256; + writeFileSync(deliveryPath, JSON.stringify(delivery)); + } + await assert.rejects(publish(f.options)); + assert.equal(f.calls.length, 0); + } +}); + +test('failed installation, wrong version and changed installer block all publication', async () => { + for (const damage of ['install', 'version', 'bytes', 'format']) { + const f = multiplatformFixture(); + const report = JSON.parse(readFileSync(f.reports[1], 'utf8')); + if (damage === 'install') report.installationVerification = 'failed'; + if (damage === 'version') report.version = '2.5.0'; + if (damage === 'bytes' || damage === 'format') { + const installer = path.join(f.options.posixRoot, 'mac/installer', report.installer); + writeFileSync(installer, Buffer.alloc(1024)); + if (damage === 'format') { + report.sha256 = createHash('sha256').update(readFileSync(installer)).digest('hex'); + const deliveryPath = path.join(f.options.posixRoot, 'mac/delivery.json'); + const delivery = JSON.parse(readFileSync(deliveryPath, 'utf8')); + delivery.artifacts[0].sha256 = report.sha256; + writeFileSync(deliveryPath, JSON.stringify(delivery)); + } + } + writeFileSync(f.reports[1], JSON.stringify(report)); + await assert.rejects(publish(f.options)); + assert.equal(f.calls.length, 0); + } +}); + +test('a late platform upload failure leaves the release as a draft', async () => { + const f = multiplatformFixture(); + const upload = f.options.github.rest.repos.uploadReleaseAsset; + f.options.github.rest.repos.uploadReleaseAsset = async args => { + if (args.name.endsWith('.dmg')) throw new Error('mac upload failed'); + return upload(args); + }; + await assert.rejects(publish(f.options), /mac upload failed/); + assert.equal(f.calls.filter(c => c.name === 'createRelease').length, 1); + assert.equal(f.calls.some(c => c.name === 'updateRelease'), false); +}); diff --git a/tools/ci/prepare-electron.mjs b/tools/ci/prepare-electron.mjs new file mode 100644 index 00000000..2ddbae87 --- /dev/null +++ b/tools/ci/prepare-electron.mjs @@ -0,0 +1,28 @@ +import { createHash } from 'node:crypto'; +import { execFileSync } from 'node:child_process'; +import { createRequire } from 'node:module'; +import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'; +import path from 'node:path'; +import { repositoryRoot } from '../runtime.mjs'; +import { currentPackagingPlatform, resolvePackagingPlatform, assertPackagingPlatformReady } from '../packaging-platforms.mjs'; + +const target = resolvePackagingPlatform(currentPackagingPlatform()); +assertPackagingPlatformReady(target); +if (target.platform === 'windows') throw new Error('Windows 使用 prepare-electron.ps1'); +const require = createRequire(path.join(repositoryRoot, 'apps/desktop/package.json')); +const root = path.dirname(require.resolve('electron/package.json')); +const version = JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf8')).version; +if (!/^\d+\.\d+\.\d+$/.test(version)) throw new Error('Electron 版本无效'); +const archiveName = `electron-v${version}-${target.nodePlatform}-${target.arch}.zip`; +const expected = JSON.parse(readFileSync(path.join(root, 'checksums.json'), 'utf8'))[archiveName]; +if (!/^[0-9a-f]{64}$/.test(expected)) throw new Error('锁定依赖中缺少当前平台的 Electron 校验值'); +const archive = path.join(process.env.RUNNER_TEMP, archiveName); +execFileSync('curl', ['--fail', '--location', '--retry', '3', '--output', archive, + `https://github.com/electron/electron/releases/download/v${version}/${archiveName}`], { stdio: 'inherit' }); +if (createHash('sha256').update(readFileSync(archive)).digest('hex') !== expected) throw new Error('Electron 下载校验失败'); +const dist = path.join(root, 'dist'); +mkdirSync(dist, { recursive: true }); +execFileSync('unzip', ['-q', '-o', archive, '-d', dist], { stdio: 'inherit' }); +if (readFileSync(path.join(dist, 'version'), 'utf8').trim().replace(/^v/, '') !== version) throw new Error('Electron 版本不匹配'); +writeFileSync(path.join(root, 'path.txt'), target.platform === 'mac' ? 'Electron.app/Contents/MacOS/Electron' : 'electron'); +console.info(`Electron ${version} ${target.nodePlatform}/${target.arch} 校验通过`); diff --git a/tools/ci/prepare-installer.mjs b/tools/ci/prepare-installer.mjs index b46ef04e..b0e43d06 100644 --- a/tools/ci/prepare-installer.mjs +++ b/tools/ci/prepare-installer.mjs @@ -3,7 +3,9 @@ import path from 'node:path'; import { fileURLToPath } from 'node:url'; const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..'); -const directory = path.join(root, '.runtime/ci-installer'); +const directory = process.env.OPENTEST_CI_INSTALLER_DIRECTORY + ? path.resolve(process.env.OPENTEST_CI_INSTALLER_DIRECTORY) + : path.join(root, '.runtime/ci-installer'); mkdirSync(directory, { recursive: true }); // Use the repository's distributable example, never a developer's local settings. @@ -23,6 +25,8 @@ writeFileSync(path.join(directory, 'packaging.json'), `${JSON.stringify({ schemaVersion: 1, backendConfig, desktopConfig, + // Mode overrides in the base config must not reintroduce local production settings. + modes: { production: { backendConfig, desktopConfig } }, ...(nativePluginBinRoot ? { nativePluginBinRoot } : {}), }, null, 2)}\n`); console.info('Prepared daily test installer settings; automatic updates are disabled.'); diff --git a/tools/ci/stage-posix-device-plugin.mjs b/tools/ci/stage-posix-device-plugin.mjs new file mode 100644 index 00000000..4e6356c2 --- /dev/null +++ b/tools/ci/stage-posix-device-plugin.mjs @@ -0,0 +1,39 @@ +import { execFileSync } from 'node:child_process'; +import { cpSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs'; +import path from 'node:path'; +import { repositoryRoot } from '../runtime.mjs'; +import { resolvePackagingPlatform, assertPackagingPlatformReady } from '../packaging-platforms.mjs'; + +const target = resolvePackagingPlatform(process.env.PACKAGE_PLATFORM); +assertPackagingPlatformReady(target); +if (!['mac', 'linux'].includes(target.platform)) throw new Error('此入口只构建 Linux/macOS 设备插件'); +const temp = process.env.RUNNER_TEMP; +const source = path.join(temp, 'opentest-plugins/plugins/opentest_sonodaq_plugin'); +const framework = path.join(repositoryRoot, 'apps/native'); +const build = path.join(temp, 'sonodaq-build'); +const mac = target.platform === 'mac'; +const sdk = path.join(source, mac ? 'macos/sonodaq-sdk-1.4.0-macos-arm64-cpp' : 'linux/sonodaq-sdk-1.4.0-linux-x64-cpp'); +const run = (command, args) => execFileSync(command, args, { stdio: 'inherit' }); +run('cmake', ['-S', source, '-B', build, '-DCMAKE_BUILD_TYPE=Release', '-DSONODAQ_BUILD_TESTS=OFF', + `-DOPENTEST_FRAMEWORK_ROOT=${framework}`, `-DSONODAQ_SDK_ROOT=${sdk}`, + ...(mac ? ['-DCMAKE_OSX_ARCHITECTURES=arm64', '-DCMAKE_OSX_DEPLOYMENT_TARGET=26.0'] : [])]); +run('cmake', ['--build', build, '--target', 'OpenTestSonoDaqDevicePlugin', '--parallel', '4']); +const install = path.join(temp, 'sonodaq-install'); +run('cmake', ['--install', build, '--prefix', install]); +const entry = `libOpenTestSonoDaqDevicePlugin.${mac ? 'dylib' : 'so'}`; +const stage = path.join(temp, 'sonodaq-stage/OpenTestSonoDaqDevicePlugin'); +run('python', [path.join(source, `package/publish-${mac ? 'macos' : 'linux'}.py`), + '--library', path.join(install, 'lib', entry), '--sdk', sdk, '--stage', stage, + '--output', path.join(temp, 'sonodaq-package'), '--framework', framework]); +const manifest = JSON.parse(readFileSync(path.join(stage, 'plugin-package.json'), 'utf8')); +if (manifest.packageId !== 'opentest.sonodaq.device' || manifest.entry !== entry) throw new Error('设备插件清单身份不匹配'); +const files = readdirSync(stage, { recursive: true, withFileTypes: true }).filter(e => e.isFile()) + .map(e => path.relative(stage, path.join(e.parentPath, e.name)).replaceAll('\\', '/')).sort(); +if (JSON.stringify(files) !== JSON.stringify([...manifest.files, 'plugin-package.json'].sort())) throw new Error('设备插件文件清单不匹配'); +const devices = path.join(process.env.NATIVE_PLUGIN_BIN, target.nativePlatform, 'plugins/devices'); +mkdirSync(devices, { recursive: true }); +cpSync(stage, path.join(devices, manifest.packageId), { recursive: true }); +writeFileSync(path.join(devices, 'plugins.json'), JSON.stringify({ schemaVersion: 1, plugins: [{ + packageId: manifest.packageId, pluginKind: manifest.pluginKind, + entry: `${manifest.packageId}/${entry}`, enabled: true, bundled: true, +}] }, null, 2) + '\n'); diff --git a/tools/ci/verify-posix-installer.mjs b/tools/ci/verify-posix-installer.mjs new file mode 100644 index 00000000..a0e9690c --- /dev/null +++ b/tools/ci/verify-posix-installer.mjs @@ -0,0 +1,145 @@ +import assert from 'node:assert/strict'; +import { createHash } from 'node:crypto'; +import { execFileSync } from 'node:child_process'; +import { accessSync, constants, existsSync, mkdtempSync, readFileSync, readdirSync, writeFileSync } from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; +import { pathToFileURL } from 'node:url'; +import { repositoryRoot } from '../runtime.mjs'; +import { resolvePackagingPlatform, assertPackagingPlatformReady } from '../packaging-platforms.mjs'; + +const sha256 = file => createHash('sha256').update(readFileSync(file)).digest('hex'); +const run = (command, args) => execFileSync(command, args, { encoding: 'utf8', timeout: 300_000, stdio: ['ignore', 'pipe', 'pipe'] }).trim(); +const files = root => readdirSync(root, { recursive: true, withFileTypes: true }).filter(e => e.isFile()) + .map(e => path.relative(root, path.join(e.parentPath, e.name))).sort(); + +export function assertSameTree(source, installed) { + const expected = files(source); + assert.ok(expected.length, `暂存目录为空:${source}`); + assert.deepEqual(files(installed), expected, `安装文件集合不匹配:${installed}`); + for (const file of expected) assert.equal(sha256(path.join(installed, file)), sha256(path.join(source, file)), `安装文件不匹配:${file}`); + return expected.length; +} + +export function assertBinary(file, platform) { + const bytes = readFileSync(file); + assert.ok(bytes.length >= 32, `二进制文件过短:${file}`); + if (platform === 'linux') { + assert.equal(bytes.subarray(0, 4).toString('hex'), '7f454c46'); + assert.equal(bytes[4], 2); // ELF64 + assert.equal(bytes[5], 1); // little-endian + assert.equal(bytes.readUInt16LE(18), 62); // x86-64 + } else { + // 本次只交付 ARM64,不接受其他架构或含混的通用二进制。 + assert.equal(bytes.readUInt32LE(0), 0xfeedfacf); + assert.equal(bytes.readUInt32LE(4), 0x0100000c); + } +} + +export function verifyInstaller({ platform = process.env.PACKAGE_PLATFORM, root = repositoryRoot } = {}) { + const target = resolvePackagingPlatform(platform); + assertPackagingPlatformReady(target); + assert.ok(['mac', 'linux'].includes(platform)); + const output = path.join(root, `dist/releases/${platform}-${target.arch}/production/unsigned`); + const delivery = JSON.parse(readFileSync(path.join(output, 'delivery.json'), 'utf8')); + assert.equal(delivery.platform, platform); + assert.equal(delivery.arch, target.arch); + assert.equal(delivery.mode, 'production'); + assert.equal(delivery.edition, 'community'); + assert.equal(delivery.signed, false); + assert.equal(delivery.artifacts.length, 1); + const artifact = delivery.artifacts[0]; + const name = `OpenTest-Community-${delivery.version}-production-installer-${platform}-${target.arch}${target.installerExtension}`; + assert.equal(artifact.file, `installer/${name}`); + const installer = path.join(output, artifact.file); + assert.equal(sha256(installer), artifact.sha256); + const stages = readdirSync(path.join(root, '.runtime/packaging')).filter(n => n.startsWith('production-')); + assert.equal(stages.length, 1, '安装验证要求唯一的本次暂存目录'); + const stage = path.join(root, '.runtime/packaging', stages[0]); + const temp = mkdtempSync(path.join(os.tmpdir(), 'opentest-install-')); + const mount = path.join(temp, 'volume'); + let mounted = false, installedPackage, installedExecutable; + let report, primaryError, cleanupError; + try { + let installation; + if (platform === 'linux') { + installedPackage = run('dpkg-deb', ['--field', installer, 'Package']); + assert.match(installedPackage, /^[a-z0-9][a-z0-9+.-]+$/); + assert.equal(run('dpkg-deb', ['--field', installer, 'Architecture']), 'amd64'); + run('sudo', ['env', 'DEBIAN_FRONTEND=noninteractive', 'apt-get', 'install', '-y', installer]); + assert.equal(run('dpkg-query', ['-W', '-f=${Status}', installedPackage]), 'install ok installed'); + const executable = run('dpkg-query', ['-L', installedPackage]).split('\n').find(f => /^\/opt\/[^/]+\/opentest$/.test(f)); + assert.ok(executable, '安装包未注册桌面程序'); + installedExecutable = executable; + installation = path.dirname(executable); + assertBinary(executable, platform); + } else { + run('hdiutil', ['attach', '-readonly', '-nobrowse', '-mountpoint', mount, installer]); + mounted = true; + const app = path.join(temp, 'OpenTest.app'); + run('ditto', [path.join(mount, 'OpenTest.app'), app]); + run('codesign', ['--verify', '--deep', '--strict', app]); + installation = path.join(app, 'Contents'); + assertBinary(path.join(installation, 'MacOS/OpenTest'), platform); + } + const resources = path.join(installation, platform === 'mac' ? 'Resources' : 'resources'); + assert.ok(readFileSync(path.join(resources, 'app.asar')).length); + const counts = {}; + // macOS 签名会调整部分二进制;与最终应用目录比较,而非签名前暂存目录。 + const finalResources = platform === 'mac' + ? path.join(output, 'installer/mac-arm64/OpenTest.app/Contents/Resources') : path.join(stage, 'resources'); + for (const directory of ['java', 'backend', 'frontend', 'config', 'bundled-plugins']) { + counts[directory] = assertSameTree(path.join(finalResources, directory), path.join(resources, directory)); + } + const java = path.join(resources, 'java/bin/java'); + assertBinary(java, platform); + accessSync(java, constants.X_OK); + run(java, ['-version']); + const native = path.join(resources, 'app.asar.unpacked/packages/native-modules/dist'); + for (const module of ['mem-ring-reader/mem_ring_reader.node', 'unit-conversion/unit_conversion.node', 'algorithm-bridge/algorithm_bridge.node']) { + assertBinary(path.join(native, module), platform); + } + const nativeSource = platform === 'mac' + ? path.join(finalResources, 'app.asar.unpacked/packages/native-modules/dist') + // 打包器会剔除类型声明等开发文件,安装结果应与最终封装目录一致。 + : path.join(output, 'installer/linux-unpacked/resources/app.asar.unpacked/packages/native-modules/dist'); + counts.nativeModules = assertSameTree(nativeSource, native); + accessSync(path.join(resources, 'backend/native/OptDevHost'), constants.X_OK); + assertBinary(path.join(resources, 'backend/native/OptDevHost'), platform); + const devices = path.join(resources, 'backend/native/plugins/devices'); + const registry = JSON.parse(readFileSync(path.join(devices, 'plugins.json'), 'utf8')); + const sono = registry.plugins.find(p => p.packageId === 'opentest.sonodaq.device'); + assert.equal(sono?.bundled, true); + assert.equal(sono?.enabled, true); + const entry = `opentest.sonodaq.device/libOpenTestSonoDaqDevicePlugin.${platform === 'mac' ? 'dylib' : 'so'}`; + assert.equal(sono.entry, entry); + assertBinary(path.join(devices, entry), platform); + assert.equal(JSON.parse(readFileSync(path.join(resources, 'config/local-settings.json'), 'utf8')).updates.enabled, false); + report = { status: 'pass', platform, architecture: target.arch, mode: 'production', version: delivery.version, + installer: name, sha256: artifact.sha256, installationVerification: 'pass', javaRuntime: 'pass', + filesVerified: counts, automaticUpdates: 'disabled', verifiedAt: new Date().toISOString() }; + } catch (error) { + primaryError = error; + } finally { + try { + if (mounted) run('hdiutil', ['detach', mount]); + if (installedPackage) { + run('sudo', ['env', 'DEBIAN_FRONTEND=noninteractive', 'apt-get', 'remove', '-y', installedPackage]); + if (installedExecutable) assert.ok(!existsSync(installedExecutable), '卸载后仍存在桌面程序'); + } + } catch (error) { + cleanupError = error; + } + } + if (primaryError) { + if (cleanupError) console.error(`清理失败(保留原始错误):${cleanupError.message}`); + throw primaryError; + } + if (cleanupError) throw cleanupError; + report.cleanup = 'pass'; + writeFileSync(path.join(output, 'installer-verification.json'), JSON.stringify(report, null, 2) + '\n'); + console.info(`安装验证通过:${name}`); + return report; +} + +if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) verifyInstaller(); diff --git a/tools/publish-community-build.cjs b/tools/publish-community-build.cjs index 29517b5f..d01e2c70 100644 --- a/tools/publish-community-build.cjs +++ b/tools/publish-community-build.cjs @@ -11,6 +11,34 @@ function channelOf(version) { return !match[4] ? 'release' : match[4].startsWith('rc.') ? 'rc' : 'dev'; } +function posixInstallers({ version, root }) { + const result = []; + for (const [platform, arch, extension] of [['linux', 'x64', '.deb'], ['mac', 'arm64', '.dmg']]) { + const directory = path.join(root, platform); + if (!path.isAbsolute(directory)) throw new Error(`Invalid downloaded artifact directory: ${directory}`); + const report = JSON.parse(readFileSync(path.join(directory, 'installer-verification.json'), 'utf8')); + const delivery = JSON.parse(readFileSync(path.join(directory, 'delivery.json'), 'utf8')); + const expectedName = `OpenTest-Community-${version}-production-installer-${platform}-${arch}${extension}`; + if (report.status !== 'pass' || report.installationVerification !== 'pass' || report.cleanup !== 'pass' || + report.javaRuntime !== 'pass' || report.automaticUpdates !== 'disabled' || report.mode !== 'production' || + report.version !== version || report.platform !== platform || report.architecture !== arch || + report.installer !== expectedName || !/^[0-9a-f]{64}$/.test(report.sha256) || + delivery.version !== version || delivery.platform !== platform || delivery.arch !== arch || + delivery.edition !== 'community' || delivery.mode !== 'production' || delivery.signed !== false || + delivery.artifacts?.length !== 1 || delivery.artifacts[0].file !== `installer/${expectedName}` || + delivery.artifacts[0].sha256 !== report.sha256) throw new Error('Invalid POSIX installation verification'); + const data = readFileSync(path.join(directory, 'installer', expectedName)); + const digest = createHash('sha256').update(data).digest('hex'); + if (digest !== report.sha256 || (platform === 'linux' + ? data.toString('ascii', 0, 8) !== '!\n' + : data.length < 512 || data.toString('ascii', data.length - 512, data.length - 508) !== 'koly')) { + throw new Error('POSIX installer failed SHA-256 or format verification'); + } + result.push({ name: `OpenTest-Community-${version}-${platform === 'mac' ? 'macos' : platform}-${arch}-setup${extension}`, data, digest }); + } + return result; +} + /** * Publish the community installer verified by the successful Windows build job. * Daily builds (A.B.C-dev.[.N]) come only from main and create tag vVERSION on the built commit. @@ -24,6 +52,9 @@ module.exports = async function publishCommunityBuild({ artifactDigest, installerPath, installerDigest, + posixRoot, + pluginsRef, + pluginsSha, }) { const channel = channelOf(version); const tag = `v${version}`; @@ -62,8 +93,10 @@ module.exports = async function publishCommunityBuild({ } const assetName = `OpenTest-Community-${version}-windows-x64-setup.exe`; - const runUrl = `${context.serverUrl}/${repo.owner}/${repo.repo}/actions/runs/${context.runId}`; const kind = { dev: 'Daily build', rc: 'Release candidate', release: 'Release' }[channel]; + // Verify every platform before creating the one draft. Only this job writes Releases. + const assets = [{ name: assetName, data: installer, digest }, + ...(posixRoot ? posixInstallers({ version, root: posixRoot }) : [])]; const { data: draft } = await github.rest.repos.createRelease({ ...repo, tag_name: tag, @@ -74,35 +107,44 @@ module.exports = async function publishCommunityBuild({ make_latest: 'false', generate_release_notes: channel !== 'dev', body: [ - `${kind} of the OpenTest community package / 社区包${{ dev: '日常构建', rc: '候选版本', release: '正式版本' }[channel]}.`, + `${kind} of the OpenTest community package / OpenTest 社区包${{ dev: '日常构建', rc: '候选版本', release: '正式版本' }[channel]}。`, '', `Source commit: ${context.sha}`, - `Successful build: ${runUrl}`, + `Successful build: ${context.serverUrl}/${repo.owner}/${repo.repo}/actions/runs/${context.runId}`, + `OpenTest-Plugins commit: ${pluginsSha || 'not provided'}${pluginsRef ? ` (ref ${pluginsRef})` : ''}`, '', - 'Includes OpenTest and the plugins from crysound/OpenTest-Plugins: the public business plugins and the SonoDAQ device plugin. Plugins from the website package are not included.', '包含 OpenTest 和 crysound/OpenTest-Plugins 中的插件:公开业务插件和 SonoDAQ 设备插件。不含官网完整包中的其他插件。', - 'Unsigned Windows x64 build using the test license service; automatic updates are disabled.', + 'Includes OpenTest and the plugins from crysound/OpenTest-Plugins: the public business plugins and the SonoDAQ device plugin. Plugins from the website package are not included.', '未签名的 Windows x64 安装包,使用测试授权服务,已关闭自动更新。', - 'The build verified silent installation, installed x64 binaries and bundled runtime integrity. Cloud login, chart licensing and hardware functions are not covered by that check.', + 'Unsigned Windows x64 build using the test license service; automatic updates are disabled.', + ...(posixRoot ? [ + 'Linux x64 提供 DEB(Debian 软件包)安装包;macOS ARM64 提供 DMG(磁盘映像)安装包。两者使用生产算法及随包默认授权,已关闭自动更新。', + 'macOS 应用及插件仅作本机临时签名,未取得开发者签名或 Apple 公证;首次打开时请在“隐私与安全性”中点“仍要打开”。SonoDAQ 设备插件要求 macOS 26 或更高版本。', + '安装验证检查随包文件和 Java 运行时,不代表云端登录、付费算法授权或真实设备功能已通过验收。', + ] : []), + '已验证安装过程、程序架构和随包运行文件完整性;未验证云端登录、图表授权或硬件功能。', '', - `SHA-256 (${assetName}): \`${digest}\``, + 'SHA-256 文件校验值:', + ...assets.map(asset => `${asset.name}: \`${asset.digest}\``), ].join('\n'), }); - // Keep the release as a draft until both attachments have uploaded successfully. - await github.rest.repos.uploadReleaseAsset({ - ...repo, - release_id: draft.id, - name: assetName, - headers: { 'content-type': 'application/octet-stream' }, - data: installer, - }); - await github.rest.repos.uploadReleaseAsset({ - ...repo, - release_id: draft.id, - name: `${assetName}.sha256`, - headers: { 'content-type': 'text/plain' }, - data: Buffer.from(`${digest} ${assetName}\n`), - }); + // Keep the release private until every installer and checksum has uploaded. + for (const asset of assets) { + await github.rest.repos.uploadReleaseAsset({ + ...repo, + release_id: draft.id, + name: asset.name, + headers: { 'content-type': 'application/octet-stream' }, + data: asset.data, + }); + await github.rest.repos.uploadReleaseAsset({ + ...repo, + release_id: draft.id, + name: `${asset.name}.sha256`, + headers: { 'content-type': 'text/plain' }, + data: Buffer.from(`${asset.digest} ${asset.name}\n`), + }); + } const { data: release } = await github.rest.repos.updateRelease({ ...repo, release_id: draft.id, From e083a690f2398d4347ce557bd32c39ccf00e2395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=8D=9A=E6=9D=91=E5=AA=B7?= Date: Mon, 16 Nov 2026 21:55:54 +0800 Subject: [PATCH 02/13] ci: run plugin revision resolution with PowerShell --- .github/workflows/community-package.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/community-package.yml b/.github/workflows/community-package.yml index eb5c7fa6..3d273656 100644 --- a/.github/workflows/community-package.yml +++ b/.github/workflows/community-package.yml @@ -85,6 +85,7 @@ jobs: REF_TYPE: ${{ github.ref_type }} REF_NAME: ${{ github.ref_name }} REQUESTED_REF: ${{ inputs.plugins_ref }} + shell: pwsh run: | $repo = 'https://github.com/crysound/OpenTest-Plugins.git' $requested = if ($env:REQUESTED_REF) { $env:REQUESTED_REF } elseif ($env:REF_TYPE -eq 'tag') { $env:REF_NAME } else { 'main' } From 0099449097c98eddcdaead0dea3b13906d97559f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=8D=9A=E6=9D=91=E5=AA=B7?= Date: Mon, 16 Nov 2026 22:23:37 +0800 Subject: [PATCH 03/13] ci: make mac community packaging and checks reliable --- .github/workflows/community-package.yml | 2 -- tools/package.mjs | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/workflows/community-package.yml b/.github/workflows/community-package.yml index 3d273656..d4c17a4f 100644 --- a/.github/workflows/community-package.yml +++ b/.github/workflows/community-package.yml @@ -153,7 +153,6 @@ jobs: with: distribution: zulu java-version: '21' - cache: maven # The host device-plugin packager runs `python` (standard library only). - uses: actions/setup-python@v7 with: @@ -306,7 +305,6 @@ jobs: with: distribution: zulu java-version: '21' - cache: maven - uses: actions/setup-python@v7 with: python-version: '3.12' diff --git a/tools/package.mjs b/tools/package.mjs index 26db19bb..f4787e7c 100644 --- a/tools/package.mjs +++ b/tools/package.mjs @@ -91,7 +91,9 @@ export function createBuilderConfig({ directories: { app: path.join(stage, "app"), output, - buildResources: path.join(desktopRoot, "assets"), + buildResources: target.platform === 'mac' + ? path.join(stage, 'mac-build-resources') + : path.join(desktopRoot, "assets"), }, compression: "maximum", npmRebuild: false, @@ -202,6 +204,17 @@ export function createBuilderConfig({ return builder; } +function prepareMacBuildResources(stage) { + const source = path.join(desktopRoot, 'assets') + const destination = path.join(stage, 'mac-build-resources') + cpSync(source, destination, { + recursive: true, + dereference: true, + filter: sourcePath => !/[/\\](?:license|eula)(?:_[^/\\.]+)?\.(?:txt|rtf|html)$/i.test(sourcePath), + }) + return destination +} + export function resolveBundledPluginPackages(directory) { if (!directory) return []; const root = path.resolve(repositoryRoot, directory); @@ -380,6 +393,7 @@ export async function packageHost({ mode, kind, sign = false, platform = current packageArtifact: async (target) => { const { build, Platform, Arch } = requireDesktop("electron-builder"); const destination = path.join(output, target); + if (platform === 'mac') prepareMacBuildResources(stage); const builderConfig = createBuilderConfig({ config, stage, From 3a5447f83c2dea05ca17a6beca0cd28874ed2ac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=8D=9A=E6=9D=91=E5=AA=B7?= Date: Mon, 16 Nov 2026 22:52:37 +0800 Subject: [PATCH 04/13] ci: checkout plugins by verified commit --- .github/workflows/community-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/community-package.yml b/.github/workflows/community-package.yml index d4c17a4f..82085093 100644 --- a/.github/workflows/community-package.yml +++ b/.github/workflows/community-package.yml @@ -136,7 +136,7 @@ jobs: uses: actions/checkout@v7 with: repository: crysound/OpenTest-Plugins - ref: ${{ needs.version.outputs.plugins-ref }} + ref: ${{ needs.version.outputs.plugins-sha }} path: .runtime/opentest-plugins persist-credentials: false - name: Verify public plugin revision @@ -288,7 +288,7 @@ jobs: uses: actions/checkout@v7 with: repository: crysound/OpenTest-Plugins - ref: ${{ needs.version.outputs.plugins-ref }} + ref: ${{ needs.version.outputs.plugins-sha }} path: .runtime/opentest-plugins persist-credentials: false - name: Verify public plugin revision From 009ea3983959e29477f9a27f3e1017b61f6db7f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=8D=9A=E6=9D=91=E5=AA=B7?= Date: Mon, 16 Nov 2026 23:37:13 +0800 Subject: [PATCH 05/13] ci: fetch verified plugin revision explicitly --- .github/workflows/community-package.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/community-package.yml b/.github/workflows/community-package.yml index 82085093..d57a4836 100644 --- a/.github/workflows/community-package.yml +++ b/.github/workflows/community-package.yml @@ -136,13 +136,14 @@ jobs: uses: actions/checkout@v7 with: repository: crysound/OpenTest-Plugins - ref: ${{ needs.version.outputs.plugins-sha }} path: .runtime/opentest-plugins persist-credentials: false - name: Verify public plugin revision env: EXPECTED_PLUGINS_SHA: ${{ needs.version.outputs.plugins-sha }} run: | + git -C .runtime/opentest-plugins fetch --no-tags origin "$EXPECTED_PLUGINS_SHA" + git -C .runtime/opentest-plugins checkout --detach "$EXPECTED_PLUGINS_SHA" $actual = (git -C $env:PLUGINS_ROOT rev-parse HEAD).Trim() if ($actual -ne $env:EXPECTED_PLUGINS_SHA) { throw "OpenTest-Plugins revision mismatch: $actual" } - uses: actions/setup-node@v7 @@ -288,13 +289,14 @@ jobs: uses: actions/checkout@v7 with: repository: crysound/OpenTest-Plugins - ref: ${{ needs.version.outputs.plugins-sha }} path: .runtime/opentest-plugins persist-credentials: false - name: Verify public plugin revision env: EXPECTED_PLUGINS_SHA: ${{ needs.version.outputs.plugins-sha }} run: | + git -C .runtime/opentest-plugins fetch --no-tags origin "$EXPECTED_PLUGINS_SHA" + git -C .runtime/opentest-plugins checkout --detach "$EXPECTED_PLUGINS_SHA" actual=$(git -C .runtime/opentest-plugins rev-parse HEAD) test "$actual" = "$EXPECTED_PLUGINS_SHA" - uses: actions/setup-node@v7 From 1b46ff70a608e8531dfeb011a37ee6cfde405b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=8D=9A=E6=9D=91=E5=AA=B7?= Date: Tue, 17 Nov 2026 07:25:10 +0800 Subject: [PATCH 06/13] ci: fix community package review findings --- .github/workflows/community-package.yml | 38 +++---------- CONTEXT.md | 2 +- CONTRIBUTING.md | 6 +- CONTRIBUTING.zh-CN.md | 6 +- tools/__tests__/community-package.test.mjs | 46 +++++++++++++-- tools/__tests__/mac-build-resources.test.mjs | 48 ++++++++++++++++ .../publish-community-build.test.mjs | 36 +++++++----- .../resolve-plugin-revision.test.mjs | 56 +++++++++++++++++++ tools/ci/prepare-electron.mjs | 3 +- tools/ci/prepare-installer.mjs | 23 +++++--- tools/ci/resolve-plugin-revision.mjs | 40 +++++++++++++ tools/ci/verify-posix-installer.mjs | 26 +++++++-- tools/package.mjs | 30 ++++++++-- tools/publish-community-build.cjs | 38 ++++++++----- 14 files changed, 308 insertions(+), 90 deletions(-) create mode 100644 tools/__tests__/mac-build-resources.test.mjs create mode 100644 tools/__tests__/resolve-plugin-revision.test.mjs create mode 100644 tools/ci/resolve-plugin-revision.mjs diff --git a/.github/workflows/community-package.yml b/.github/workflows/community-package.yml index d57a4836..9bbc87c1 100644 --- a/.github/workflows/community-package.yml +++ b/.github/workflows/community-package.yml @@ -35,7 +35,7 @@ on: workflow_dispatch: inputs: plugins_ref: - description: OpenTest-Plugins branch or tag (default main; tag builds use the same tag) + description: OpenTest-Plugins branch, tag, full ref or commit SHA (tag builds require the same tag) required: false default: '' permissions: @@ -85,29 +85,7 @@ jobs: REF_TYPE: ${{ github.ref_type }} REF_NAME: ${{ github.ref_name }} REQUESTED_REF: ${{ inputs.plugins_ref }} - shell: pwsh - run: | - $repo = 'https://github.com/crysound/OpenTest-Plugins.git' - $requested = if ($env:REQUESTED_REF) { $env:REQUESTED_REF } elseif ($env:REF_TYPE -eq 'tag') { $env:REF_NAME } else { 'main' } - $ref = $requested - $sha = '' - if ($env:REF_TYPE -eq 'tag' -and -not $env:REQUESTED_REF) { - $sha = (git ls-remote $repo "refs/tags/$requested^{}" | ForEach-Object { ($_ -split '\s+')[0] } | Select-Object -First 1) - if (-not $sha) { $sha = (git ls-remote $repo "refs/tags/$requested" | ForEach-Object { ($_ -split '\s+')[0] } | Select-Object -First 1) } - if (-not $sha) { - $ref = 'main' - $sha = (git ls-remote $repo 'refs/heads/main' | ForEach-Object { ($_ -split '\s+')[0] } | Select-Object -First 1) - Write-Host "OpenTest-Plugins has no tag $requested; using main at $sha." - } - } else { - $sha = (git ls-remote $repo "refs/heads/$requested" | ForEach-Object { ($_ -split '\s+')[0] } | Select-Object -First 1) - if (-not $sha) { $sha = (git ls-remote $repo "refs/tags/$requested^{}" | ForEach-Object { ($_ -split '\s+')[0] } | Select-Object -First 1) } - if (-not $sha) { $sha = (git ls-remote $repo "refs/tags/$requested" | ForEach-Object { ($_ -split '\s+')[0] } | Select-Object -First 1) } - } - if ($sha -notmatch '^[0-9a-f]{40}$') { throw "Could not resolve OpenTest-Plugins ref: $requested" } - "ref=$ref" >> $env:GITHUB_OUTPUT - "sha=$sha" >> $env:GITHUB_OUTPUT - Write-Host "OpenTest-Plugins: $ref ($sha)" + run: node tools/ci/resolve-plugin-revision.mjs build: needs: version name: build-community-installer @@ -136,20 +114,22 @@ jobs: uses: actions/checkout@v7 with: repository: crysound/OpenTest-Plugins + ref: ${{ needs.version.outputs.plugins-sha }} path: .runtime/opentest-plugins persist-credentials: false - name: Verify public plugin revision env: EXPECTED_PLUGINS_SHA: ${{ needs.version.outputs.plugins-sha }} run: | - git -C .runtime/opentest-plugins fetch --no-tags origin "$EXPECTED_PLUGINS_SHA" - git -C .runtime/opentest-plugins checkout --detach "$EXPECTED_PLUGINS_SHA" - $actual = (git -C $env:PLUGINS_ROOT rev-parse HEAD).Trim() + $actual = git -C $env:PLUGINS_ROOT rev-parse HEAD + if ($LASTEXITCODE -ne 0) { throw 'Could not read the checked-out plugin revision.' } + $actual = $actual.Trim() if ($actual -ne $env:EXPECTED_PLUGINS_SHA) { throw "OpenTest-Plugins revision mismatch: $actual" } - uses: actions/setup-node@v7 with: node-version: 22 package-manager-cache: false + # Do not persist Maven caches: manually selected plugin code must not poison later release builds. - uses: actions/setup-java@v6 with: distribution: zulu @@ -289,20 +269,20 @@ jobs: uses: actions/checkout@v7 with: repository: crysound/OpenTest-Plugins + ref: ${{ needs.version.outputs.plugins-sha }} path: .runtime/opentest-plugins persist-credentials: false - name: Verify public plugin revision env: EXPECTED_PLUGINS_SHA: ${{ needs.version.outputs.plugins-sha }} run: | - git -C .runtime/opentest-plugins fetch --no-tags origin "$EXPECTED_PLUGINS_SHA" - git -C .runtime/opentest-plugins checkout --detach "$EXPECTED_PLUGINS_SHA" actual=$(git -C .runtime/opentest-plugins rev-parse HEAD) test "$actual" = "$EXPECTED_PLUGINS_SHA" - uses: actions/setup-node@v7 with: node-version: 22 package-manager-cache: false + # Do not persist Maven caches: manually selected plugin code must not poison later release builds. - uses: actions/setup-java@v6 with: distribution: zulu diff --git a/CONTEXT.md b/CONTEXT.md index a14da749..07d4737b 100644 --- a/CONTEXT.md +++ b/CONTEXT.md @@ -5,7 +5,7 @@ 宿主默认独立构建、打包和启动,不依赖插件仓库,不要求安装外置业务或设备插件。`default-plugins.json` 只列公开插件 `fft-tools`,仅供显式套件构建;只有提供预制 `--plugins-dir` 或启用 CI 的 `bundle_plugins` 时才随附业务插件。源码启动默认忽略套件缓存,只有显式 `OPENTEST_BUNDLED_PLUGINS_DIR` 才选择该材料。插件仓库消费公开 SDK 并独立生成自己的安装包。 `apps/native` 维护公开 Device Host、IPC、SDK、portable 加载器、校验器、管理器、`common_device_runtime` 共享插件运行时及其平台实现和测试。JNI(含 Host 客户端)、算法适配、系统音频、蓝牙、Sequence 和设备控制等原生组件以预编译二进制随附,例如 `apps/desktop/packages/native-modules/vendor/` 和后端 `resources/native/`;其源码不在本仓库。 -SonoDAQ 源码在公开的 `OpenTest-Plugins/native/opentest_sonodaq_plugin` 维护;其他具体设备插件由各自独立源码和部署材料提供。公开 Host 构建不依赖具体设备插件源码或 JNI 源码。 +SonoDAQ 源码在公开的 `OpenTest-Plugins/plugins/opentest_sonodaq_plugin` 维护;其他具体设备插件由各自独立源码和部署材料提供。公开 Host 构建不依赖具体设备插件源码或 JNI 源码。 构建输出位于源码外,与后端 `resources/native/` 运行材料分开管理;构建不自动替换已部署二进制。框架边界遵循 `apps/native/AGENTS.md`,当前入口见 [公开构建说明](apps/native/docs/public-build.md)。 ## 开发工作区术语 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d4b082dc..89ac7d32 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,7 +41,11 @@ node --test tools/__tests__/docs-policy.test.mjs ## Community packages -The `community-package` workflow builds the unsigned Windows community installer: OpenTest plus the plugins from `crysound/OpenTest-Plugins`: the business plugins listed in `default-plugins.json` (currently `fft-tools`) and the SonoDAQ device plugin, which is bundled under `resources/backend/native/plugins/devices`. Each push to `main` publishes a daily prerelease `A.B.C-dev.` (later builds on the same Beijing day add `.2`, `.3` and so on). Pushing tag `vA.B.C-rc.N` or `vA.B.C` publishes a release candidate or a release; tag the same name in `OpenTest-Plugins` first. Pull requests that change packaging only build and verify the installer. `package.json` keeps the plain `A.B.C` used for plugin compatibility; the full version is passed to `node tools/package.mjs --version`. The workflow uses `--edition community`, which bundles only the plugins listed in `default-plugins.json`. +The `community-package` workflow builds three community installers: an EXE executable installer for Windows x64, a DEB Debian package for Linux x64, and a DMG disk image for macOS ARM64. They include OpenTest, the business plugins listed in `default-plugins.json` (currently `fft-tools`) from `crysound/OpenTest-Plugins`, and the SonoDAQ device plugin, but not the other plugins from the website package. Device plugins are bundled under `backend/native/plugins/devices` in the application resources. Windows retains `test` mode; Linux and macOS use `production` license mode, with separate generated configurations for each mode. All platforms connect to `https://update.opentest.com`; there is no separate test server. Automatic updates are disabled. Windows is unsigned; macOS retains its multilingual license agreement and has only ad hoc signatures, without developer signing or Apple notarization. On first launch, choose Open Anyway in Privacy & Security. The SonoDAQ device plugin requires macOS 26 or later. + +Each push to `main` publishes a daily prerelease `A.B.C-dev.`; later builds on the same Beijing day add `.1`, `.2` and so on. Pushing `vA.B.C-rc.N` or `vA.B.C` publishes a release candidate or release. First create the same tag in `OpenTest-Plugins`: a missing tag fails the build instead of falling back to `main`. Daily builds and pull requests resolve the plugin `main` by default. Only an explicit `plugins_ref` input to `workflow_dispatch` overrides that choice; it accepts branch names, tag names, full references starting with `refs/`, and 40-character commit hashes. All three platforms check out the same resolved commit directly and verify it again, so a moving branch cannot change the build inputs. After every build and installation check succeeds, one publishing job uploads three installers and their SHA-256 checksum files before making the release public. + +Pull requests targeting `main` trigger all three builds and installation checks, without publishing, when they change the packaging scripts listed in the workflow, `tools/__tests__/**`, `tools/ci/**`, `default-plugins.json`, `packaging.config.json`, `apps/**`, `sdks/**`, `vendor/**`, `package.json`, or `pnpm-lock.yaml`. This intentionally retains the existing scope, including application, software development kit and runtime material changes. `package.json` keeps the plain `A.B.C` used for plugin compatibility; the full version is passed to `node tools/package.mjs --version`. The workflow uses `--edition community`. ## GitHub enforcement diff --git a/CONTRIBUTING.zh-CN.md b/CONTRIBUTING.zh-CN.md index b295bc56..bc86fa0a 100644 --- a/CONTRIBUTING.zh-CN.md +++ b/CONTRIBUTING.zh-CN.md @@ -41,7 +41,11 @@ node --test tools/__tests__/docs-policy.test.mjs ## 社区包 -`community-package` 工作流构建未签名的 Windows 社区安装包:OpenTest,加上 `crysound/OpenTest-Plugins` 中的插件:`default-plugins.json` 列出的业务插件(当前为 `fft-tools`),以及 SonoDAQ 设备插件。设备插件放在安装目录的 `resources/backend/native/plugins/devices` 下。每次推送到 `main` 都发布一个日常预发布版本 `A.B.C-dev.<年月日>`,北京时间同一天的后续构建依次加 `.2`、`.3`。推送 `vA.B.C-rc.N` 或 `vA.B.C` 标签会发布候选版本或正式版本,打标签前先在 `OpenTest-Plugins` 打同名标签。修改打包相关文件的拉取请求只构建和校验安装包,不发布。`package.json` 保留用于插件兼容性的 `A.B.C`,完整版本号通过 `node tools/package.mjs --version` 传入。该工作流使用 `--edition community`,只随附 `default-plugins.json` 列出的插件。 +`community-package` 工作流构建三平台社区安装包:Windows x64 的 EXE(可执行安装程序)、Linux x64 的 DEB(Debian 软件包)、macOS ARM64 的 DMG(磁盘映像)。社区包包含 OpenTest、`crysound/OpenTest-Plugins` 中由 `default-plugins.json` 列出的业务插件(当前为 `fft-tools`)和 SonoDAQ 设备插件,不含官网完整包的其他插件。设备插件放在应用资源目录的 `backend/native/plugins/devices` 下。Windows 保留 `test` 测试模式,Linux、macOS 使用 `production` 正式授权模式,各模式独立生成配置。三平台均连接 `https://update.opentest.com`,当前没有独立测试服务器;自动更新均关闭。Windows 未签名;macOS 保留多语言许可协议,仅作本机临时签名,未取得开发者签名或 Apple 公证,首次打开需在“隐私与安全性”中点“仍要打开”。SonoDAQ 设备插件要求 macOS 26 或更高版本。 + +每次推送到 `main` 都发布一个日常预发布版本 `A.B.C-dev.<年月日>`,北京时间同一天的后续构建依次加 `.1`、`.2`。推送 `vA.B.C-rc.N` 或 `vA.B.C` 标签会发布候选版本或正式版本;必须先在 `OpenTest-Plugins` 创建同名标签,缺失时构建立即失败,不回落到 `main`。日常构建和拉取请求默认解析插件的 `main`;只有手动触发 `workflow_dispatch` 并显式填写 `plugins_ref` 才可覆盖,支持分支名、标签名、`refs/` 开头的完整引用和 40 位提交编号。三个平台直接检出解析得到的同一提交,并再次核对,防止构建期间分支前移。全部构建及安装验证通过后,单一发布任务先上传三个安装包及各自的 SHA-256 文件校验值,再公开版本。 + +面向 `main` 的拉取请求若修改工作流中列出的打包脚本、`tools/__tests__/**`、`tools/ci/**`、`default-plugins.json`、`packaging.config.json`、`apps/**`、`sdks/**`、`vendor/**`、`package.json` 或 `pnpm-lock.yaml`,会触发三平台构建和安装验证,但不发布。这一范围有意包含应用、软件开发套件和运行材料变更,保持现有触发规则。`package.json` 保留用于插件兼容性的 `A.B.C`,完整版本号通过 `node tools/package.mjs --version` 传入;工作流使用 `--edition community`。 ## GitHub 强制检查 diff --git a/tools/__tests__/community-package.test.mjs b/tools/__tests__/community-package.test.mjs index d320b90f..abdb8fc8 100644 --- a/tools/__tests__/community-package.test.mjs +++ b/tools/__tests__/community-package.test.mjs @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; import { createRequire } from 'node:module'; import { execFileSync } from 'node:child_process'; -import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; +import { mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import test from 'node:test'; @@ -40,25 +40,59 @@ test('工作流为三平台共用版本,只有推送且全部构建成功才 assert.ok(windows.some(s => s.run?.includes('--platform windows --mode test'))); assert.ok(windows.some(s => s.name === 'Verify public plugin revision')); assert.ok(workflow.jobs['build-posix'].steps.some(s => s.name === 'Verify public plugin revision')); + for (const job of [workflow.jobs.build, workflow.jobs['build-posix']]) { + const checkout = job.steps.find(s => s.with?.repository === 'crysound/OpenTest-Plugins'); + assert.equal(checkout.with.ref, '${{ needs.version.outputs.plugins-sha }}'); + assert.equal(checkout.with.path, '.runtime/opentest-plugins'); + } + assert.equal(workflow.jobs.build.env.PLUGINS_ROOT, '${{ github.workspace }}/.runtime/opentest-plugins'); + const windowsVerify = windows.find(s => s.name === 'Verify public plugin revision').run; + assert.match(windowsVerify, /\$env:EXPECTED_PLUGINS_SHA/); + assert.match(windowsVerify, /\$LASTEXITCODE -ne 0/); const posix = workflow.jobs['build-posix'].steps; const verify = posix.findIndex(s => s.run?.includes('verify-posix-installer.mjs')); const upload = posix.findIndex(s => s.uses?.startsWith('actions/upload-artifact@')); assert.ok(verify > 0 && upload > verify); }); -test('安装配置在生产模式也使用自动构建生成的公开配置', () => { +test('三平台生成独立模式配置并使用明确的正式许可证地址', t => { const temporary = mkdtempSync(path.join(os.tmpdir(), 'opentest-ci-installer-')); + t.after(() => rmSync(temporary, { recursive: true, force: true })); execFileSync(process.execPath, ['tools/ci/prepare-installer.mjs'], { cwd: repositoryRoot, env: { ...process.env, OPENTEST_CI_NATIVE_PLUGIN_BIN_ROOT: '', OPENTEST_CI_INSTALLER_DIRECTORY: temporary }, }); for (const platform of ['windows', 'linux', 'mac']) { - const config = loadPackagingConfig(platform === 'windows' ? 'test' : 'production', + const mode = platform === 'windows' ? 'test' : 'production'; + const config = loadPackagingConfig(mode, path.join(temporary, 'packaging.json'), platform); - assert.equal(config.backendConfig, path.join(temporary, 'application.properties')); - assert.equal(config.desktopConfig, path.join(temporary, 'local-settings.json')); + assert.equal(config.backendConfig, path.join(temporary, `application-${mode}.properties`)); + assert.equal(config.desktopConfig, path.join(temporary, `local-settings-${mode}.json`)); + assert.equal(config.services.environment, mode); + assert.equal(config.services.licenseUrl, 'https://update.opentest.com'); + assert.match(readFileSync(config.backendConfig, 'utf8'), /^cloud\.license\.url=https:\/\/update\.opentest\.com$/m); assert.equal(JSON.parse(readFileSync(config.desktopConfig, 'utf8')).updates.enabled, false); } - rmSync(temporary, { recursive: true, force: true }); +}); + +test('安装文件检查识别符号链接缺失、目标变化和文件类型变化', t => { + const root = mkdtempSync(path.join(os.tmpdir(), 'opentest-links-')); + t.after(() => rmSync(root, { recursive: true, force: true })); + const source = path.join(root, 'source'), installed = path.join(root, 'installed'); + mkdirSync(source); mkdirSync(installed); + const original = path.join(root, 'original'), other = path.join(root, 'other'); + mkdirSync(original); mkdirSync(other); + // Windows 目录联接无需额外权限,仍由 lstat/readlink 作为链接比较。 + const link = (target, name) => symlinkSync(target, name, process.platform === 'win32' ? 'junction' : 'dir'); + link(original, path.join(source, 'runtime')); + link(original, path.join(installed, 'runtime')); + assert.equal(assertSameTree(source, installed), 1); + rmSync(path.join(installed, 'runtime')); + assert.throws(() => assertSameTree(source, installed)); + link(other, path.join(installed, 'runtime')); + assert.throws(() => assertSameTree(source, installed)); + rmSync(path.join(installed, 'runtime')); + writeFileSync(path.join(installed, 'runtime'), 'regular file'); + assert.throws(() => assertSameTree(source, installed), /类型/); }); test('安装文件检查拒绝缺失、额外或内容被修改的文件', t => { diff --git a/tools/__tests__/mac-build-resources.test.mjs b/tools/__tests__/mac-build-resources.test.mjs new file mode 100644 index 00000000..291620c5 --- /dev/null +++ b/tools/__tests__/mac-build-resources.test.mjs @@ -0,0 +1,48 @@ +import assert from 'node:assert/strict'; +import { mkdtempSync, readdirSync, readFileSync, rmSync } from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; +import test from 'node:test'; +import { createBuilderConfig, licenseTextToRtf, prepareMacBuildResources } from '../package.mjs'; +import { desktopRoot } from '../runtime.mjs'; + +function decodeRtf(rtf) { + assert.match(rtf, /^\{\\rtf1\\ansi\\ansicpg1252\\uc1 /); + const body = rtf.replace(/^\{\\rtf1\\ansi\\ansicpg1252\\uc1 /, '').slice(0, -1); + return body.replace(/\\u(-?\d+)\?|\\par\n|\\tab |\\([\\{}])/g, (all, number, escaped) => { + if (number !== undefined) return String.fromCharCode(Number(number) & 0xffff); + if (escaped) return escaped; + return all.startsWith('\\par') ? '\n' : '\t'; + }); +} + +test('许可协议转换保留 Unicode、特殊符号、段落及 RTF 保留字符', () => { + const text = 'Français ● 中文 한국어 日本語 😀 {terms} \\ path\tvalue\r\nnext'; + const rtf = licenseTextToRtf('\uFEFF' + text); + assert.doesNotMatch(rtf, /[^\x00-\x7f]/); + assert.equal(decodeRtf(rtf), text.replace(/\r\n/g, '\n')); +}); + +test('macOS builder 使用含全部九种语言协议的暂存资源,其他平台保持原资源', t => { + const stage = mkdtempSync(path.join(os.tmpdir(), 'opentest-mac-resources-')); + t.after(() => rmSync(stage, { recursive: true, force: true })); + const source = path.join(desktopRoot, 'assets'); + const target = prepareMacBuildResources(stage); + // --kind both 会在同一暂存目录分别构建安装包和升级包。 + assert.equal(prepareMacBuildResources(stage), target); + const licenses = readdirSync(source).filter(name => /^license_.*\.txt$/.test(name)); + assert.equal(licenses.length, 9); + for (const name of licenses) { + const original = readFileSync(path.join(source, name), 'utf8'); + const rtf = readFileSync(path.join(target, name.replace('.txt', '.rtf')), 'ascii'); + assert.equal(decodeRtf(rtf), original.replace(/^\uFEFF/, '').replace(/\r\n?/g, '\n'), name); + assert.equal(readFileSync(path.join(source, name), 'utf8'), original); + } + assert.deepEqual(readFileSync(path.join(target, 'icons/darwin/icon.icns')), readFileSync(path.join(source, 'icons/darwin/icon.icns'))); + assert.equal(readdirSync(target).filter(name => /^license_.*\.(txt|rtf|html)$/.test(name)).length, licenses.length); + for (const platform of ['mac', 'windows', 'linux']) { + const builder = createBuilderConfig({ config: { platform, mode: 'production' }, stage, + output: path.join(stage, 'out'), version: '2.5.0', kind: 'installer', electronExecutable: '/runtime/electron' }); + assert.equal(builder.directories.buildResources, platform === 'mac' ? target : source); + } +}); diff --git a/tools/__tests__/publish-community-build.test.mjs b/tools/__tests__/publish-community-build.test.mjs index d822397b..46416ce0 100644 --- a/tools/__tests__/publish-community-build.test.mjs +++ b/tools/__tests__/publish-community-build.test.mjs @@ -9,7 +9,7 @@ import publish from '../publish-community-build.cjs'; const temporary = mkdtempSync(path.join(os.tmpdir(), 'opentest-release-')); after(() => rmSync(temporary, { recursive: true, force: true })); -function fixture(version = '2.5.0-dev.20261114.2', ref = 'refs/heads/main') { +function windowsFixture(version = '2.5.0-dev.20261114.2', ref = 'refs/heads/main') { const installer = Buffer.alloc(256); installer.write('MZ'); installer.writeUInt32LE(128, 0x3c); @@ -45,7 +45,7 @@ test('daily builds from main create the dated tag and stay prereleases', async ( const { options, calls, installer } = fixture(); const result = await publish(options); assert.match(result.html_url, /releases\/tag\/v2\.5\.0-dev\.20261114\.2$/); - assert.deepEqual(calls.map(c => c.name), ['createRelease', 'uploadReleaseAsset', 'uploadReleaseAsset', 'updateRelease']); + assert.deepEqual(calls.map(c => c.name), ['createRelease', ...Array(6).fill('uploadReleaseAsset'), 'updateRelease']); assert.equal(calls[0].args.tag_name, 'v2.5.0-dev.20261114.2'); assert.equal(calls[0].args.target_commitish, options.context.sha); assert.equal(calls[0].args.draft, true); @@ -54,9 +54,9 @@ test('daily builds from main create the dated tag and stay prereleases', async ( assert.deepEqual(calls[1].args.data, installer); assert.equal(calls[1].args.name, 'OpenTest-Community-2.5.0-dev.20261114.2-windows-x64-setup.exe'); assert.equal(calls[2].args.data.toString(), `${options.installerDigest} ${calls[1].args.name}\n`); - assert.equal(calls[3].args.draft, false); - assert.equal(calls[3].args.prerelease, true); - assert.equal(calls[3].args.make_latest, 'false'); + assert.equal(calls.at(-1).args.draft, false); + assert.equal(calls.at(-1).args.prerelease, true); + assert.equal(calls.at(-1).args.make_latest, 'false'); }); test('release candidates and releases publish only from their own tag', async () => { @@ -64,12 +64,12 @@ test('release candidates and releases publish only from their own tag', async () await publish(rc.options); assert.equal(rc.calls[0].args.prerelease, true); assert.equal(rc.calls[0].args.generate_release_notes, true); - assert.equal(rc.calls[3].args.make_latest, 'false'); + assert.equal(rc.calls.at(-1).args.make_latest, 'false'); const release = fixture('2.5.0', 'refs/tags/v2.5.0'); await publish(release.options); assert.equal(release.calls[0].args.tag_name, 'v2.5.0'); - assert.equal(release.calls[3].args.prerelease, false); - assert.equal(release.calls[3].args.make_latest, 'true'); + assert.equal(release.calls.at(-1).args.prerelease, false); + assert.equal(release.calls.at(-1).args.make_latest, 'true'); }); test('refuses a version that does not match the triggering ref', async () => { @@ -131,6 +131,11 @@ test('rejects invalid inputs without creating a release', async () => { for (const change of [ o => { o.version = '2.5.0-beta.1'; }, o => { o.artifactId = ''; }, + o => { delete o.posixRoot; }, + o => { o.posixRoot = 'relative'; }, + o => { delete o.pluginsSha; }, + o => { o.pluginsSha = 'b'.repeat(39); }, + o => { o.pluginsSha = 'g'.repeat(40); }, o => { o.artifactDigest = ''; }, o => { o.installerDigest = ''; }, o => { o.installerPath = 'app.zip'; }, @@ -143,8 +148,8 @@ test('rejects invalid inputs without creating a release', async () => { } }); -function multiplatformFixture(version, ref) { - const f = fixture(version, ref); +function fixture(version, ref) { + const f = windowsFixture(version, ref); const { options } = f; options.posixRoot = mkdtempSync(path.join(temporary, 'posix-')); f.reports = []; @@ -171,7 +176,7 @@ function multiplatformFixture(version, ref) { } test('three verified platforms create one release and publish only after all six uploads', async () => { - const { options, calls } = multiplatformFixture(); + const { options, calls } = fixture(); await publish(options); assert.equal(calls.filter(c => c.name === 'createRelease').length, 1); const uploads = calls.filter(c => c.name === 'uploadReleaseAsset'); @@ -185,11 +190,12 @@ test('three verified platforms create one release and publish only after all six assert.match(calls[0].args.body, /Successful build:/); assert.match(calls[0].args.body, /OpenTest-Plugins commit: b{40}/); assert.match(calls[0].args.body, /Includes OpenTest/); + for (const phrase of ['production license mode', 'https://update.opentest.com', 'no separate test server', 'multilingual license agreement', 'Open Anyway', 'macOS 26', 'were not verified', 'SHA-256 checksums:']) assert.ok(calls[0].args.body.includes(phrase), phrase); }); test('all-platform release and RC retain channel semantics', async () => { for (const version of ['2.5.0', '2.5.0-rc.1']) { - const f = multiplatformFixture(version, `refs/tags/v${version}`); + const f = fixture(version, `refs/tags/v${version}`); await publish(f.options); assert.equal(f.calls.at(-1).args.make_latest, version === '2.5.0' ? 'true' : 'false'); } @@ -197,7 +203,7 @@ test('all-platform release and RC retain channel semantics', async () => { test('missing or invalid downloaded POSIX files block release creation', async () => { for (const damage of ['missing', 'report', 'delivery', 'digest', 'format']) { - const f = multiplatformFixture(); + const f = fixture(); if (damage === 'missing') rmSync(path.join(f.options.posixRoot, 'mac'), { recursive: true, force: true }); if (damage === 'report') rmSync(f.reports[1]); if (damage === 'delivery') rmSync(path.join(f.options.posixRoot, 'mac/delivery.json')); @@ -224,7 +230,7 @@ test('missing or invalid downloaded POSIX files block release creation', async ( test('failed installation, wrong version and changed installer block all publication', async () => { for (const damage of ['install', 'version', 'bytes', 'format']) { - const f = multiplatformFixture(); + const f = fixture(); const report = JSON.parse(readFileSync(f.reports[1], 'utf8')); if (damage === 'install') report.installationVerification = 'failed'; if (damage === 'version') report.version = '2.5.0'; @@ -246,7 +252,7 @@ test('failed installation, wrong version and changed installer block all publica }); test('a late platform upload failure leaves the release as a draft', async () => { - const f = multiplatformFixture(); + const f = fixture(); const upload = f.options.github.rest.repos.uploadReleaseAsset; f.options.github.rest.repos.uploadReleaseAsset = async args => { if (args.name.endsWith('.dmg')) throw new Error('mac upload failed'); diff --git a/tools/__tests__/resolve-plugin-revision.test.mjs b/tools/__tests__/resolve-plugin-revision.test.mjs new file mode 100644 index 00000000..a5e1df46 --- /dev/null +++ b/tools/__tests__/resolve-plugin-revision.test.mjs @@ -0,0 +1,56 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { resolvePluginRevision } from '../ci/resolve-plugin-revision.mjs'; + +const commit = 'a'.repeat(40), tagObject = 'b'.repeat(40); +function lookup(entries, queries = []) { + return { lsRemote(refs) { + queries.push(...refs); + return Object.entries(entries).filter(([ref]) => refs.includes(ref)).map(([ref, sha]) => `${sha}\t${ref}`).join('\n'); + } }; +} + +test('主线和拉取请求锁定插件 main,不接受非手动事件的覆盖输入', () => { + for (const eventName of ['push', 'pull_request']) { + assert.deepEqual(resolvePluginRevision({ eventName, refType: 'branch', requestedRef: 'other' }, + lookup({ 'refs/heads/main': commit, 'refs/heads/other': tagObject })), { ref: 'main', sha: commit }); + } +}); + +for (const refName of ['v2.5.0', 'v2.5.0-rc.1']) { + test(`${refName} 缺少同名插件标签时失败,不借用同名分支或 main`, () => { + const queries = []; + assert.throws(() => resolvePluginRevision({ eventName: 'push', refType: 'tag', refName, requestedRef: 'main' }, + lookup({ 'refs/heads/main': commit, [`refs/heads/${refName}`]: commit }, queries)), /同名标签/); + assert.ok(queries.every(ref => ref.startsWith(`refs/tags/${refName}`))); + }); + test(`${refName} 支持轻量标签与附注标签,附注标签取提交而非标签对象`, () => { + for (const annotated of [false, true]) { + const refs = { [`refs/tags/${refName}`]: annotated ? tagObject : commit }; + if (annotated) refs[`refs/tags/${refName}^{}`] = commit; + assert.equal(resolvePluginRevision({ eventName: 'push', refType: 'tag', refName }, lookup(refs)).sha, commit); + } + }); +} + +test('只有手动输入能够覆盖标签,支持分支、标签、完整引用和 40 位提交', () => { + const refs = { 'refs/heads/feature': commit, 'refs/tags/plugin-release': tagObject, + 'refs/tags/plugin-release^{}': commit, 'refs/pull/12/head': commit }; + for (const requestedRef of ['feature', 'plugin-release', 'refs/heads/feature', 'refs/tags/plugin-release', 'refs/pull/12/head']) { + assert.deepEqual(resolvePluginRevision({ eventName: 'workflow_dispatch', refType: 'tag', refName: 'v2.5.0', requestedRef }, lookup(refs)), + { ref: requestedRef, sha: commit }); + } + assert.deepEqual(resolvePluginRevision({ eventName: 'workflow_dispatch', requestedRef: commit.toUpperCase() }, { + lsRemote() { throw new Error('提交编号应直接交给 checkout 验证是否存在'); }, + }), { ref: commit.toUpperCase(), sha: commit }); +}); + +test('空白手动输入遵守标签规则,非法引用和网络错误不能回落', () => { + assert.throws(() => resolvePluginRevision({ eventName: 'workflow_dispatch', refType: 'tag', refName: 'v2.5.0', requestedRef: ' ' }, lookup({})), /同名标签/); + for (const requestedRef of ['main\nsha=bad', '*', 'refs/heads/a..b', 'refs/heads/a^{}']) { + assert.throws(() => resolvePluginRevision({ eventName: 'workflow_dispatch', requestedRef }, lookup({})), /格式/); + } + const failure = new Error('remote unavailable'); + assert.throws(() => resolvePluginRevision({ eventName: 'push' }, { lsRemote() { throw failure; } }), error => error === failure); + assert.throws(() => resolvePluginRevision({ eventName: 'push' }, lookup({ 'refs/heads/main': 'bad' })), /无法解析/); +}); diff --git a/tools/ci/prepare-electron.mjs b/tools/ci/prepare-electron.mjs index 2ddbae87..204ea782 100644 --- a/tools/ci/prepare-electron.mjs +++ b/tools/ci/prepare-electron.mjs @@ -3,6 +3,7 @@ import { execFileSync } from 'node:child_process'; import { createRequire } from 'node:module'; import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'; import path from 'node:path'; +import os from 'node:os'; import { repositoryRoot } from '../runtime.mjs'; import { currentPackagingPlatform, resolvePackagingPlatform, assertPackagingPlatformReady } from '../packaging-platforms.mjs'; @@ -16,7 +17,7 @@ if (!/^\d+\.\d+\.\d+$/.test(version)) throw new Error('Electron 版本无效'); const archiveName = `electron-v${version}-${target.nodePlatform}-${target.arch}.zip`; const expected = JSON.parse(readFileSync(path.join(root, 'checksums.json'), 'utf8'))[archiveName]; if (!/^[0-9a-f]{64}$/.test(expected)) throw new Error('锁定依赖中缺少当前平台的 Electron 校验值'); -const archive = path.join(process.env.RUNNER_TEMP, archiveName); +const archive = path.join(process.env.RUNNER_TEMP || os.tmpdir(), archiveName); execFileSync('curl', ['--fail', '--location', '--retry', '3', '--output', archive, `https://github.com/electron/electron/releases/download/v${version}/${archiveName}`], { stdio: 'inherit' }); if (createHash('sha256').update(readFileSync(archive)).digest('hex') !== expected) throw new Error('Electron 下载校验失败'); diff --git a/tools/ci/prepare-installer.mjs b/tools/ci/prepare-installer.mjs index b0e43d06..1ab0bb84 100644 --- a/tools/ci/prepare-installer.mjs +++ b/tools/ci/prepare-installer.mjs @@ -11,10 +11,17 @@ mkdirSync(directory, { recursive: true }); // Use the repository's distributable example, never a developer's local settings. const settings = JSON.parse(readFileSync(path.join(root, 'apps/desktop/local-settings.example.json'), 'utf8')); settings.updates = { ...settings.updates, enabled: false }; -const backendConfig = path.join(directory, 'application.properties'); -const desktopConfig = path.join(directory, 'local-settings.json'); -writeFileSync(backendConfig, '# Daily test installer: use the bundled backend defaults.\n'); -writeFileSync(desktopConfig, `${JSON.stringify(settings, null, 2)}\n`); +const base = JSON.parse(readFileSync(path.join(root, 'packaging.config.json'), 'utf8')); +const modes = {}; +for (const mode of ['test', 'production']) { + const licenseUrl = base.modes[mode].licenseUrl; + if (licenseUrl !== 'https://update.opentest.com') throw new Error(`未确认的 ${mode} 授权服务地址`); + const backendConfig = path.join(directory, `application-${mode}.properties`); + const desktopConfig = path.join(directory, `local-settings-${mode}.json`); + writeFileSync(backendConfig, `# Community installer: ${mode}\ncloud.license.url=${licenseUrl}\n`); + writeFileSync(desktopConfig, `${JSON.stringify(settings, null, 2)}\n`); + modes[mode] = { backendConfig, desktopConfig, licenseUrl }; +} writeFileSync(path.join(directory, 'runtime.env'), '# CI uses only explicit workflow environment values.\n'); // Optional prepared device plugins (/windows-amd64/plugins/devices/...), e.g. SonoDAQ in the community package. const nativePluginBinRoot = process.env.OPENTEST_CI_NATIVE_PLUGIN_BIN_ROOT @@ -23,10 +30,8 @@ if (nativePluginBinRoot && !(existsSync(nativePluginBinRoot) && statSync(nativeP throw new Error(`Missing device plugin directory: ${nativePluginBinRoot}`); writeFileSync(path.join(directory, 'packaging.json'), `${JSON.stringify({ schemaVersion: 1, - backendConfig, - desktopConfig, - // Mode overrides in the base config must not reintroduce local production settings. - modes: { production: { backendConfig, desktopConfig } }, + // Each mode has its own generated configuration; never read developer settings. + modes, ...(nativePluginBinRoot ? { nativePluginBinRoot } : {}), }, null, 2)}\n`); -console.info('Prepared daily test installer settings; automatic updates are disabled.'); +console.info('已分别生成测试和生产模式配置,均使用仓库确认的正式服务地址;自动更新已关闭。'); diff --git a/tools/ci/resolve-plugin-revision.mjs b/tools/ci/resolve-plugin-revision.mjs new file mode 100644 index 00000000..5f3028b8 --- /dev/null +++ b/tools/ci/resolve-plugin-revision.mjs @@ -0,0 +1,40 @@ +import { execFileSync } from 'node:child_process'; +import { appendFileSync } from 'node:fs'; +import path from 'node:path'; +import { pathToFileURL } from 'node:url'; + +const repository = 'https://github.com/crysound/OpenTest-Plugins.git'; +const shaPattern = /^[0-9a-f]{40}$/i; + +export function resolvePluginRevision({ eventName, refType, refName, requestedRef = '' }, { + lsRemote = refs => execFileSync('git', ['ls-remote', repository, ...refs], { + encoding: 'utf8', timeout: 60_000, windowsHide: true, + }), +} = {}) { + const explicit = eventName === 'workflow_dispatch' && requestedRef.trim(); + const ref = explicit || (refType === 'tag' ? refName : 'main'); + if (explicit && shaPattern.test(ref)) return { ref, sha: ref.toLowerCase() }; + if (typeof ref !== 'string' || !ref || /[\s\x00-\x1f\x7f~^:?*\[\\]/.test(ref) || ref.includes('..') || ref.includes('@{')) { + throw new Error('插件引用格式无效'); + } + const candidates = !explicit && refType === 'tag' ? [`refs/tags/${ref}`] + : ref.startsWith('refs/') ? [ref] : [`refs/heads/${ref}`, `refs/tags/${ref}`]; + const queries = candidates.flatMap(candidate => [candidate, `${candidate}^{}`]); + // 精确匹配返回的引用;附注标签优先使用剥离后的提交编号,网络失败直接向上传递。 + const refs = new Map(lsRemote(queries).trim().split(/\r?\n/).filter(Boolean).map(line => { + const [sha, name] = line.split(/\s+/); + return [name, sha]; + })); + for (const candidate of candidates) { + const sha = refs.get(`${candidate}^{}`) || refs.get(candidate); + if (shaPattern.test(sha || '')) return { ref, sha: sha.toLowerCase() }; + } + throw new Error(`无法解析插件引用 ${ref};标签构建必须先在插件仓库创建同名标签`); +} + +if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) { + const result = resolvePluginRevision({ eventName: process.env.GITHUB_EVENT_NAME, + refType: process.env.REF_TYPE, refName: process.env.REF_NAME, requestedRef: process.env.REQUESTED_REF }); + if (process.env.GITHUB_OUTPUT) appendFileSync(process.env.GITHUB_OUTPUT, `ref=${result.ref}\nsha=${result.sha}\n`); + console.info(`OpenTest-Plugins: ${result.ref} (${result.sha})`); +} diff --git a/tools/ci/verify-posix-installer.mjs b/tools/ci/verify-posix-installer.mjs index a0e9690c..51735f6f 100644 --- a/tools/ci/verify-posix-installer.mjs +++ b/tools/ci/verify-posix-installer.mjs @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; import { createHash } from 'node:crypto'; import { execFileSync } from 'node:child_process'; -import { accessSync, constants, existsSync, mkdtempSync, readFileSync, readdirSync, writeFileSync } from 'node:fs'; +import { accessSync, constants, existsSync, lstatSync, mkdtempSync, readFileSync, readdirSync, readlinkSync, rmSync, writeFileSync } from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import { pathToFileURL } from 'node:url'; @@ -9,15 +9,20 @@ import { repositoryRoot } from '../runtime.mjs'; import { resolvePackagingPlatform, assertPackagingPlatformReady } from '../packaging-platforms.mjs'; const sha256 = file => createHash('sha256').update(readFileSync(file)).digest('hex'); -const run = (command, args) => execFileSync(command, args, { encoding: 'utf8', timeout: 300_000, stdio: ['ignore', 'pipe', 'pipe'] }).trim(); -const files = root => readdirSync(root, { recursive: true, withFileTypes: true }).filter(e => e.isFile()) +const run = (command, args, options = {}) => execFileSync(command, args, { encoding: 'utf8', timeout: 300_000, stdio: ['pipe', 'pipe', 'pipe'], ...options }).trim(); +const files = root => readdirSync(root, { recursive: true, withFileTypes: true }).filter(e => e.isFile() || e.isSymbolicLink()) .map(e => path.relative(root, path.join(e.parentPath, e.name))).sort(); export function assertSameTree(source, installed) { const expected = files(source); assert.ok(expected.length, `暂存目录为空:${source}`); assert.deepEqual(files(installed), expected, `安装文件集合不匹配:${installed}`); - for (const file of expected) assert.equal(sha256(path.join(installed, file)), sha256(path.join(source, file)), `安装文件不匹配:${file}`); + for (const file of expected) { + const from = path.join(source, file), to = path.join(installed, file); + const link = lstatSync(from).isSymbolicLink(); + assert.equal(lstatSync(to).isSymbolicLink(), link, `安装文件类型不匹配:${file}`); + assert.equal(link ? readlinkSync(to) : sha256(to), link ? readlinkSync(from) : sha256(from), `安装文件不匹配:${file}`); + } return expected.length; } @@ -74,8 +79,9 @@ export function verifyInstaller({ platform = process.env.PACKAGE_PLATFORM, root installation = path.dirname(executable); assertBinary(executable, platform); } else { - run('hdiutil', ['attach', '-readonly', '-nobrowse', '-mountpoint', mount, installer]); + // Even a timed-out attach may have mounted the volume: attempt detach before removal. mounted = true; + run('hdiutil', ['attach', '-readonly', '-nobrowse', '-mountpoint', mount, installer], { input: 'Y\n' }); const app = path.join(temp, 'OpenTest.app'); run('ditto', [path.join(mount, 'OpenTest.app'), app]); run('codesign', ['--verify', '--deep', '--strict', app]); @@ -122,7 +128,10 @@ export function verifyInstaller({ platform = process.env.PACKAGE_PLATFORM, root primaryError = error; } finally { try { - if (mounted) run('hdiutil', ['detach', mount]); + if (mounted) { + run('hdiutil', ['detach', mount]); + mounted = false; + } if (installedPackage) { run('sudo', ['env', 'DEBIAN_FRONTEND=noninteractive', 'apt-get', 'remove', '-y', installedPackage]); if (installedExecutable) assert.ok(!existsSync(installedExecutable), '卸载后仍存在桌面程序'); @@ -130,6 +139,11 @@ export function verifyInstaller({ platform = process.env.PACKAGE_PLATFORM, root } catch (error) { cleanupError = error; } + // Never recursively remove a directory while its disk image is still mounted. + if (!mounted) { + try { rmSync(temp, { recursive: true, force: true }); } + catch (error) { cleanupError ||= error; } + } } if (primaryError) { if (cleanupError) console.error(`清理失败(保留原始错误):${cleanupError.message}`); diff --git a/tools/package.mjs b/tools/package.mjs index f4787e7c..9f3d2784 100644 --- a/tools/package.mjs +++ b/tools/package.mjs @@ -204,15 +204,33 @@ export function createBuilderConfig({ return builder; } -function prepareMacBuildResources(stage) { - const source = path.join(desktopRoot, 'assets') - const destination = path.join(stage, 'mac-build-resources') +export function licenseTextToRtf(text) { + // DMG text resources use legacy Mac encodings. ASCII RTF with Unicode escapes + // preserves every language, punctuation mark and paragraph without that loss. + const body = text.replace(/^\uFEFF/, '').replace(/\r\n?/g, '\n').split('').map(char => { + if (char === '\n') return '\\par\n'; + if (char === '\t') return '\\tab '; + if ('\\{}'.includes(char)) return `\\${char}`; + const code = char.charCodeAt(0); + return code >= 32 && code < 127 ? char : `\\u${code > 32767 ? code - 65536 : code}?`; + }).join(''); + return `{\\rtf1\\ansi\\ansicpg1252\\uc1 ${body}}`; +} + +export function prepareMacBuildResources(stage, source = path.join(desktopRoot, 'assets')) { + const destination = path.join(stage, 'mac-build-resources'); + const isTextLicense = name => /^(?:license|eula)(?:_[^.]+)?\.txt$/i.test(name); cpSync(source, destination, { recursive: true, dereference: true, - filter: sourcePath => !/[/\\](?:license|eula)(?:_[^/\\.]+)?\.(?:txt|rtf|html)$/i.test(sourcePath), - }) - return destination + filter: sourcePath => path.dirname(sourcePath) !== source || !isTextLicense(path.basename(sourcePath)), + }); + for (const name of readdirSync(source).filter(isTextLicense)) { + const target = path.join(destination, name.replace(/\.txt$/i, '.rtf')); + if (existsSync(path.join(source, path.basename(target)))) throw new Error(`许可协议存在重复格式:${name}`); + writeFileSync(target, licenseTextToRtf(readFileSync(path.join(source, name), 'utf8')), 'ascii'); + } + return destination; } export function resolveBundledPluginPackages(directory) { diff --git a/tools/publish-community-build.cjs b/tools/publish-community-build.cjs index d01e2c70..c79f823d 100644 --- a/tools/publish-community-build.cjs +++ b/tools/publish-community-build.cjs @@ -40,7 +40,7 @@ function posixInstallers({ version, root }) { } /** - * Publish the community installer verified by the successful Windows build job. + * Publish the three community installers after all installation checks succeed. * Daily builds (A.B.C-dev.[.N]) come only from main and create tag vVERSION on the built commit. * Release candidates and releases come only from the pushed tag vVERSION. */ @@ -66,6 +66,9 @@ module.exports = async function publishCommunityBuild({ throw new Error('Missing or invalid build artifact SHA-256'); } + if (typeof posixRoot !== 'string' || !path.isAbsolute(posixRoot)) throw new Error('Missing or invalid POSIX artifact root'); + if (typeof pluginsSha !== 'string' || !/^[0-9a-f]{40}$/i.test(pluginsSha)) throw new Error('Missing or invalid plugin commit SHA'); + const repo = context.repo; const { data: artifact } = await github.rest.actions.getArtifact({ ...repo, artifact_id: Number(artifactId) }); if (artifact.expired || artifact.name !== `opentest-community-windows-x64-${context.sha}` || @@ -96,7 +99,7 @@ module.exports = async function publishCommunityBuild({ const kind = { dev: 'Daily build', rc: 'Release candidate', release: 'Release' }[channel]; // Verify every platform before creating the one draft. Only this job writes Releases. const assets = [{ name: assetName, data: installer, digest }, - ...(posixRoot ? posixInstallers({ version, root: posixRoot }) : [])]; + ...posixInstallers({ version, root: posixRoot })]; const { data: draft } = await github.rest.repos.createRelease({ ...repo, tag_name: tag, @@ -107,24 +110,29 @@ module.exports = async function publishCommunityBuild({ make_latest: 'false', generate_release_notes: channel !== 'dev', body: [ - `${kind} of the OpenTest community package / OpenTest 社区包${{ dev: '日常构建', rc: '候选版本', release: '正式版本' }[channel]}。`, + `OpenTest 社区包${{ dev: '日常构建', rc: '候选版本', release: '正式版本' }[channel]}。`, + `${kind} of the OpenTest community package.`, '', + `源码提交:${context.sha}`, `Source commit: ${context.sha}`, + `成功构建:${context.serverUrl}/${repo.owner}/${repo.repo}/actions/runs/${context.runId}`, `Successful build: ${context.serverUrl}/${repo.owner}/${repo.repo}/actions/runs/${context.runId}`, - `OpenTest-Plugins commit: ${pluginsSha || 'not provided'}${pluginsRef ? ` (ref ${pluginsRef})` : ''}`, + `OpenTest-Plugins 插件提交:${pluginsSha}${pluginsRef ? `(引用 ${pluginsRef})` : ''}`, + `OpenTest-Plugins commit: ${pluginsSha}${pluginsRef ? ` (ref ${pluginsRef})` : ''}`, '', - '包含 OpenTest 和 crysound/OpenTest-Plugins 中的插件:公开业务插件和 SonoDAQ 设备插件。不含官网完整包中的其他插件。', - 'Includes OpenTest and the plugins from crysound/OpenTest-Plugins: the public business plugins and the SonoDAQ device plugin. Plugins from the website package are not included.', - '未签名的 Windows x64 安装包,使用测试授权服务,已关闭自动更新。', - 'Unsigned Windows x64 build using the test license service; automatic updates are disabled.', - ...(posixRoot ? [ - 'Linux x64 提供 DEB(Debian 软件包)安装包;macOS ARM64 提供 DMG(磁盘映像)安装包。两者使用生产算法及随包默认授权,已关闭自动更新。', - 'macOS 应用及插件仅作本机临时签名,未取得开发者签名或 Apple 公证;首次打开时请在“隐私与安全性”中点“仍要打开”。SonoDAQ 设备插件要求 macOS 26 或更高版本。', - '安装验证检查随包文件和 Java 运行时,不代表云端登录、付费算法授权或真实设备功能已通过验收。', - ] : []), - '已验证安装过程、程序架构和随包运行文件完整性;未验证云端登录、图表授权或硬件功能。', + '包含 OpenTest 和 crysound/OpenTest-Plugins 中的公开业务插件及 SonoDAQ 设备插件,不含官网完整包中的其他插件。', + 'Includes OpenTest and the public business plugins and SonoDAQ device plugin from crysound/OpenTest-Plugins; other plugins from the website package are not included.', + 'Windows x64 提供未签名的 EXE(可执行安装程序),保留 test 测试模式;Linux x64 提供 DEB(Debian 软件包),macOS ARM64 提供 DMG(磁盘映像),使用 production 正式授权模式。', + 'Windows x64 provides an unsigned EXE installer in test mode; Linux x64 provides a DEB package and macOS ARM64 provides a DMG disk image, both in production license mode.', + '三平台均连接正式许可证服务 https://update.opentest.com;当前没有独立测试服务器,test 模式不代表另有测试服务。自动更新均已关闭。', + 'All three platforms connect to the production license service https://update.opentest.com; there is no separate test server, and test mode does not imply one. Automatic updates are disabled.', + 'macOS 保留多语言许可协议;应用及插件仅作本机临时签名,未取得开发者签名或 Apple 公证。首次打开请在“隐私与安全性”中点“仍要打开”;SonoDAQ 设备插件要求 macOS 26 或更高版本。', + 'macOS retains the multilingual license agreement. The application and plugins have only ad hoc signatures, without developer signing or Apple notarization. On first launch, choose Open Anyway in Privacy & Security; the SonoDAQ device plugin requires macOS 26 or later.', + '已验证安装过程、程序架构、随包文件完整性和 Java 运行时;未验证云端登录、付费算法授权或真实硬件功能。', + 'The build verified installation, executable architecture, bundled file integrity and the Java runtime; cloud login, paid algorithm authorization and physical hardware functionality were not verified.', '', - 'SHA-256 文件校验值:', + 'SHA-256(文件校验值):', + 'SHA-256 checksums:', ...assets.map(asset => `${asset.name}: \`${asset.digest}\``), ].join('\n'), }); From c1f4f7c16ea109162fd5c402152ee0040c3d62f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=8D=9A=E6=9D=91=E5=AA=B7?= Date: Tue, 17 Nov 2026 07:33:50 +0800 Subject: [PATCH 07/13] ci: run packaging regressions and clarify current license modes --- .github/workflows/community-package.yml | 4 ++++ CONTEXT.md | 2 +- CONTRIBUTING.md | 4 ++-- CONTRIBUTING.zh-CN.md | 4 ++-- tools/ci/prepare-installer.mjs | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/community-package.yml b/.github/workflows/community-package.yml index 9bbc87c1..1d009e5d 100644 --- a/.github/workflows/community-package.yml +++ b/.github/workflows/community-package.yml @@ -59,6 +59,8 @@ jobs: with: node-version: 22 package-manager-cache: false + - name: Test version, plugin resolution and publication rules + run: node --test tools/__tests__/build-version.test.mjs tools/__tests__/resolve-plugin-revision.test.mjs tools/__tests__/publish-community-build.test.mjs - name: Resolve package version id: version env: @@ -145,6 +147,8 @@ jobs: pnpm --version - name: Install dependencies run: pnpm install --frozen-lockfile + - name: Test installer configuration and macOS license resources + run: node --test tools/__tests__/community-package.test.mjs tools/__tests__/mac-build-resources.test.mjs tools/__tests__/service-environment.test.mjs - name: Prepare Electron runtime run: ./tools/ci/prepare-electron.ps1 - name: Install the host plugin SDK into Maven diff --git a/CONTEXT.md b/CONTEXT.md index 07d4737b..3d4cdef0 100644 --- a/CONTEXT.md +++ b/CONTEXT.md @@ -115,7 +115,7 @@ _Avoid_:本地用户解锁、离线授权 **云许可证服务(Cloud License Service)**:签发、刷新和管理产品使用权益的云端服务;与建立用户身份的云账号登录服务分别配置。本机绑定的权益可通过该服务取得离线证书。 _Avoid_:登录服务器、Casdoor 服务 -**授权环境(License Environment)**:云许可证服务及与之匹配的后端原生授权材料共同构成的一套签发体系,分为测试与正式,两者的材料不可交叉组合;桌面算法模块的原生依赖按其自身交付约定管理。它与源码是否以开发方式运行、安装包是否签名分别描述。 +**授权环境(License Environment)**:云许可证服务及与之匹配的后端原生授权材料共同构成的一套签发体系。当前正式服务为 `https://update.opentest.com`,没有独立测试服务器;保留的 `test`、`production` 模式用于选择配置和配套材料,两种打包模式默认共用该地址,不能仅凭模式名称推断存在两套云服务。当前 Windows 两种模式均使用平台外层的生产材料;Linux、macOS 打包只支持 `production` 模式。自定义材料仍须与所选服务配套,桌面算法模块的原生依赖按其自身交付约定管理。配置及取材规则见[授权环境配置](docs/authorization-configuration_cn.md)。它与源码是否以开发方式运行、安装包是否签名分别描述。 _Avoid_:开发模式、打包模式 **默认原生许可证(Default Native License)**:随后端原生库交付、供原生授权模块初始化使用的预置许可证。它与用户从云端获得或自行导入的权益证书分别管理。 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 89ac7d32..cb7abbf6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -43,9 +43,9 @@ node --test tools/__tests__/docs-policy.test.mjs The `community-package` workflow builds three community installers: an EXE executable installer for Windows x64, a DEB Debian package for Linux x64, and a DMG disk image for macOS ARM64. They include OpenTest, the business plugins listed in `default-plugins.json` (currently `fft-tools`) from `crysound/OpenTest-Plugins`, and the SonoDAQ device plugin, but not the other plugins from the website package. Device plugins are bundled under `backend/native/plugins/devices` in the application resources. Windows retains `test` mode; Linux and macOS use `production` license mode, with separate generated configurations for each mode. All platforms connect to `https://update.opentest.com`; there is no separate test server. Automatic updates are disabled. Windows is unsigned; macOS retains its multilingual license agreement and has only ad hoc signatures, without developer signing or Apple notarization. On first launch, choose Open Anyway in Privacy & Security. The SonoDAQ device plugin requires macOS 26 or later. -Each push to `main` publishes a daily prerelease `A.B.C-dev.`; later builds on the same Beijing day add `.1`, `.2` and so on. Pushing `vA.B.C-rc.N` or `vA.B.C` publishes a release candidate or release. First create the same tag in `OpenTest-Plugins`: a missing tag fails the build instead of falling back to `main`. Daily builds and pull requests resolve the plugin `main` by default. Only an explicit `plugins_ref` input to `workflow_dispatch` overrides that choice; it accepts branch names, tag names, full references starting with `refs/`, and 40-character commit hashes. All three platforms check out the same resolved commit directly and verify it again, so a moving branch cannot change the build inputs. After every build and installation check succeeds, one publishing job uploads three installers and their SHA-256 checksum files before making the release public. +Each push to `main` publishes a daily prerelease `A.B.C-dev.`; later builds on the same Beijing day add `.2`, `.3` and so on. Pushing `vA.B.C-rc.N` or `vA.B.C` publishes a release candidate or release. First create the same tag in `OpenTest-Plugins`: a missing tag fails the build instead of falling back to `main`. Daily builds and pull requests resolve the plugin `main` by default. Only an explicit `plugins_ref` input to `workflow_dispatch` overrides that choice; it accepts branch names, tag names, full references starting with `refs/`, and 40-character commit hashes. All three platforms check out the same resolved commit directly and verify it again, so a moving branch cannot change the build inputs. After every build and installation check succeeds, one publishing job uploads three installers and their SHA-256 checksum files before making the release public. -Pull requests targeting `main` trigger all three builds and installation checks, without publishing, when they change the packaging scripts listed in the workflow, `tools/__tests__/**`, `tools/ci/**`, `default-plugins.json`, `packaging.config.json`, `apps/**`, `sdks/**`, `vendor/**`, `package.json`, or `pnpm-lock.yaml`. This intentionally retains the existing scope, including application, software development kit and runtime material changes. `package.json` keeps the plain `A.B.C` used for plugin compatibility; the full version is passed to `node tools/package.mjs --version`. The workflow uses `--edition community`. +Pull requests targeting `main` trigger all three builds and installation checks, without publishing, when they change the packaging scripts listed in the workflow, `tools/__tests__/**`, `tools/ci/**`, `default-plugins.json`, `packaging.config.json`, `apps/**`, `sdks/**`, `vendor/**`, `package.json`, or `pnpm-lock.yaml`. This workflow intentionally includes application, software development kit and runtime material changes in its three-platform validation scope. `package.json` keeps the plain `A.B.C` used for plugin compatibility; the full version is passed to `node tools/package.mjs --version`. The workflow uses `--edition community`. ## GitHub enforcement diff --git a/CONTRIBUTING.zh-CN.md b/CONTRIBUTING.zh-CN.md index bc86fa0a..d471d81f 100644 --- a/CONTRIBUTING.zh-CN.md +++ b/CONTRIBUTING.zh-CN.md @@ -43,9 +43,9 @@ node --test tools/__tests__/docs-policy.test.mjs `community-package` 工作流构建三平台社区安装包:Windows x64 的 EXE(可执行安装程序)、Linux x64 的 DEB(Debian 软件包)、macOS ARM64 的 DMG(磁盘映像)。社区包包含 OpenTest、`crysound/OpenTest-Plugins` 中由 `default-plugins.json` 列出的业务插件(当前为 `fft-tools`)和 SonoDAQ 设备插件,不含官网完整包的其他插件。设备插件放在应用资源目录的 `backend/native/plugins/devices` 下。Windows 保留 `test` 测试模式,Linux、macOS 使用 `production` 正式授权模式,各模式独立生成配置。三平台均连接 `https://update.opentest.com`,当前没有独立测试服务器;自动更新均关闭。Windows 未签名;macOS 保留多语言许可协议,仅作本机临时签名,未取得开发者签名或 Apple 公证,首次打开需在“隐私与安全性”中点“仍要打开”。SonoDAQ 设备插件要求 macOS 26 或更高版本。 -每次推送到 `main` 都发布一个日常预发布版本 `A.B.C-dev.<年月日>`,北京时间同一天的后续构建依次加 `.1`、`.2`。推送 `vA.B.C-rc.N` 或 `vA.B.C` 标签会发布候选版本或正式版本;必须先在 `OpenTest-Plugins` 创建同名标签,缺失时构建立即失败,不回落到 `main`。日常构建和拉取请求默认解析插件的 `main`;只有手动触发 `workflow_dispatch` 并显式填写 `plugins_ref` 才可覆盖,支持分支名、标签名、`refs/` 开头的完整引用和 40 位提交编号。三个平台直接检出解析得到的同一提交,并再次核对,防止构建期间分支前移。全部构建及安装验证通过后,单一发布任务先上传三个安装包及各自的 SHA-256 文件校验值,再公开版本。 +每次推送到 `main` 都发布一个日常预发布版本 `A.B.C-dev.<年月日>`,北京时间同一天的后续构建依次加 `.2`、`.3`。推送 `vA.B.C-rc.N` 或 `vA.B.C` 标签会发布候选版本或正式版本;必须先在 `OpenTest-Plugins` 创建同名标签,缺失时构建立即失败,不回落到 `main`。日常构建和拉取请求默认解析插件的 `main`;只有手动触发 `workflow_dispatch` 并显式填写 `plugins_ref` 才可覆盖,支持分支名、标签名、`refs/` 开头的完整引用和 40 位提交编号。三个平台直接检出解析得到的同一提交,并再次核对,防止构建期间分支前移。全部构建及安装验证通过后,单一发布任务先上传三个安装包及各自的 SHA-256 文件校验值,再公开版本。 -面向 `main` 的拉取请求若修改工作流中列出的打包脚本、`tools/__tests__/**`、`tools/ci/**`、`default-plugins.json`、`packaging.config.json`、`apps/**`、`sdks/**`、`vendor/**`、`package.json` 或 `pnpm-lock.yaml`,会触发三平台构建和安装验证,但不发布。这一范围有意包含应用、软件开发套件和运行材料变更,保持现有触发规则。`package.json` 保留用于插件兼容性的 `A.B.C`,完整版本号通过 `node tools/package.mjs --version` 传入;工作流使用 `--edition community`。 +面向 `main` 的拉取请求若修改工作流中列出的打包脚本、`tools/__tests__/**`、`tools/ci/**`、`default-plugins.json`、`packaging.config.json`、`apps/**`、`sdks/**`、`vendor/**`、`package.json` 或 `pnpm-lock.yaml`,会触发三平台构建和安装验证,但不发布。本工作流有意将应用、软件开发套件和运行材料变更纳入三平台验证范围。`package.json` 保留用于插件兼容性的 `A.B.C`,完整版本号通过 `node tools/package.mjs --version` 传入;工作流使用 `--edition community`。 ## GitHub 强制检查 diff --git a/tools/ci/prepare-installer.mjs b/tools/ci/prepare-installer.mjs index 1ab0bb84..51fa85e5 100644 --- a/tools/ci/prepare-installer.mjs +++ b/tools/ci/prepare-installer.mjs @@ -15,7 +15,7 @@ const base = JSON.parse(readFileSync(path.join(root, 'packaging.config.json'), ' const modes = {}; for (const mode of ['test', 'production']) { const licenseUrl = base.modes[mode].licenseUrl; - if (licenseUrl !== 'https://update.opentest.com') throw new Error(`未确认的 ${mode} 授权服务地址`); + if (typeof licenseUrl !== 'string' || !licenseUrl.trim()) throw new Error(`${mode} 模式缺少授权服务地址`); const backendConfig = path.join(directory, `application-${mode}.properties`); const desktopConfig = path.join(directory, `local-settings-${mode}.json`); writeFileSync(backendConfig, `# Community installer: ${mode}\ncloud.license.url=${licenseUrl}\n`); From 9f624fa7f5b6044710d7e53feebd75375353c014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=8D=9A=E6=9D=91=E5=AA=B7?= Date: Tue, 17 Nov 2026 08:17:01 +0800 Subject: [PATCH 08/13] ci: ensure POSIX delivery manifest before verification --- .github/workflows/community-package.yml | 2 + .../ensure-delivery-manifest.test.mjs | 34 ++++++++++++++++ tools/ci/ensure-delivery-manifest.mjs | 40 +++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 tools/__tests__/ensure-delivery-manifest.test.mjs create mode 100644 tools/ci/ensure-delivery-manifest.mjs diff --git a/.github/workflows/community-package.yml b/.github/workflows/community-package.yml index 1d009e5d..2b0c81eb 100644 --- a/.github/workflows/community-package.yml +++ b/.github/workflows/community-package.yml @@ -327,6 +327,8 @@ jobs: run: | node tools/package.mjs --platform "$PACKAGE_PLATFORM" --mode production --kind installer --edition community \ --version "$VERSION" --plugins-dir "$PLUGIN_PACKAGES" --config .runtime/ci-installer/packaging.json + - name: Ensure delivery manifest + run: node tools/ci/ensure-delivery-manifest.mjs - name: Verify silent install run: node tools/ci/verify-posix-installer.mjs - name: Upload installer diff --git a/tools/__tests__/ensure-delivery-manifest.test.mjs b/tools/__tests__/ensure-delivery-manifest.test.mjs new file mode 100644 index 00000000..83574fa4 --- /dev/null +++ b/tools/__tests__/ensure-delivery-manifest.test.mjs @@ -0,0 +1,34 @@ +import assert from 'node:assert/strict'; +import { createHash } from 'node:crypto'; +import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; +import test from 'node:test'; +import { ensureDeliveryManifest } from '../ci/ensure-delivery-manifest.mjs'; + +test('为真实单一安装包补齐交付清单并校验名称和摘要', t => { + const root = mkdtempSync(path.join(os.tmpdir(), 'opentest-delivery-')); + t.after(() => rmSync(root, { recursive: true, force: true })); + const directory = path.join(root, 'dist/releases/mac-arm64/production/unsigned/installer'); + mkdirSync(directory, { recursive: true }); + const name = 'OpenTest-Community-2.5.0-dev.20261117-production-installer-mac-arm64.dmg'; + const data = Buffer.from('dmg fixture'); + writeFileSync(path.join(directory, name), data); + const result = ensureDeliveryManifest({ root, platform: 'mac', version: '2.5.0-dev.20261117' }); + assert.equal(result.artifacts[0].sha256, createHash('sha256').update(data).digest('hex')); + const manifest = JSON.parse(readFileSync(path.join(root, 'dist/releases/mac-arm64/production/unsigned/delivery.json'), 'utf8')); + assert.deepEqual(manifest, result); + assert.deepEqual(ensureDeliveryManifest({ root, platform: 'mac', version: '2.5.0-dev.20261117' }), result); +}); + +test('清单步骤拒绝缺失、重复、错误命名或已篡改清单', t => { + const root = mkdtempSync(path.join(os.tmpdir(), 'opentest-delivery-invalid-')); + t.after(() => rmSync(root, { recursive: true, force: true })); + const directory = path.join(root, 'dist/releases/linux-x64/production/unsigned/installer'); + mkdirSync(directory, { recursive: true }); + const name = 'OpenTest-Community-2.5.0-production-installer-linux-x64.deb'; + writeFileSync(path.join(directory, name), 'deb'); + assert.throws(() => ensureDeliveryManifest({ root, platform: 'linux', version: '2.5.0-dev.20261117' }), /名称/); + writeFileSync(path.join(directory, 'OpenTest-Community-2.5.0-dev.20261117-production-installer-linux-x64.deb'), 'deb'); + assert.throws(() => ensureDeliveryManifest({ root, platform: 'linux', version: '2.5.0-dev.20261117' }), /一个/); +}); diff --git a/tools/ci/ensure-delivery-manifest.mjs b/tools/ci/ensure-delivery-manifest.mjs new file mode 100644 index 00000000..b9edfd0f --- /dev/null +++ b/tools/ci/ensure-delivery-manifest.mjs @@ -0,0 +1,40 @@ +import { createHash } from 'node:crypto'; +import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'; +import path from 'node:path'; +import { pathToFileURL } from 'node:url'; +import { repositoryRoot } from '../runtime.mjs'; +import { resolvePackagingPlatform } from '../packaging-platforms.mjs'; + +export function ensureDeliveryManifest({ root = repositoryRoot, platform, version, mode = 'production', edition = 'community' } = {}) { + const target = resolvePackagingPlatform(platform); + const output = path.join(root, 'dist/releases', `${target.platform}-${target.arch}`, mode, 'unsigned'); + const installerDir = path.join(output, 'installer'); + const extension = target.installerExtension; + const installers = existsSync(installerDir) + ? readdirSync(installerDir).filter(name => name.endsWith(extension)).map(name => path.join(installerDir, name)) + : []; + if (installers.length !== 1) throw new Error(`应有一个 ${platform} 安装包,实际找到 ${installers.length}`); + const installer = installers[0]; + const name = path.basename(installer); + const expected = `OpenTest-Community-${version}-${mode}-installer-${platform}-${target.arch}${extension}`; + if (name !== expected) throw new Error(`安装包名称不匹配:${name};应为 ${expected}`); + const sha256 = createHash('sha256').update(readFileSync(installer)).digest('hex'); + const manifest = { + version, productVersion: version.replace(/-(?:dev|rc)\..*$/, ''), edition, mode, + platform, arch: target.arch, signed: false, notarized: false, + artifacts: [{ file: `installer/${name}`, sha256 }], + }; + const manifestPath = path.join(output, 'delivery.json'); + if (existsSync(manifestPath)) { + const existing = JSON.parse(readFileSync(manifestPath, 'utf8')); + if (JSON.stringify(existing) !== JSON.stringify(manifest)) throw new Error(`已有 delivery.json 与实际安装包不一致:${manifestPath}`); + } else { + writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`); + } + return manifest; +} + +if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) { + ensureDeliveryManifest({ platform: process.env.PACKAGE_PLATFORM, version: process.env.VERSION }); + console.info('安装包交付清单已核对'); +} From 77f7c617fb4c18d6d26e071d4778e18010c5f89e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=8D=9A=E6=9D=91=E5=AA=B7?= Date: Tue, 17 Nov 2026 08:39:46 +0800 Subject: [PATCH 09/13] ci: accept package delivery manifest metadata --- .../ensure-delivery-manifest.test.mjs | 20 +++++++++++++++++++ tools/ci/ensure-delivery-manifest.mjs | 11 +++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/tools/__tests__/ensure-delivery-manifest.test.mjs b/tools/__tests__/ensure-delivery-manifest.test.mjs index 83574fa4..f1eae0f1 100644 --- a/tools/__tests__/ensure-delivery-manifest.test.mjs +++ b/tools/__tests__/ensure-delivery-manifest.test.mjs @@ -21,6 +21,26 @@ test('为真实单一安装包补齐交付清单并校验名称和摘要', t => assert.deepEqual(ensureDeliveryManifest({ root, platform: 'mac', version: '2.5.0-dev.20261117' }), result); }); +test('保留打包器已有的附加清单字段并只校验交付核心字段', t => { + const root = mkdtempSync(path.join(os.tmpdir(), 'opentest-delivery-existing-')); + t.after(() => rmSync(root, { recursive: true, force: true })); + const directory = path.join(root, 'dist/releases/linux-x64/production/unsigned/installer'); + mkdirSync(directory, { recursive: true }); + const name = 'OpenTest-Community-2.5.0-dev.20261117-production-installer-linux-x64.deb'; + const data = Buffer.from('deb fixture'); + writeFileSync(path.join(directory, name), data); + const digest = createHash('sha256').update(data).digest('hex'); + const existing = { + version: '2.5.0-dev.20261117', productVersion: '2.5.0', edition: 'community', mode: 'production', + platform: 'linux', arch: 'x64', signed: false, notarized: false, + bundledPlugins: [{ pluginId: 'com.opentest.fft-tools', version: '1.4.0' }], automaticUpdate: false, + artifacts: [{ file: `installer/${name}`, sha256: digest }], + }; + const output = path.join(root, 'dist/releases/linux-x64/production/unsigned'); + writeFileSync(path.join(output, 'delivery.json'), JSON.stringify(existing)); + assert.deepEqual(ensureDeliveryManifest({ root, platform: 'linux', version: '2.5.0-dev.20261117' }), existing); +}); + test('清单步骤拒绝缺失、重复、错误命名或已篡改清单', t => { const root = mkdtempSync(path.join(os.tmpdir(), 'opentest-delivery-invalid-')); t.after(() => rmSync(root, { recursive: true, force: true })); diff --git a/tools/ci/ensure-delivery-manifest.mjs b/tools/ci/ensure-delivery-manifest.mjs index b9edfd0f..166a0ba2 100644 --- a/tools/ci/ensure-delivery-manifest.mjs +++ b/tools/ci/ensure-delivery-manifest.mjs @@ -22,12 +22,21 @@ export function ensureDeliveryManifest({ root = repositoryRoot, platform, versio const manifest = { version, productVersion: version.replace(/-(?:dev|rc)\..*$/, ''), edition, mode, platform, arch: target.arch, signed: false, notarized: false, + bundledPlugins: [], automaticUpdate: platform !== 'linux', artifacts: [{ file: `installer/${name}`, sha256 }], }; const manifestPath = path.join(output, 'delivery.json'); if (existsSync(manifestPath)) { const existing = JSON.parse(readFileSync(manifestPath, 'utf8')); - if (JSON.stringify(existing) !== JSON.stringify(manifest)) throw new Error(`已有 delivery.json 与实际安装包不一致:${manifestPath}`); + const artifact = existing?.artifacts?.length === 1 ? existing.artifacts[0] : null; + const valid = existing.version === manifest.version && + existing.productVersion === manifest.productVersion && + existing.edition === manifest.edition && existing.mode === manifest.mode && + existing.platform === manifest.platform && existing.arch === manifest.arch && + existing.signed === manifest.signed && existing.notarized === manifest.notarized && + artifact?.file === manifest.artifacts[0].file && artifact.sha256 === sha256; + if (!valid) throw new Error(`已有 delivery.json 与实际安装包不一致:${manifestPath}`); + return existing; } else { writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`); } From a08fcdc9518188dcd02d66fa0c1d32fbc64fd709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=8D=9A=E6=9D=91=E5=AA=B7?= Date: Tue, 17 Nov 2026 14:06:30 +0800 Subject: [PATCH 10/13] ci: neutralize plugin revision output names --- .github/workflows/community-package.yml | 42 +++++++------------ CONTEXT.md | 2 +- CONTRIBUTING.md | 2 +- CONTRIBUTING.zh-CN.md | 2 +- tools/__tests__/community-package.test.mjs | 19 +++++++-- .../publish-community-build.test.mjs | 8 ++-- .../resolve-plugin-revision.test.mjs | 38 +++++++---------- tools/ci/resolve-plugin-revision.mjs | 14 +++---- tools/publish-community-build.cjs | 10 ++--- 9 files changed, 62 insertions(+), 75 deletions(-) diff --git a/.github/workflows/community-package.yml b/.github/workflows/community-package.yml index 2b0c81eb..d2777a59 100644 --- a/.github/workflows/community-package.yml +++ b/.github/workflows/community-package.yml @@ -25,19 +25,10 @@ on: - tools/package-java.mjs - tools/macos-signing.mjs - tools/__tests__/** - - apps/** - - sdks/** - - vendor/** - - package.json - - pnpm-lock.yaml - tools/publish-community-build.cjs - tools/ci/** - workflow_dispatch: - inputs: - plugins_ref: - description: OpenTest-Plugins branch, tag, full ref or commit SHA (tag builds require the same tag) - required: false - default: '' + # Manual runs use the same plugin revision rules as push runs; they cannot select arbitrary plugin code. + workflow_dispatch: {} permissions: contents: read concurrency: @@ -49,8 +40,8 @@ jobs: timeout-minutes: 10 outputs: version: ${{ steps.version.outputs.version }} - plugins-ref: ${{ steps.plugins.outputs.ref }} - plugins-sha: ${{ steps.plugins.outputs.sha }} + plugins-source: ${{ steps.plugins.outputs.source }} + plugins-revision: ${{ steps.plugins.outputs.revision }} steps: - uses: actions/checkout@v7 with: @@ -86,7 +77,6 @@ jobs: env: REF_TYPE: ${{ github.ref_type }} REF_NAME: ${{ github.ref_name }} - REQUESTED_REF: ${{ inputs.plugins_ref }} run: node tools/ci/resolve-plugin-revision.mjs build: needs: version @@ -116,22 +106,22 @@ jobs: uses: actions/checkout@v7 with: repository: crysound/OpenTest-Plugins - ref: ${{ needs.version.outputs.plugins-sha }} + ref: ${{ needs.version.outputs.plugins-revision }} path: .runtime/opentest-plugins persist-credentials: false - name: Verify public plugin revision env: - EXPECTED_PLUGINS_SHA: ${{ needs.version.outputs.plugins-sha }} + EXPECTED_PLUGINS_REVISION: ${{ needs.version.outputs.plugins-revision }} run: | $actual = git -C $env:PLUGINS_ROOT rev-parse HEAD if ($LASTEXITCODE -ne 0) { throw 'Could not read the checked-out plugin revision.' } $actual = $actual.Trim() - if ($actual -ne $env:EXPECTED_PLUGINS_SHA) { throw "OpenTest-Plugins revision mismatch: $actual" } + if ($actual -ne $env:EXPECTED_PLUGINS_REVISION) { throw "OpenTest-Plugins revision mismatch: $actual" } - uses: actions/setup-node@v7 with: node-version: 22 package-manager-cache: false - # Do not persist Maven caches: manually selected plugin code must not poison later release builds. + # Do not persist Maven caches between runs. - uses: actions/setup-java@v6 with: distribution: zulu @@ -273,20 +263,20 @@ jobs: uses: actions/checkout@v7 with: repository: crysound/OpenTest-Plugins - ref: ${{ needs.version.outputs.plugins-sha }} + ref: ${{ needs.version.outputs.plugins-revision }} path: .runtime/opentest-plugins persist-credentials: false - name: Verify public plugin revision env: - EXPECTED_PLUGINS_SHA: ${{ needs.version.outputs.plugins-sha }} + EXPECTED_PLUGINS_REVISION: ${{ needs.version.outputs.plugins-revision }} run: | actual=$(git -C .runtime/opentest-plugins rev-parse HEAD) - test "$actual" = "$EXPECTED_PLUGINS_SHA" + test "$actual" = "$EXPECTED_PLUGINS_REVISION" - uses: actions/setup-node@v7 with: node-version: 22 package-manager-cache: false - # Do not persist Maven caches: manually selected plugin code must not poison later release builds. + # Do not persist Maven caches between runs. - uses: actions/setup-java@v6 with: distribution: zulu @@ -372,8 +362,8 @@ jobs: uses: actions/github-script@v9 env: VERSION: ${{ needs.version.outputs.version }} - PLUGINS_REF: ${{ needs.version.outputs.plugins-ref }} - PLUGINS_SHA: ${{ needs.version.outputs.plugins-sha }} + PLUGINS_SOURCE: ${{ needs.version.outputs.plugins-source }} + PLUGINS_REVISION: ${{ needs.version.outputs.plugins-revision }} ARTIFACT_ID: ${{ needs.build.outputs.artifact-id }} ARTIFACT_DIGEST: ${{ needs.build.outputs.artifact-digest }} INSTALLER_NAME: ${{ needs.build.outputs.installer-name }} @@ -390,7 +380,7 @@ jobs: installerPath: path.join(process.env.GITHUB_WORKSPACE, 'release/windows/installer', process.env.INSTALLER_NAME), installerDigest: process.env.INSTALLER_SHA256, posixRoot: path.join(process.env.GITHUB_WORKSPACE, 'release'), - pluginsRef: process.env.PLUGINS_REF, - pluginsSha: process.env.PLUGINS_SHA, + pluginsSource: process.env.PLUGINS_SOURCE, + pluginsRevision: process.env.PLUGINS_REVISION, }) core.notice(`Published ${release.html_url}`) diff --git a/CONTEXT.md b/CONTEXT.md index 3d4cdef0..07d4737b 100644 --- a/CONTEXT.md +++ b/CONTEXT.md @@ -115,7 +115,7 @@ _Avoid_:本地用户解锁、离线授权 **云许可证服务(Cloud License Service)**:签发、刷新和管理产品使用权益的云端服务;与建立用户身份的云账号登录服务分别配置。本机绑定的权益可通过该服务取得离线证书。 _Avoid_:登录服务器、Casdoor 服务 -**授权环境(License Environment)**:云许可证服务及与之匹配的后端原生授权材料共同构成的一套签发体系。当前正式服务为 `https://update.opentest.com`,没有独立测试服务器;保留的 `test`、`production` 模式用于选择配置和配套材料,两种打包模式默认共用该地址,不能仅凭模式名称推断存在两套云服务。当前 Windows 两种模式均使用平台外层的生产材料;Linux、macOS 打包只支持 `production` 模式。自定义材料仍须与所选服务配套,桌面算法模块的原生依赖按其自身交付约定管理。配置及取材规则见[授权环境配置](docs/authorization-configuration_cn.md)。它与源码是否以开发方式运行、安装包是否签名分别描述。 +**授权环境(License Environment)**:云许可证服务及与之匹配的后端原生授权材料共同构成的一套签发体系,分为测试与正式,两者的材料不可交叉组合;桌面算法模块的原生依赖按其自身交付约定管理。它与源码是否以开发方式运行、安装包是否签名分别描述。 _Avoid_:开发模式、打包模式 **默认原生许可证(Default Native License)**:随后端原生库交付、供原生授权模块初始化使用的预置许可证。它与用户从云端获得或自行导入的权益证书分别管理。 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cb7abbf6..7816535d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -43,7 +43,7 @@ node --test tools/__tests__/docs-policy.test.mjs The `community-package` workflow builds three community installers: an EXE executable installer for Windows x64, a DEB Debian package for Linux x64, and a DMG disk image for macOS ARM64. They include OpenTest, the business plugins listed in `default-plugins.json` (currently `fft-tools`) from `crysound/OpenTest-Plugins`, and the SonoDAQ device plugin, but not the other plugins from the website package. Device plugins are bundled under `backend/native/plugins/devices` in the application resources. Windows retains `test` mode; Linux and macOS use `production` license mode, with separate generated configurations for each mode. All platforms connect to `https://update.opentest.com`; there is no separate test server. Automatic updates are disabled. Windows is unsigned; macOS retains its multilingual license agreement and has only ad hoc signatures, without developer signing or Apple notarization. On first launch, choose Open Anyway in Privacy & Security. The SonoDAQ device plugin requires macOS 26 or later. -Each push to `main` publishes a daily prerelease `A.B.C-dev.`; later builds on the same Beijing day add `.2`, `.3` and so on. Pushing `vA.B.C-rc.N` or `vA.B.C` publishes a release candidate or release. First create the same tag in `OpenTest-Plugins`: a missing tag fails the build instead of falling back to `main`. Daily builds and pull requests resolve the plugin `main` by default. Only an explicit `plugins_ref` input to `workflow_dispatch` overrides that choice; it accepts branch names, tag names, full references starting with `refs/`, and 40-character commit hashes. All three platforms check out the same resolved commit directly and verify it again, so a moving branch cannot change the build inputs. After every build and installation check succeeds, one publishing job uploads three installers and their SHA-256 checksum files before making the release public. +Each push to `main` publishes a daily prerelease `A.B.C-dev.`; later builds on the same Beijing day add `.2`, `.3` and so on. Pushing `vA.B.C-rc.N` or `vA.B.C` publishes a release candidate or release. First create the same tag in `OpenTest-Plugins`: a missing tag fails the build instead of falling back to `main`. Daily builds, pull requests, and manual runs use the plugin repository's `main`; manual runs cannot select an arbitrary plugin revision. Tag runs require the matching plugin tag. All three platforms check out the same resolved commit directly and verify it again, so a moving branch cannot change the build inputs. After every build and installation check succeeds, one publishing job uploads three installers and their SHA-256 checksum files before making the release public. Pull requests targeting `main` trigger all three builds and installation checks, without publishing, when they change the packaging scripts listed in the workflow, `tools/__tests__/**`, `tools/ci/**`, `default-plugins.json`, `packaging.config.json`, `apps/**`, `sdks/**`, `vendor/**`, `package.json`, or `pnpm-lock.yaml`. This workflow intentionally includes application, software development kit and runtime material changes in its three-platform validation scope. `package.json` keeps the plain `A.B.C` used for plugin compatibility; the full version is passed to `node tools/package.mjs --version`. The workflow uses `--edition community`. diff --git a/CONTRIBUTING.zh-CN.md b/CONTRIBUTING.zh-CN.md index d471d81f..63136c99 100644 --- a/CONTRIBUTING.zh-CN.md +++ b/CONTRIBUTING.zh-CN.md @@ -43,7 +43,7 @@ node --test tools/__tests__/docs-policy.test.mjs `community-package` 工作流构建三平台社区安装包:Windows x64 的 EXE(可执行安装程序)、Linux x64 的 DEB(Debian 软件包)、macOS ARM64 的 DMG(磁盘映像)。社区包包含 OpenTest、`crysound/OpenTest-Plugins` 中由 `default-plugins.json` 列出的业务插件(当前为 `fft-tools`)和 SonoDAQ 设备插件,不含官网完整包的其他插件。设备插件放在应用资源目录的 `backend/native/plugins/devices` 下。Windows 保留 `test` 测试模式,Linux、macOS 使用 `production` 正式授权模式,各模式独立生成配置。三平台均连接 `https://update.opentest.com`,当前没有独立测试服务器;自动更新均关闭。Windows 未签名;macOS 保留多语言许可协议,仅作本机临时签名,未取得开发者签名或 Apple 公证,首次打开需在“隐私与安全性”中点“仍要打开”。SonoDAQ 设备插件要求 macOS 26 或更高版本。 -每次推送到 `main` 都发布一个日常预发布版本 `A.B.C-dev.<年月日>`,北京时间同一天的后续构建依次加 `.2`、`.3`。推送 `vA.B.C-rc.N` 或 `vA.B.C` 标签会发布候选版本或正式版本;必须先在 `OpenTest-Plugins` 创建同名标签,缺失时构建立即失败,不回落到 `main`。日常构建和拉取请求默认解析插件的 `main`;只有手动触发 `workflow_dispatch` 并显式填写 `plugins_ref` 才可覆盖,支持分支名、标签名、`refs/` 开头的完整引用和 40 位提交编号。三个平台直接检出解析得到的同一提交,并再次核对,防止构建期间分支前移。全部构建及安装验证通过后,单一发布任务先上传三个安装包及各自的 SHA-256 文件校验值,再公开版本。 +每次推送到 `main` 都发布一个日常预发布版本 `A.B.C-dev.<年月日>`,北京时间同一天的后续构建依次加 `.2`、`.3`。推送 `vA.B.C-rc.N` 或 `vA.B.C` 标签会发布候选版本或正式版本;必须先在 `OpenTest-Plugins` 创建同名标签,缺失时构建立即失败,不回落到 `main`。日常构建、拉取请求和手动运行都使用插件仓库的 `main`;手动运行不能指定任意插件版本,标签运行必须使用同名插件标签。三个平台直接检出解析得到的同一提交,并再次核对,防止构建期间分支前移。全部构建及安装验证通过后,单一发布任务先上传三个安装包及各自的 SHA-256 文件校验值,再公开版本。 面向 `main` 的拉取请求若修改工作流中列出的打包脚本、`tools/__tests__/**`、`tools/ci/**`、`default-plugins.json`、`packaging.config.json`、`apps/**`、`sdks/**`、`vendor/**`、`package.json` 或 `pnpm-lock.yaml`,会触发三平台构建和安装验证,但不发布。本工作流有意将应用、软件开发套件和运行材料变更纳入三平台验证范围。`package.json` 保留用于插件兼容性的 `A.B.C`,完整版本号通过 `node tools/package.mjs --version` 传入;工作流使用 `--edition community`。 diff --git a/tools/__tests__/community-package.test.mjs b/tools/__tests__/community-package.test.mjs index abdb8fc8..d0a8ad0f 100644 --- a/tools/__tests__/community-package.test.mjs +++ b/tools/__tests__/community-package.test.mjs @@ -20,9 +20,20 @@ test('工作流为三平台共用版本,只有推送且全部构建成功才 assert.ok(workflow.on.push.tags.includes('!v*-dev.*')); assert.ok(workflow.on.pull_request); assert.ok(workflow.on.workflow_dispatch); + assert.deepEqual(workflow.on.workflow_dispatch, {}); + assert.equal(JSON.stringify(workflow).includes('plugins_ref'), false); + assert.equal(JSON.stringify(workflow).includes('REQUESTED_REF'), false); + assert.equal(JSON.stringify(workflow).includes('plugins-sha'), false); + assert.equal(JSON.stringify(workflow).includes('plugins-ref'), false); + assert.deepEqual(workflow.on.pull_request.paths, [ + '.github/workflows/community-package.yml', 'default-plugins.json', 'packaging.config.json', + 'tools/build-version.mjs', 'tools/default-plugins.mjs', 'tools/package.mjs', 'tools/packaging.mjs', + 'tools/packaging-platforms.mjs', 'tools/package-posix-native.mjs', 'tools/package-java.mjs', + 'tools/macos-signing.mjs', 'tools/__tests__/**', 'tools/publish-community-build.cjs', 'tools/ci/**', + ]); assert.equal(workflow.jobs.build.needs, 'version'); - assert.equal(workflow.jobs.version.outputs['plugins-ref'], '${{ steps.plugins.outputs.ref }}'); - assert.equal(workflow.jobs.version.outputs['plugins-sha'], '${{ steps.plugins.outputs.sha }}'); + assert.equal(workflow.jobs.version.outputs['plugins-source'], '${{ steps.plugins.outputs.source }}'); + assert.equal(workflow.jobs.version.outputs['plugins-revision'], '${{ steps.plugins.outputs.revision }}'); assert.equal(workflow.jobs['build-posix'].needs, 'version'); assert.deepEqual(workflow.jobs.publish.needs, ['version', 'build', 'build-posix']); assert.equal(workflow.jobs.publish.if, "github.event_name == 'push'"); @@ -42,12 +53,12 @@ test('工作流为三平台共用版本,只有推送且全部构建成功才 assert.ok(workflow.jobs['build-posix'].steps.some(s => s.name === 'Verify public plugin revision')); for (const job of [workflow.jobs.build, workflow.jobs['build-posix']]) { const checkout = job.steps.find(s => s.with?.repository === 'crysound/OpenTest-Plugins'); - assert.equal(checkout.with.ref, '${{ needs.version.outputs.plugins-sha }}'); + assert.equal(checkout.with.ref, '${{ needs.version.outputs.plugins-revision }}'); assert.equal(checkout.with.path, '.runtime/opentest-plugins'); } assert.equal(workflow.jobs.build.env.PLUGINS_ROOT, '${{ github.workspace }}/.runtime/opentest-plugins'); const windowsVerify = windows.find(s => s.name === 'Verify public plugin revision').run; - assert.match(windowsVerify, /\$env:EXPECTED_PLUGINS_SHA/); + assert.match(windowsVerify, /\$env:EXPECTED_PLUGINS_REVISION/); assert.match(windowsVerify, /\$LASTEXITCODE -ne 0/); const posix = workflow.jobs['build-posix'].steps; const verify = posix.findIndex(s => s.run?.includes('verify-posix-installer.mjs')); diff --git a/tools/__tests__/publish-community-build.test.mjs b/tools/__tests__/publish-community-build.test.mjs index 46416ce0..f28858a7 100644 --- a/tools/__tests__/publish-community-build.test.mjs +++ b/tools/__tests__/publish-community-build.test.mjs @@ -37,7 +37,7 @@ function windowsFixture(version = '2.5.0-dev.20261114.2', ref = 'refs/heads/main artifact, calls, installer, options: { github, context, version, artifactId: '456', artifactDigest, installerPath, installerDigest: createHash('sha256').update(installer).digest('hex'), - pluginsRef: 'main', pluginsSha: 'b'.repeat(40) }, + pluginsSource: 'main', pluginsRevision: 'b'.repeat(40) }, }; } @@ -133,9 +133,9 @@ test('rejects invalid inputs without creating a release', async () => { o => { o.artifactId = ''; }, o => { delete o.posixRoot; }, o => { o.posixRoot = 'relative'; }, - o => { delete o.pluginsSha; }, - o => { o.pluginsSha = 'b'.repeat(39); }, - o => { o.pluginsSha = 'g'.repeat(40); }, + o => { delete o.pluginsRevision; }, + o => { o.pluginsRevision = 'b'.repeat(39); }, + o => { o.pluginsRevision = 'g'.repeat(40); }, o => { o.artifactDigest = ''; }, o => { o.installerDigest = ''; }, o => { o.installerPath = 'app.zip'; }, diff --git a/tools/__tests__/resolve-plugin-revision.test.mjs b/tools/__tests__/resolve-plugin-revision.test.mjs index a5e1df46..d485f948 100644 --- a/tools/__tests__/resolve-plugin-revision.test.mjs +++ b/tools/__tests__/resolve-plugin-revision.test.mjs @@ -10,17 +10,17 @@ function lookup(entries, queries = []) { } }; } -test('主线和拉取请求锁定插件 main,不接受非手动事件的覆盖输入', () => { - for (const eventName of ['push', 'pull_request']) { - assert.deepEqual(resolvePluginRevision({ eventName, refType: 'branch', requestedRef: 'other' }, - lookup({ 'refs/heads/main': commit, 'refs/heads/other': tagObject })), { ref: 'main', sha: commit }); +test('主线、拉取请求和手动运行都锁定插件 main', () => { + for (const refType of ['branch', undefined]) { + assert.deepEqual(resolvePluginRevision({ refType, refName: 'feature' }, + lookup({ 'refs/heads/main': commit, 'refs/heads/feature': tagObject })), { ref: 'main', sha: commit }); } }); for (const refName of ['v2.5.0', 'v2.5.0-rc.1']) { - test(`${refName} 缺少同名插件标签时失败,不借用同名分支或 main`, () => { + test(`${refName} 缺少同名插件标签时失败,不借用分支或 main`, () => { const queries = []; - assert.throws(() => resolvePluginRevision({ eventName: 'push', refType: 'tag', refName, requestedRef: 'main' }, + assert.throws(() => resolvePluginRevision({ refType: 'tag', refName }, lookup({ 'refs/heads/main': commit, [`refs/heads/${refName}`]: commit }, queries)), /同名标签/); assert.ok(queries.every(ref => ref.startsWith(`refs/tags/${refName}`))); }); @@ -28,29 +28,19 @@ for (const refName of ['v2.5.0', 'v2.5.0-rc.1']) { for (const annotated of [false, true]) { const refs = { [`refs/tags/${refName}`]: annotated ? tagObject : commit }; if (annotated) refs[`refs/tags/${refName}^{}`] = commit; - assert.equal(resolvePluginRevision({ eventName: 'push', refType: 'tag', refName }, lookup(refs)).sha, commit); + assert.equal(resolvePluginRevision({ refType: 'tag', refName }, lookup(refs)).sha, commit); } }); } -test('只有手动输入能够覆盖标签,支持分支、标签、完整引用和 40 位提交', () => { - const refs = { 'refs/heads/feature': commit, 'refs/tags/plugin-release': tagObject, - 'refs/tags/plugin-release^{}': commit, 'refs/pull/12/head': commit }; - for (const requestedRef of ['feature', 'plugin-release', 'refs/heads/feature', 'refs/tags/plugin-release', 'refs/pull/12/head']) { - assert.deepEqual(resolvePluginRevision({ eventName: 'workflow_dispatch', refType: 'tag', refName: 'v2.5.0', requestedRef }, lookup(refs)), - { ref: requestedRef, sha: commit }); - } - assert.deepEqual(resolvePluginRevision({ eventName: 'workflow_dispatch', requestedRef: commit.toUpperCase() }, { - lsRemote() { throw new Error('提交编号应直接交给 checkout 验证是否存在'); }, - }), { ref: commit.toUpperCase(), sha: commit }); +test('手动运行不能指定任意插件引用,标签仍遵守同名标签规则', () => { + assert.deepEqual(resolvePluginRevision({ refType: 'branch' }, lookup({ 'refs/heads/main': commit, + 'refs/heads/feature': tagObject })), { ref: 'main', sha: commit }); + assert.throws(() => resolvePluginRevision({ refType: 'tag', refName: 'v2.5.0' }, lookup({})), /同名标签/); }); -test('空白手动输入遵守标签规则,非法引用和网络错误不能回落', () => { - assert.throws(() => resolvePluginRevision({ eventName: 'workflow_dispatch', refType: 'tag', refName: 'v2.5.0', requestedRef: ' ' }, lookup({})), /同名标签/); - for (const requestedRef of ['main\nsha=bad', '*', 'refs/heads/a..b', 'refs/heads/a^{}']) { - assert.throws(() => resolvePluginRevision({ eventName: 'workflow_dispatch', requestedRef }, lookup({})), /格式/); - } +test('网络错误不能回落,错误提交不能通过', () => { const failure = new Error('remote unavailable'); - assert.throws(() => resolvePluginRevision({ eventName: 'push' }, { lsRemote() { throw failure; } }), error => error === failure); - assert.throws(() => resolvePluginRevision({ eventName: 'push' }, lookup({ 'refs/heads/main': 'bad' })), /无法解析/); + assert.throws(() => resolvePluginRevision({ refType: 'branch' }, { lsRemote() { throw failure; } }), error => error === failure); + assert.throws(() => resolvePluginRevision({ refType: 'branch' }, lookup({ 'refs/heads/main': 'bad' })), /无法解析/); }); diff --git a/tools/ci/resolve-plugin-revision.mjs b/tools/ci/resolve-plugin-revision.mjs index 5f3028b8..be5f4b01 100644 --- a/tools/ci/resolve-plugin-revision.mjs +++ b/tools/ci/resolve-plugin-revision.mjs @@ -6,19 +6,16 @@ import { pathToFileURL } from 'node:url'; const repository = 'https://github.com/crysound/OpenTest-Plugins.git'; const shaPattern = /^[0-9a-f]{40}$/i; -export function resolvePluginRevision({ eventName, refType, refName, requestedRef = '' }, { +export function resolvePluginRevision({ refType, refName }, { lsRemote = refs => execFileSync('git', ['ls-remote', repository, ...refs], { encoding: 'utf8', timeout: 60_000, windowsHide: true, }), } = {}) { - const explicit = eventName === 'workflow_dispatch' && requestedRef.trim(); - const ref = explicit || (refType === 'tag' ? refName : 'main'); - if (explicit && shaPattern.test(ref)) return { ref, sha: ref.toLowerCase() }; + const ref = refType === 'tag' ? refName : 'main'; if (typeof ref !== 'string' || !ref || /[\s\x00-\x1f\x7f~^:?*\[\\]/.test(ref) || ref.includes('..') || ref.includes('@{')) { throw new Error('插件引用格式无效'); } - const candidates = !explicit && refType === 'tag' ? [`refs/tags/${ref}`] - : ref.startsWith('refs/') ? [ref] : [`refs/heads/${ref}`, `refs/tags/${ref}`]; + const candidates = refType === 'tag' ? [`refs/tags/${ref}`] : ['refs/heads/main']; const queries = candidates.flatMap(candidate => [candidate, `${candidate}^{}`]); // 精确匹配返回的引用;附注标签优先使用剥离后的提交编号,网络失败直接向上传递。 const refs = new Map(lsRemote(queries).trim().split(/\r?\n/).filter(Boolean).map(line => { @@ -33,8 +30,7 @@ export function resolvePluginRevision({ eventName, refType, refName, requestedRe } if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) { - const result = resolvePluginRevision({ eventName: process.env.GITHUB_EVENT_NAME, - refType: process.env.REF_TYPE, refName: process.env.REF_NAME, requestedRef: process.env.REQUESTED_REF }); - if (process.env.GITHUB_OUTPUT) appendFileSync(process.env.GITHUB_OUTPUT, `ref=${result.ref}\nsha=${result.sha}\n`); + const result = resolvePluginRevision({ refType: process.env.REF_TYPE, refName: process.env.REF_NAME }); + if (process.env.GITHUB_OUTPUT) appendFileSync(process.env.GITHUB_OUTPUT, `source=${result.ref}\nrevision=${result.sha}\n`); console.info(`OpenTest-Plugins: ${result.ref} (${result.sha})`); } diff --git a/tools/publish-community-build.cjs b/tools/publish-community-build.cjs index c79f823d..3438773f 100644 --- a/tools/publish-community-build.cjs +++ b/tools/publish-community-build.cjs @@ -53,8 +53,8 @@ module.exports = async function publishCommunityBuild({ installerPath, installerDigest, posixRoot, - pluginsRef, - pluginsSha, + pluginsSource, + pluginsRevision, }) { const channel = channelOf(version); const tag = `v${version}`; @@ -67,7 +67,7 @@ module.exports = async function publishCommunityBuild({ } if (typeof posixRoot !== 'string' || !path.isAbsolute(posixRoot)) throw new Error('Missing or invalid POSIX artifact root'); - if (typeof pluginsSha !== 'string' || !/^[0-9a-f]{40}$/i.test(pluginsSha)) throw new Error('Missing or invalid plugin commit SHA'); + if (typeof pluginsRevision !== 'string' || !/^[0-9a-f]{40}$/i.test(pluginsRevision)) throw new Error('Missing or invalid plugin revision'); const repo = context.repo; const { data: artifact } = await github.rest.actions.getArtifact({ ...repo, artifact_id: Number(artifactId) }); @@ -117,8 +117,8 @@ module.exports = async function publishCommunityBuild({ `Source commit: ${context.sha}`, `成功构建:${context.serverUrl}/${repo.owner}/${repo.repo}/actions/runs/${context.runId}`, `Successful build: ${context.serverUrl}/${repo.owner}/${repo.repo}/actions/runs/${context.runId}`, - `OpenTest-Plugins 插件提交:${pluginsSha}${pluginsRef ? `(引用 ${pluginsRef})` : ''}`, - `OpenTest-Plugins commit: ${pluginsSha}${pluginsRef ? ` (ref ${pluginsRef})` : ''}`, + `OpenTest-Plugins 插件提交:${pluginsRevision}${pluginsSource ? `(来源 ${pluginsSource})` : ''}`, + `OpenTest-Plugins commit: ${pluginsRevision}${pluginsSource ? ` (source ${pluginsSource})` : ''}`, '', '包含 OpenTest 和 crysound/OpenTest-Plugins 中的公开业务插件及 SonoDAQ 设备插件,不含官网完整包中的其他插件。', 'Includes OpenTest and the public business plugins and SonoDAQ device plugin from crysound/OpenTest-Plugins; other plugins from the website package are not included.', From 57a60d52674506124c719b3d03df0f46d303209f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=8D=9A=E6=9D=91=E5=AA=B7?= Date: Tue, 17 Nov 2026 15:27:57 +0800 Subject: [PATCH 11/13] fix(community-package): align installer metadata and test mode --- .github/workflows/community-package.yml | 4 +- CONTRIBUTING.md | 4 +- CONTRIBUTING.zh-CN.md | 4 +- tools/__tests__/community-package.test.mjs | 4 +- .../ensure-delivery-manifest.test.mjs | 79 ++++++++++++------- tools/ci/ensure-delivery-manifest.mjs | 30 ++++++- tools/ci/prepare-installer.mjs | 7 +- tools/ci/stage-posix-device-plugin.mjs | 4 +- tools/ci/verify-posix-installer.mjs | 1 + tools/package.mjs | 2 +- tools/publish-community-build.cjs | 8 +- 11 files changed, 101 insertions(+), 46 deletions(-) diff --git a/.github/workflows/community-package.yml b/.github/workflows/community-package.yml index d2777a59..1f28f787 100644 --- a/.github/workflows/community-package.yml +++ b/.github/workflows/community-package.yml @@ -50,8 +50,8 @@ jobs: with: node-version: 22 package-manager-cache: false - - name: Test version, plugin resolution and publication rules - run: node --test tools/__tests__/build-version.test.mjs tools/__tests__/resolve-plugin-revision.test.mjs tools/__tests__/publish-community-build.test.mjs + - name: Test version, plugin resolution, delivery manifest and publication rules + run: node --test tools/__tests__/build-version.test.mjs tools/__tests__/resolve-plugin-revision.test.mjs tools/__tests__/ensure-delivery-manifest.test.mjs tools/__tests__/publish-community-build.test.mjs - name: Resolve package version id: version env: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7816535d..2e2ab692 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,11 +41,11 @@ node --test tools/__tests__/docs-policy.test.mjs ## Community packages -The `community-package` workflow builds three community installers: an EXE executable installer for Windows x64, a DEB Debian package for Linux x64, and a DMG disk image for macOS ARM64. They include OpenTest, the business plugins listed in `default-plugins.json` (currently `fft-tools`) from `crysound/OpenTest-Plugins`, and the SonoDAQ device plugin, but not the other plugins from the website package. Device plugins are bundled under `backend/native/plugins/devices` in the application resources. Windows retains `test` mode; Linux and macOS use `production` license mode, with separate generated configurations for each mode. All platforms connect to `https://update.opentest.com`; there is no separate test server. Automatic updates are disabled. Windows is unsigned; macOS retains its multilingual license agreement and has only ad hoc signatures, without developer signing or Apple notarization. On first launch, choose Open Anyway in Privacy & Security. The SonoDAQ device plugin requires macOS 26 or later. +The `community-package` workflow builds three community installers: an EXE executable installer for Windows x64, a DEB Debian package for Linux x64, and a DMG disk image for macOS ARM64. They include OpenTest, the business plugins listed in `default-plugins.json` (currently `fft-tools`) from `crysound/OpenTest-Plugins`, and the SonoDAQ device plugin, but not the other plugins from the website package. Device plugins are bundled under `backend/native/plugins/devices` in the application resources. Windows retains `test` mode and uses the backend defaults without an explicit `cloud.license.url`; Linux and macOS use `production` license mode with the formal license service and separate generated configurations. There is no separate test server. Automatic updates are disabled. Windows is unsigned; macOS retains its multilingual license agreement and has only ad hoc signatures, without developer signing or Apple notarization. On first launch, choose Open Anyway in Privacy & Security. The SonoDAQ device plugin requires macOS 26 or later. Each push to `main` publishes a daily prerelease `A.B.C-dev.`; later builds on the same Beijing day add `.2`, `.3` and so on. Pushing `vA.B.C-rc.N` or `vA.B.C` publishes a release candidate or release. First create the same tag in `OpenTest-Plugins`: a missing tag fails the build instead of falling back to `main`. Daily builds, pull requests, and manual runs use the plugin repository's `main`; manual runs cannot select an arbitrary plugin revision. Tag runs require the matching plugin tag. All three platforms check out the same resolved commit directly and verify it again, so a moving branch cannot change the build inputs. After every build and installation check succeeds, one publishing job uploads three installers and their SHA-256 checksum files before making the release public. -Pull requests targeting `main` trigger all three builds and installation checks, without publishing, when they change the packaging scripts listed in the workflow, `tools/__tests__/**`, `tools/ci/**`, `default-plugins.json`, `packaging.config.json`, `apps/**`, `sdks/**`, `vendor/**`, `package.json`, or `pnpm-lock.yaml`. This workflow intentionally includes application, software development kit and runtime material changes in its three-platform validation scope. `package.json` keeps the plain `A.B.C` used for plugin compatibility; the full version is passed to `node tools/package.mjs --version`. The workflow uses `--edition community`. +Pull requests targeting `main` trigger all three builds and installation checks, without publishing, when they change `.github/workflows/community-package.yml`, `default-plugins.json`, `packaging.config.json`, the packaging scripts listed in the workflow, `tools/__tests__/**`, `tools/ci/**`, or `tools/publish-community-build.cjs`. The workflow uses `--edition community` and does not trigger for unrelated application, SDK, vendor, manifest, or lockfile changes. `package.json` keeps the plain `A.B.C` used for plugin compatibility; the full version is passed to `node tools/package.mjs --version`. ## GitHub enforcement diff --git a/CONTRIBUTING.zh-CN.md b/CONTRIBUTING.zh-CN.md index 63136c99..f8e9c5d4 100644 --- a/CONTRIBUTING.zh-CN.md +++ b/CONTRIBUTING.zh-CN.md @@ -41,11 +41,11 @@ node --test tools/__tests__/docs-policy.test.mjs ## 社区包 -`community-package` 工作流构建三平台社区安装包:Windows x64 的 EXE(可执行安装程序)、Linux x64 的 DEB(Debian 软件包)、macOS ARM64 的 DMG(磁盘映像)。社区包包含 OpenTest、`crysound/OpenTest-Plugins` 中由 `default-plugins.json` 列出的业务插件(当前为 `fft-tools`)和 SonoDAQ 设备插件,不含官网完整包的其他插件。设备插件放在应用资源目录的 `backend/native/plugins/devices` 下。Windows 保留 `test` 测试模式,Linux、macOS 使用 `production` 正式授权模式,各模式独立生成配置。三平台均连接 `https://update.opentest.com`,当前没有独立测试服务器;自动更新均关闭。Windows 未签名;macOS 保留多语言许可协议,仅作本机临时签名,未取得开发者签名或 Apple 公证,首次打开需在“隐私与安全性”中点“仍要打开”。SonoDAQ 设备插件要求 macOS 26 或更高版本。 +`community-package` 工作流构建三平台社区安装包:Windows x64 的 EXE(可执行安装程序)、Linux x64 的 DEB(Debian 软件包)、macOS ARM64 的 DMG(磁盘映像)。社区包包含 OpenTest、`crysound/OpenTest-Plugins` 中由 `default-plugins.json` 列出的业务插件(当前为 `fft-tools`)和 SonoDAQ 设备插件,不含官网完整包的其他插件。设备插件放在应用资源目录的 `backend/native/plugins/devices` 下。Windows 保留 `test` 测试模式,使用后端默认配置且不写入 `cloud.license.url`;Linux、macOS 使用正式授权服务的 `production` 模式,各模式独立生成配置。当前没有独立测试服务器;自动更新均关闭。Windows 未签名;macOS 保留多语言许可协议,仅作本机临时签名,未取得开发者签名或 Apple 公证,首次打开需在“隐私与安全性”中点“仍要打开”。SonoDAQ 设备插件要求 macOS 26 或更高版本。 每次推送到 `main` 都发布一个日常预发布版本 `A.B.C-dev.<年月日>`,北京时间同一天的后续构建依次加 `.2`、`.3`。推送 `vA.B.C-rc.N` 或 `vA.B.C` 标签会发布候选版本或正式版本;必须先在 `OpenTest-Plugins` 创建同名标签,缺失时构建立即失败,不回落到 `main`。日常构建、拉取请求和手动运行都使用插件仓库的 `main`;手动运行不能指定任意插件版本,标签运行必须使用同名插件标签。三个平台直接检出解析得到的同一提交,并再次核对,防止构建期间分支前移。全部构建及安装验证通过后,单一发布任务先上传三个安装包及各自的 SHA-256 文件校验值,再公开版本。 -面向 `main` 的拉取请求若修改工作流中列出的打包脚本、`tools/__tests__/**`、`tools/ci/**`、`default-plugins.json`、`packaging.config.json`、`apps/**`、`sdks/**`、`vendor/**`、`package.json` 或 `pnpm-lock.yaml`,会触发三平台构建和安装验证,但不发布。本工作流有意将应用、软件开发套件和运行材料变更纳入三平台验证范围。`package.json` 保留用于插件兼容性的 `A.B.C`,完整版本号通过 `node tools/package.mjs --version` 传入;工作流使用 `--edition community`。 +面向 `main` 的拉取请求若修改 `.github/workflows/community-package.yml`、`default-plugins.json`、`packaging.config.json`、工作流中列出的打包脚本、`tools/__tests__/**`、`tools/ci/**` 或 `tools/publish-community-build.cjs`,会触发三平台构建和安装验证,但不发布。工作流使用 `--edition community`;无关的应用、软件开发套件、vendor、清单或锁文件变更不会触发这条流程。`package.json` 保留用于插件兼容性的 `A.B.C`,完整版本号通过 `node tools/package.mjs --version` 传入。 ## GitHub 强制检查 diff --git a/tools/__tests__/community-package.test.mjs b/tools/__tests__/community-package.test.mjs index d0a8ad0f..1eebd150 100644 --- a/tools/__tests__/community-package.test.mjs +++ b/tools/__tests__/community-package.test.mjs @@ -80,7 +80,9 @@ test('三平台生成独立模式配置并使用明确的正式许可证地址', assert.equal(config.desktopConfig, path.join(temporary, `local-settings-${mode}.json`)); assert.equal(config.services.environment, mode); assert.equal(config.services.licenseUrl, 'https://update.opentest.com'); - assert.match(readFileSync(config.backendConfig, 'utf8'), /^cloud\.license\.url=https:\/\/update\.opentest\.com$/m); + const backend = readFileSync(config.backendConfig, 'utf8'); + if (mode === 'test') assert.doesNotMatch(backend, /^cloud\.license\.url=/m); + else assert.match(backend, /^cloud\.license\.url=https:\/\/update\.opentest\.com$/m); assert.equal(JSON.parse(readFileSync(config.desktopConfig, 'utf8')).updates.enabled, false); } }); diff --git a/tools/__tests__/ensure-delivery-manifest.test.mjs b/tools/__tests__/ensure-delivery-manifest.test.mjs index f1eae0f1..4c30e140 100644 --- a/tools/__tests__/ensure-delivery-manifest.test.mjs +++ b/tools/__tests__/ensure-delivery-manifest.test.mjs @@ -6,49 +6,68 @@ import path from 'node:path'; import test from 'node:test'; import { ensureDeliveryManifest } from '../ci/ensure-delivery-manifest.mjs'; -test('为真实单一安装包补齐交付清单并校验名称和摘要', t => { - const root = mkdtempSync(path.join(os.tmpdir(), 'opentest-delivery-')); +function fixture(prefix, platform = 'linux') { + const root = mkdtempSync(path.join(os.tmpdir(), prefix)); + const arch = platform === 'mac' ? 'arm64' : 'x64'; + const extension = platform === 'mac' ? '.dmg' : '.deb'; + const version = '2.5.0-dev.20261117'; + const output = path.join(root, `dist/releases/${platform}-${arch}/production/unsigned`); + const installer = path.join(output, 'installer', `OpenTest-Community-${version}-production-installer-${platform}-${arch}${extension}`); + mkdirSync(path.dirname(installer), { recursive: true }); + const data = Buffer.from(`${platform} fixture`); + writeFileSync(installer, data); + return { root, output, installer, version, data }; +} + +test('creates and rechecks a delivery manifest with the installer digest', t => { + const { root, version, data } = fixture('opentest-delivery-', 'mac'); t.after(() => rmSync(root, { recursive: true, force: true })); - const directory = path.join(root, 'dist/releases/mac-arm64/production/unsigned/installer'); - mkdirSync(directory, { recursive: true }); - const name = 'OpenTest-Community-2.5.0-dev.20261117-production-installer-mac-arm64.dmg'; - const data = Buffer.from('dmg fixture'); - writeFileSync(path.join(directory, name), data); - const result = ensureDeliveryManifest({ root, platform: 'mac', version: '2.5.0-dev.20261117' }); + const result = ensureDeliveryManifest({ root, platform: 'mac', version }); + assert.equal(result.automaticUpdate, false); assert.equal(result.artifacts[0].sha256, createHash('sha256').update(data).digest('hex')); const manifest = JSON.parse(readFileSync(path.join(root, 'dist/releases/mac-arm64/production/unsigned/delivery.json'), 'utf8')); assert.deepEqual(manifest, result); - assert.deepEqual(ensureDeliveryManifest({ root, platform: 'mac', version: '2.5.0-dev.20261117' }), result); + assert.deepEqual(ensureDeliveryManifest({ root, platform: 'mac', version }), result); }); -test('保留打包器已有的附加清单字段并只校验交付核心字段', t => { - const root = mkdtempSync(path.join(os.tmpdir(), 'opentest-delivery-existing-')); +test('preserves bundled plugin metadata while validating generated fields', t => { + const { root, output, installer, version, data } = fixture('opentest-delivery-existing-'); t.after(() => rmSync(root, { recursive: true, force: true })); - const directory = path.join(root, 'dist/releases/linux-x64/production/unsigned/installer'); - mkdirSync(directory, { recursive: true }); - const name = 'OpenTest-Community-2.5.0-dev.20261117-production-installer-linux-x64.deb'; - const data = Buffer.from('deb fixture'); - writeFileSync(path.join(directory, name), data); const digest = createHash('sha256').update(data).digest('hex'); const existing = { - version: '2.5.0-dev.20261117', productVersion: '2.5.0', edition: 'community', mode: 'production', + version, productVersion: '2.5.0', edition: 'community', mode: 'production', platform: 'linux', arch: 'x64', signed: false, notarized: false, - bundledPlugins: [{ pluginId: 'com.opentest.fft-tools', version: '1.4.0' }], automaticUpdate: false, - artifacts: [{ file: `installer/${name}`, sha256: digest }], + bundledPlugins: [{ pluginId: 'com.opentest.fft-tools', version: '2.5.4' }], automaticUpdate: false, + artifacts: [{ file: `installer/${path.basename(installer)}`, sha256: digest }], }; - const output = path.join(root, 'dist/releases/linux-x64/production/unsigned'); writeFileSync(path.join(output, 'delivery.json'), JSON.stringify(existing)); - assert.deepEqual(ensureDeliveryManifest({ root, platform: 'linux', version: '2.5.0-dev.20261117' }), existing); + assert.deepEqual(ensureDeliveryManifest({ root, platform: 'linux', version }), existing); +}); + +test('rejects a missing installer directory or duplicate installers', t => { + const root = mkdtempSync(path.join(os.tmpdir(), 'opentest-delivery-missing-')); + t.after(() => rmSync(root, { recursive: true, force: true })); + assert.throws(() => ensureDeliveryManifest({ root, platform: 'linux', version: '2.5.0-dev.20261117' })); + const duplicate = fixture('opentest-delivery-duplicate-'); + t.after(() => rmSync(duplicate.root, { recursive: true, force: true })); + writeFileSync(path.join(duplicate.output, 'installer', `OpenTest-Community-${duplicate.version}-production-installer-linux-x64-copy.deb`), 'duplicate'); + assert.throws(() => ensureDeliveryManifest({ root: duplicate.root, platform: 'linux', version: duplicate.version })); }); -test('清单步骤拒绝缺失、重复、错误命名或已篡改清单', t => { - const root = mkdtempSync(path.join(os.tmpdir(), 'opentest-delivery-invalid-')); +test('rejects tampered digest, version, platform, and automatic update fields', t => { + const { root, output, installer, version, data } = fixture('opentest-delivery-tampered-'); t.after(() => rmSync(root, { recursive: true, force: true })); - const directory = path.join(root, 'dist/releases/linux-x64/production/unsigned/installer'); - mkdirSync(directory, { recursive: true }); - const name = 'OpenTest-Community-2.5.0-production-installer-linux-x64.deb'; - writeFileSync(path.join(directory, name), 'deb'); - assert.throws(() => ensureDeliveryManifest({ root, platform: 'linux', version: '2.5.0-dev.20261117' }), /名称/); - writeFileSync(path.join(directory, 'OpenTest-Community-2.5.0-dev.20261117-production-installer-linux-x64.deb'), 'deb'); - assert.throws(() => ensureDeliveryManifest({ root, platform: 'linux', version: '2.5.0-dev.20261117' }), /一个/); + const digest = createHash('sha256').update(data).digest('hex'); + const base = { + version, productVersion: '2.5.0', edition: 'community', mode: 'production', + platform: 'linux', arch: 'x64', signed: false, notarized: false, + bundledPlugins: [{ pluginId: 'com.opentest.fft-tools', version: '2.5.4' }], automaticUpdate: false, + artifacts: [{ file: `installer/${path.basename(installer)}`, sha256: digest }], + }; + for (const [field, value] of [['version', '2.5.1-dev.20261117'], ['platform', 'mac'], ['automaticUpdate', true]]) { + writeFileSync(path.join(output, 'delivery.json'), JSON.stringify({ ...base, [field]: value })); + assert.throws(() => ensureDeliveryManifest({ root, platform: 'linux', version })); + } + writeFileSync(path.join(output, 'delivery.json'), JSON.stringify({ ...base, artifacts: [{ ...base.artifacts[0], sha256: '0'.repeat(64) }] })); + assert.throws(() => ensureDeliveryManifest({ root, platform: 'linux', version })); }); diff --git a/tools/ci/ensure-delivery-manifest.mjs b/tools/ci/ensure-delivery-manifest.mjs index 166a0ba2..2d3df7a3 100644 --- a/tools/ci/ensure-delivery-manifest.mjs +++ b/tools/ci/ensure-delivery-manifest.mjs @@ -5,6 +5,31 @@ import { pathToFileURL } from 'node:url'; import { repositoryRoot } from '../runtime.mjs'; import { resolvePackagingPlatform } from '../packaging-platforms.mjs'; +function discoverBundledPlugins(root) { + const entries = new Map(); + const add = (pluginId, version) => { + if (typeof pluginId === 'string' && typeof version === 'string' && pluginId && version) { + entries.set(pluginId, { pluginId, version }); + } + }; + const searchRoot = path.join(root, '.runtime/packaging'); + if (!existsSync(searchRoot)) return []; + for (const entry of readdirSync(searchRoot, { recursive: true, withFileTypes: true })) { + if (!entry.isFile()) continue; + const file = path.join(entry.parentPath, entry.name); + if (entry.name === 'plugin-package.json') { + try { + const metadata = JSON.parse(readFileSync(file, 'utf8')); + add(metadata.pluginId || metadata.packageId, metadata.version); + } catch { /* Ignore unrelated or incomplete staging files. */ } + } else { + const match = entry.name.match(/^(com\.opentest\.[^-]+)-(\d+\.\d+\.\d+)-[0-9a-f]{64}\.otplugin$/i); + if (match) add(match[1], match[2]); + } + } + return [...entries.values()].sort((a, b) => a.pluginId.localeCompare(b.pluginId)); +} + export function ensureDeliveryManifest({ root = repositoryRoot, platform, version, mode = 'production', edition = 'community' } = {}) { const target = resolvePackagingPlatform(platform); const output = path.join(root, 'dist/releases', `${target.platform}-${target.arch}`, mode, 'unsigned'); @@ -19,10 +44,11 @@ export function ensureDeliveryManifest({ root = repositoryRoot, platform, versio const expected = `OpenTest-Community-${version}-${mode}-installer-${platform}-${target.arch}${extension}`; if (name !== expected) throw new Error(`安装包名称不匹配:${name};应为 ${expected}`); const sha256 = createHash('sha256').update(readFileSync(installer)).digest('hex'); + const bundledPlugins = discoverBundledPlugins(root); const manifest = { version, productVersion: version.replace(/-(?:dev|rc)\..*$/, ''), edition, mode, platform, arch: target.arch, signed: false, notarized: false, - bundledPlugins: [], automaticUpdate: platform !== 'linux', + ...(bundledPlugins.length ? { bundledPlugins } : {}), automaticUpdate: false, artifacts: [{ file: `installer/${name}`, sha256 }], }; const manifestPath = path.join(output, 'delivery.json'); @@ -34,6 +60,8 @@ export function ensureDeliveryManifest({ root = repositoryRoot, platform, versio existing.edition === manifest.edition && existing.mode === manifest.mode && existing.platform === manifest.platform && existing.arch === manifest.arch && existing.signed === manifest.signed && existing.notarized === manifest.notarized && + existing.automaticUpdate === false && + (!bundledPlugins.length || JSON.stringify(existing.bundledPlugins) === JSON.stringify(bundledPlugins)) && artifact?.file === manifest.artifacts[0].file && artifact.sha256 === sha256; if (!valid) throw new Error(`已有 delivery.json 与实际安装包不一致:${manifestPath}`); return existing; diff --git a/tools/ci/prepare-installer.mjs b/tools/ci/prepare-installer.mjs index 51fa85e5..a4128c3a 100644 --- a/tools/ci/prepare-installer.mjs +++ b/tools/ci/prepare-installer.mjs @@ -18,7 +18,10 @@ for (const mode of ['test', 'production']) { if (typeof licenseUrl !== 'string' || !licenseUrl.trim()) throw new Error(`${mode} 模式缺少授权服务地址`); const backendConfig = path.join(directory, `application-${mode}.properties`); const desktopConfig = path.join(directory, `local-settings-${mode}.json`); - writeFileSync(backendConfig, `# Community installer: ${mode}\ncloud.license.url=${licenseUrl}\n`); + const backendContents = mode === 'test' + ? `# Community installer: ${mode}\n` + : `# Community installer: ${mode}\ncloud.license.url=${licenseUrl}\n`; + writeFileSync(backendConfig, backendContents); writeFileSync(desktopConfig, `${JSON.stringify(settings, null, 2)}\n`); modes[mode] = { backendConfig, desktopConfig, licenseUrl }; } @@ -34,4 +37,4 @@ writeFileSync(path.join(directory, 'packaging.json'), `${JSON.stringify({ modes, ...(nativePluginBinRoot ? { nativePluginBinRoot } : {}), }, null, 2)}\n`); -console.info('已分别生成测试和生产模式配置,均使用仓库确认的正式服务地址;自动更新已关闭。'); +console.info('已分别生成测试和生产模式配置:测试模式使用后端默认授权配置,生产模式使用仓库确认的正式服务地址;自动更新已关闭。'); diff --git a/tools/ci/stage-posix-device-plugin.mjs b/tools/ci/stage-posix-device-plugin.mjs index 4e6356c2..fe765d76 100644 --- a/tools/ci/stage-posix-device-plugin.mjs +++ b/tools/ci/stage-posix-device-plugin.mjs @@ -1,5 +1,6 @@ import { execFileSync } from 'node:child_process'; import { cpSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs'; +import os from 'node:os'; import path from 'node:path'; import { repositoryRoot } from '../runtime.mjs'; import { resolvePackagingPlatform, assertPackagingPlatformReady } from '../packaging-platforms.mjs'; @@ -7,7 +8,8 @@ import { resolvePackagingPlatform, assertPackagingPlatformReady } from '../packa const target = resolvePackagingPlatform(process.env.PACKAGE_PLATFORM); assertPackagingPlatformReady(target); if (!['mac', 'linux'].includes(target.platform)) throw new Error('此入口只构建 Linux/macOS 设备插件'); -const temp = process.env.RUNNER_TEMP; +const temp = process.env.RUNNER_TEMP || os.tmpdir(); +if (!process.env.NATIVE_PLUGIN_BIN) throw new Error('NATIVE_PLUGIN_BIN 必须设置为设备插件输出目录'); const source = path.join(temp, 'opentest-plugins/plugins/opentest_sonodaq_plugin'); const framework = path.join(repositoryRoot, 'apps/native'); const build = path.join(temp, 'sonodaq-build'); diff --git a/tools/ci/verify-posix-installer.mjs b/tools/ci/verify-posix-installer.mjs index 51735f6f..e6fa3c95 100644 --- a/tools/ci/verify-posix-installer.mjs +++ b/tools/ci/verify-posix-installer.mjs @@ -47,6 +47,7 @@ export function verifyInstaller({ platform = process.env.PACKAGE_PLATFORM, root assert.ok(['mac', 'linux'].includes(platform)); const output = path.join(root, `dist/releases/${platform}-${target.arch}/production/unsigned`); const delivery = JSON.parse(readFileSync(path.join(output, 'delivery.json'), 'utf8')); + if (process.env.VERSION) assert.equal(delivery.version, process.env.VERSION); assert.equal(delivery.platform, platform); assert.equal(delivery.arch, target.arch); assert.equal(delivery.mode, 'production'); diff --git a/tools/package.mjs b/tools/package.mjs index 9f3d2784..d950bc22 100644 --- a/tools/package.mjs +++ b/tools/package.mjs @@ -468,7 +468,7 @@ export async function packageHost({ mode, kind, sign = false, platform = current arch: platformTarget.arch, signed: sign, notarized: notarize, - automaticUpdate: platform !== 'linux', + automaticUpdate: false, artifacts: artifacts.map((file) => ({ file: path.relative(output, file), sha256: createHash("sha256").update(readFileSync(file)).digest("hex"), diff --git a/tools/publish-community-build.cjs b/tools/publish-community-build.cjs index 3438773f..972ae1f2 100644 --- a/tools/publish-community-build.cjs +++ b/tools/publish-community-build.cjs @@ -122,10 +122,10 @@ module.exports = async function publishCommunityBuild({ '', '包含 OpenTest 和 crysound/OpenTest-Plugins 中的公开业务插件及 SonoDAQ 设备插件,不含官网完整包中的其他插件。', 'Includes OpenTest and the public business plugins and SonoDAQ device plugin from crysound/OpenTest-Plugins; other plugins from the website package are not included.', - 'Windows x64 提供未签名的 EXE(可执行安装程序),保留 test 测试模式;Linux x64 提供 DEB(Debian 软件包),macOS ARM64 提供 DMG(磁盘映像),使用 production 正式授权模式。', - 'Windows x64 provides an unsigned EXE installer in test mode; Linux x64 provides a DEB package and macOS ARM64 provides a DMG disk image, both in production license mode.', - '三平台均连接正式许可证服务 https://update.opentest.com;当前没有独立测试服务器,test 模式不代表另有测试服务。自动更新均已关闭。', - 'All three platforms connect to the production license service https://update.opentest.com; there is no separate test server, and test mode does not imply one. Automatic updates are disabled.', + 'Windows x64 提供未签名的 EXE(可执行安装程序),保留 test 测试模式,使用后端默认配置且不写入 cloud.license.url;Linux x64 提供 DEB(Debian 软件包),macOS ARM64 提供 DMG(磁盘映像),两者使用 production 正式授权模式。', + 'Windows x64 provides an unsigned EXE installer in test mode using backend defaults without an explicit cloud.license.url; Linux x64 provides a DEB package and macOS ARM64 provides a DMG disk image, both in production license mode.', + 'Linux 和 macOS 连接正式许可证服务 https://update.opentest.com;当前没有独立测试服务器。Windows test 模式不意味着有独立测试服务。自动更新均已关闭。', + 'Linux and macOS connect to the production license service https://update.opentest.com; there is no separate test server. Windows test mode does not imply a separate test service. Automatic updates are disabled.', 'macOS 保留多语言许可协议;应用及插件仅作本机临时签名,未取得开发者签名或 Apple 公证。首次打开请在“隐私与安全性”中点“仍要打开”;SonoDAQ 设备插件要求 macOS 26 或更高版本。', 'macOS retains the multilingual license agreement. The application and plugins have only ad hoc signatures, without developer signing or Apple notarization. On first launch, choose Open Anyway in Privacy & Security; the SonoDAQ device plugin requires macOS 26 or later.', '已验证安装过程、程序架构、随包文件完整性和 Java 运行时;未验证云端登录、付费算法授权或真实硬件功能。', From 99ce1719f5abc950eae4c065994305dbdbee5c2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=8D=9A=E6=9D=91=E5=AA=B7?= Date: Tue, 17 Nov 2026 15:49:02 +0800 Subject: [PATCH 12/13] fix(community-package): parse hyphenated plugin archives --- tools/__tests__/ensure-delivery-manifest.test.mjs | 10 ++++++++++ tools/ci/ensure-delivery-manifest.mjs | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/__tests__/ensure-delivery-manifest.test.mjs b/tools/__tests__/ensure-delivery-manifest.test.mjs index 4c30e140..61df2d87 100644 --- a/tools/__tests__/ensure-delivery-manifest.test.mjs +++ b/tools/__tests__/ensure-delivery-manifest.test.mjs @@ -30,6 +30,16 @@ test('creates and rechecks a delivery manifest with the installer digest', t => assert.deepEqual(ensureDeliveryManifest({ root, platform: 'mac', version }), result); }); +test('discovers bundled plugin archives whose IDs contain hyphens', t => { + const { root, version } = fixture('opentest-delivery-plugin-'); + t.after(() => rmSync(root, { recursive: true, force: true })); + const staged = path.join(root, '.runtime/packaging/production-stage/resources/bundled-plugins'); + mkdirSync(staged, { recursive: true }); + writeFileSync(path.join(staged, `com.opentest.fft-tools-2.5.4-${'a'.repeat(64)}.otplugin`), 'fixture'); + const result = ensureDeliveryManifest({ root, platform: 'linux', version }); + assert.deepEqual(result.bundledPlugins, [{ pluginId: 'com.opentest.fft-tools', version: '2.5.4' }]); +}); + test('preserves bundled plugin metadata while validating generated fields', t => { const { root, output, installer, version, data } = fixture('opentest-delivery-existing-'); t.after(() => rmSync(root, { recursive: true, force: true })); diff --git a/tools/ci/ensure-delivery-manifest.mjs b/tools/ci/ensure-delivery-manifest.mjs index 2d3df7a3..fdfbdb52 100644 --- a/tools/ci/ensure-delivery-manifest.mjs +++ b/tools/ci/ensure-delivery-manifest.mjs @@ -23,7 +23,10 @@ function discoverBundledPlugins(root) { add(metadata.pluginId || metadata.packageId, metadata.version); } catch { /* Ignore unrelated or incomplete staging files. */ } } else { - const match = entry.name.match(/^(com\.opentest\.[^-]+)-(\d+\.\d+\.\d+)-[0-9a-f]{64}\.otplugin$/i); + // Plugin IDs may contain hyphens (for example `com.opentest.fft-tools`). + // Parse from the version and archive digest suffix instead of stopping at + // the first hyphen in the ID. + const match = entry.name.match(/^(com\.opentest\..+)-(\d+\.\d+\.\d+)-[0-9a-f]{64}\.otplugin$/i); if (match) add(match[1], match[2]); } } From 717dbd4bc29017ab5680653f04ff472250c1565a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=8D=9A=E6=9D=91=E5=AA=B7?= Date: Tue, 17 Nov 2026 16:20:36 +0800 Subject: [PATCH 13/13] fix(community-package): align manifest plugin metadata --- .../ensure-delivery-manifest.test.mjs | 20 +++++++ tools/ci/ensure-delivery-manifest.mjs | 58 ++++++++++++++----- 2 files changed, 63 insertions(+), 15 deletions(-) diff --git a/tools/__tests__/ensure-delivery-manifest.test.mjs b/tools/__tests__/ensure-delivery-manifest.test.mjs index 61df2d87..8b4d8026 100644 --- a/tools/__tests__/ensure-delivery-manifest.test.mjs +++ b/tools/__tests__/ensure-delivery-manifest.test.mjs @@ -40,6 +40,26 @@ test('discovers bundled plugin archives whose IDs contain hyphens', t => { assert.deepEqual(result.bundledPlugins, [{ pluginId: 'com.opentest.fft-tools', version: '2.5.4' }]); }); +test('uses the package index format for bundled plugin metadata', t => { + const { root, version } = fixture('opentest-delivery-index-'); + t.after(() => rmSync(root, { recursive: true, force: true })); + const staged = path.join(root, '.runtime/packaging/production-stage/resources/bundled-plugins'); + mkdirSync(staged, { recursive: true }); + writeFileSync(path.join(staged, 'index.json'), JSON.stringify({ + schemaVersion: 1, + hostVersion: '2.5.0', + plugins: [{ + pluginId: 'com.opentest.fft-tools', + version: '2.5.4', + file: `com.opentest.fft-tools-2.5.4-${'a'.repeat(64)}.otplugin`, + archiveSha256: 'a'.repeat(64), + packageDigest: 'b'.repeat(64), + }], + })); + const result = ensureDeliveryManifest({ root, platform: 'linux', version }); + assert.deepEqual(result.bundledPlugins, [{ pluginId: 'com.opentest.fft-tools', version: '2.5.4' }]); +}); + test('preserves bundled plugin metadata while validating generated fields', t => { const { root, output, installer, version, data } = fixture('opentest-delivery-existing-'); t.after(() => rmSync(root, { recursive: true, force: true })); diff --git a/tools/ci/ensure-delivery-manifest.mjs b/tools/ci/ensure-delivery-manifest.mjs index fdfbdb52..d7c9619f 100644 --- a/tools/ci/ensure-delivery-manifest.mjs +++ b/tools/ci/ensure-delivery-manifest.mjs @@ -14,20 +14,30 @@ function discoverBundledPlugins(root) { }; const searchRoot = path.join(root, '.runtime/packaging'); if (!existsSync(searchRoot)) return []; - for (const entry of readdirSync(searchRoot, { recursive: true, withFileTypes: true })) { - if (!entry.isFile()) continue; - const file = path.join(entry.parentPath, entry.name); - if (entry.name === 'plugin-package.json') { - try { - const metadata = JSON.parse(readFileSync(file, 'utf8')); - add(metadata.pluginId || metadata.packageId, metadata.version); - } catch { /* Ignore unrelated or incomplete staging files. */ } - } else { - // Plugin IDs may contain hyphens (for example `com.opentest.fft-tools`). - // Parse from the version and archive digest suffix instead of stopping at - // the first hyphen in the ID. - const match = entry.name.match(/^(com\.opentest\..+)-(\d+\.\d+\.\d+)-[0-9a-f]{64}\.otplugin$/i); - if (match) add(match[1], match[2]); + // package.mjs writes this index beside the staged archives. Reading it keeps + // the verifier on the same metadata source as the generated delivery.json. + for (const stage of readdirSync(searchRoot, { withFileTypes: true })) { + if (!stage.isDirectory() || !stage.name.startsWith('production-')) continue; + const index = path.join(searchRoot, stage.name, 'resources', 'bundled-plugins', 'index.json'); + if (!existsSync(index)) continue; + try { + const metadata = JSON.parse(readFileSync(index, 'utf8')); + for (const plugin of metadata.plugins || []) add(plugin.pluginId, plugin.version); + } catch { /* Ignore incomplete staging files. */ } + } + if (!entries.size) { + for (const entry of readdirSync(searchRoot, { recursive: true, withFileTypes: true })) { + if (!entry.isFile()) continue; + const file = path.join(entry.parentPath, entry.name); + if (entry.name === 'plugin-package.json') { + try { + const metadata = JSON.parse(readFileSync(file, 'utf8')); + add(metadata.pluginId || metadata.packageId, metadata.version); + } catch { /* Ignore unrelated or incomplete staging files. */ } + } else { + const match = entry.name.match(/^(com\.opentest\..+)-(\d+\.\d+\.\d+)-[0-9a-f]{64}\.otplugin$/i); + if (match) add(match[1], match[2]); + } } } return [...entries.values()].sort((a, b) => a.pluginId.localeCompare(b.pluginId)); @@ -66,7 +76,25 @@ export function ensureDeliveryManifest({ root = repositoryRoot, platform, versio existing.automaticUpdate === false && (!bundledPlugins.length || JSON.stringify(existing.bundledPlugins) === JSON.stringify(bundledPlugins)) && artifact?.file === manifest.artifacts[0].file && artifact.sha256 === sha256; - if (!valid) throw new Error(`已有 delivery.json 与实际安装包不一致:${manifestPath}`); + if (!valid) { + console.error('交付清单字段不一致:', JSON.stringify({ + existing: { + version: existing.version, + productVersion: existing.productVersion, + edition: existing.edition, + mode: existing.mode, + platform: existing.platform, + arch: existing.arch, + signed: existing.signed, + notarized: existing.notarized, + automaticUpdate: existing.automaticUpdate, + bundledPlugins: existing.bundledPlugins, + artifacts: existing.artifacts, + }, + expected: manifest, + })); + throw new Error(`已有 delivery.json 与实际安装包不一致:${manifestPath}`); + } return existing; } else { writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);