跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

提交记录
新增.github/workflows/release-platforms.yml+46 −0看文件
@@ -0,0 +1,46 @@
1新增:name: Build signed release platforms for local macOS assembly
2新增:on:
3新增: workflow_dispatch:
4新增: inputs:
5新增: ref:
6新增: description: Exact versioned source commit SHA (same as the locally notarized macOS build)
7新增: required: true
8新增: type: string
9新增:permissions:
10新增: contents: read
11新增:concurrency:
12新增: group: cage-local-assembly-platforms
13新增: cancel-in-progress: false
14新增:jobs:
15新增: validate:
16新增: if: github.repository == 'Lee-xeo/Claude-Cage' && github.ref == 'refs/heads/main'
17新增: runs-on: ubuntu-24.04
18新增: steps:
19新增: - name: Require an immutable build source
20新增: env:
21新增: BUILD_REF: ${{ inputs.ref }}
22新增: run: '[[ "$BUILD_REF" =~ ^[0-9a-f]{40}$ ]]'
23新增: - uses: actions/checkout@v4
24新增: with:
25新增: ref: ${{ inputs.ref }}
26新增: persist-credentials: false
27新增: - uses: actions/setup-node@v4
28新增: with:
29新增: node-version: 24
30新增: - run: node scripts/check-version.mjs
31新增: windows:
32新增: needs: validate
33新增: if: github.repository == 'Lee-xeo/Claude-Cage' && github.ref == 'refs/heads/main'
34新增: uses: ./.github/workflows/windows-build.yml
35新增: with:
36新增: ref: ${{ inputs.ref }}
37新增: release: true
38新增: artifact_name: release-windows
39新增: linux:
40新增: needs: validate
41新增: if: github.repository == 'Lee-xeo/Claude-Cage' && github.ref == 'refs/heads/main'
42新增: uses: ./.github/workflows/linux-build.yml
43新增: with:
44新增: ref: ${{ inputs.ref }}
45新增: release: true
46新增: artifact_name: release-linux
修改.github/workflows/release.yml+8 −2看文件
@@ -8,6 +8,14 @@ on:
88 default: prerelease
99 type: choice
1010 options: [prerelease, patch, minor, major]
11新增: version:
12新增: description: Exact requested version (for example 0.1.7-rc.1); overrides bump
13新增: required: false
14新增: type: string
15新增: notes_path:
16新增: description: Committed Markdown release notes under docs/ (optional)
17新增: required: false
18新增: type: string
1119permissions:
1220 contents: read
1321concurrency:
@@ -47,8 +55,6 @@ jobs:
4755 CAGE_ESIGNER_TOTP_SECRET: ${{ secrets.CAGE_ESIGNER_TOTP_SECRET }}
4856 CAGE_WINDOWS_PFX_BASE64: ${{ secrets.CAGE_WINDOWS_PFX_BASE64 }}
4957 CAGE_WINDOWS_PFX_PASSWORD: ${{ secrets.CAGE_WINDOWS_PFX_PASSWORD }}
50删除: CAGE_WINDOWS_QEMU_SOURCE_URL: ${{ vars.CAGE_WINDOWS_QEMU_SOURCE_URL }}
51删除: CAGE_WINDOWS_QEMU_SOURCE_SHA256: ${{ vars.CAGE_WINDOWS_QEMU_SOURCE_SHA256 }}
5258 run: node scripts/check-release-readiness.mjs
5359 - name: Validate versions and release behavior
5460 run: |
修改.github/workflows/windows-build.yml+0 −2看文件
@@ -145,8 +145,6 @@ jobs:
145145 CAGE_ESIGNER_TOTP_SECRET: ${{ secrets.CAGE_ESIGNER_TOTP_SECRET }}
146146 CAGE_WINDOWS_PFX_BASE64: ${{ secrets.CAGE_WINDOWS_PFX_BASE64 }}
147147 CAGE_WINDOWS_PFX_PASSWORD: ${{ secrets.CAGE_WINDOWS_PFX_PASSWORD }}
148删除: CAGE_WINDOWS_QEMU_SOURCE_URL: ${{ vars.CAGE_WINDOWS_QEMU_SOURCE_URL }}
149删除: CAGE_WINDOWS_QEMU_SOURCE_SHA256: ${{ vars.CAGE_WINDOWS_QEMU_SOURCE_SHA256 }}
150148 run: ./scripts/ci-windows-build.ps1 -Release
151149 - uses: actions/upload-artifact@v4
152150 with:
修改scripts/build-qemu-windows.ps1+1 −1看文件
@@ -14,7 +14,7 @@ $DependencyCache = [IO.Path]::GetFullPath($DependencyCache)
1414$OutputDirectory = [IO.Path]::GetFullPath($OutputDirectory)
1515$dependencies = Get-Content (Join-Path $repository 'packaging/windows/dependencies.json') -Raw | ConvertFrom-Json
1616$patchDirectory = Join-Path $repository 'patches/qemu'
17删除:$inputs = @((Join-Path $PSScriptRoot 'build-qemu-windows.sh'), $PSCommandPath) + @(Get-ChildItem $patchDirectory -Filter '*.patch' | Sort-Object Name | ForEach-Object FullName)
17新增:$inputs = @((Join-Path $PSScriptRoot 'build-qemu-windows.sh'), (Join-Path $PSScriptRoot 'bundle-qemu-sources.sh'), $PSCommandPath) + @(Get-ChildItem $patchDirectory -Filter '*.patch' | Sort-Object Name | ForEach-Object FullName)
1818$fingerprintText = $dependencies.qemuSource.hash + $dependencies.qemuKeycodemap.hash + (($inputs | ForEach-Object { (Get-FileHash $_ -Algorithm SHA256).Hash }) -join '')
1919$fingerprint = [Convert]::ToHexString([Security.Cryptography.SHA256]::HashData([Text.Encoding]::UTF8.GetBytes($fingerprintText)))
2020$manifestPath = Join-Path $OutputDirectory 'cage-build.json'
修改scripts/build-qemu-windows.sh+10 −0看文件
@@ -24,14 +24,24 @@ strip "$output_dir"/*.exe
2424# Copy the DLL dependency closure from this toolchain, using the same versions
2525# that were linked into the executables. Windows system DLLs remain system-owned.
2626pending=("$output_dir"/*.exe)
27新增:packages=()
2728while ((${#pending[@]})); do
2829 binary=${pending[0]}
2930 pending=("${pending[@]:1}")
3031 while read -r dll; do
3132 if [[ -f "$MINGW_PREFIX/bin/$dll" && ! -f "$output_dir/$dll" ]]; then
3233 cp "$MINGW_PREFIX/bin/$dll" "$output_dir/$dll"
34新增: packages+=("$(pacman -Qqo "$MINGW_PREFIX/bin/$dll")")
3335 pending+=("$output_dir/$dll")
3436 fi
3537 done < <(objdump -p "$binary" | awk '/DLL Name:/ {print $3}')
3638done
3739pacman -Q > "$output_dir/build-packages.txt"
40新增:# Keep the exact source package identity with cached binaries. A later runner
41新增:# must not collect the source of whichever library version happens to be installed.
42新增:for package in "${packages[@]}"; do
43新增: read -r name version < <(pacman -Q "$package")
44新增: base=$(awk '/^%BASE%$/ {getline; print; exit}' "/var/lib/pacman/local/$name-$version/desc")
45新增: [[ -n "$base" ]] || { echo "Source package identity missing for $package" >&2; exit 1; }
46新增: printf '%s %s\n' "$base" "$version"
47新增:done | sort -u > "$output_dir/build-source-packages.txt"
修改scripts/build-windows.ps1+11 −1看文件
@@ -105,7 +105,17 @@ try {
105105 Expand-BuildArchive $qemuArchive $qemuTarget $sevenZip
106106 $qemuBuilt = Join-Path $DependencyCache 'qemu-cage'
107107 & (Join-Path $PSScriptRoot 'build-qemu-windows.ps1') -DependencyCache $DependencyCache -OutputDirectory $qemuBuilt
108删除: Copy-Item (Join-Path $qemuBuilt '*') $qemuTarget -Force
108新增: $runtimeManifest = Get-Content (Join-Path $qemuBuilt 'cage-build.json') -Raw | ConvertFrom-Json
109新增: $ownedRuntime = @($runtimeManifest.files | ForEach-Object { $_.name }) + @('cage-build.json')
110新增: foreach ($name in $ownedRuntime) {
111新增: if ([IO.Path]::GetFileName($name) -ne $name) { throw 'Invalid QEMU runtime manifest path.' }
112新增: Copy-Item -LiteralPath (Join-Path $qemuBuilt $name) -Destination $qemuTarget -Force
113新增: }
114新增: # The two executables above are linked against the built dependency closure.
115新增: # Vendor DLLs/executables outside that closure have no runtime consumer.
116新增: Get-ChildItem -LiteralPath $qemuTarget -File | Where-Object {
117新增: $_.Extension -in @('.exe', '.dll') -and $_.Name -notin $ownedRuntime
118新增: } | Remove-Item -Force
109119 # Ship the x64 VM only, with its original firmware, DLLs and notices.
110120 Get-ChildItem -LiteralPath $qemuTarget -Filter 'qemu-system-*.exe' | Where-Object { $_.Name -ne 'qemu-system-x86_64.exe' } | Remove-Item -Force
111121 Get-ChildItem -LiteralPath (Join-Path $qemuTarget 'share') -File |
新增scripts/bundle-qemu-sources.sh+51 −0看文件
@@ -0,0 +1,51 @@
1新增:#!/usr/bin/env bash
2新增:# Bundle the exact QEMU/firmware revisions and the packages owning its DLLs.
3新增:set -euo pipefail
4新增:repository=$(cygpath -u "$1")
5新增:runtime=$(cygpath -u "$2")
6新增:archive=$(cygpath -u "$3")
7新增:commit=$(node -p "JSON.parse(require('fs').readFileSync(process.argv[1])).qemuSource.commit" "$repository/packaging/windows/dependencies.json")
8新增:[[ $commit =~ ^[a-f0-9]{40}$ && -s "$runtime/build-source-packages.txt" ]] || { echo 'QEMU source/package identity is missing.' >&2; exit 1; }
9新增:stage=$(mktemp -d)
10新增:trap 'rm -rf "$stage"' EXIT
11新增:mkdir -p "$stage/source/packages" "$stage/source/cage"
12新增:git -c core.autocrlf=false init -q "$stage/source/qemu"
13新增:git -C "$stage/source/qemu" fetch --depth=1 https://github.com/stweil/qemu.git "$commit"
14新增:git -c core.autocrlf=false -C "$stage/source/qemu" checkout -q --detach FETCH_HEAD
15新增:[[ $(git -C "$stage/source/qemu" rev-parse HEAD) == "$commit" ]]
16新增:# All shipped firmware comes from QEMU's pinned ROM submodules. Include nested
17新增:# submodules (EDK2 libraries etc.), not only the superproject's empty gitlinks.
18新增:git -c core.autocrlf=false -C "$stage/source/qemu" submodule update --init --recursive --depth=1 -- roms
19新增:git -C "$stage/source/qemu" submodule status --recursive -- roms > "$stage/source/firmware-revisions.txt"
20新增:if grep -Eq '^[-+U]' "$stage/source/firmware-revisions.txt"; then echo 'Firmware source revisions are incomplete.' >&2; exit 1; fi
21新增:cp "$runtime/build-source-packages.txt" "$runtime/build-packages.txt" "$runtime/cage-build.json" "$stage/source/cage/"
22新增:cp "$repository/scripts/build-qemu-windows.sh" "$repository/scripts/build-qemu-windows.ps1" "$repository/scripts/bundle-qemu-sources.sh" "$stage/source/cage/"
23新增:cp -R "$repository/patches/qemu" "$stage/source/cage/patches"
24新增:keymap_url=$(node -p "JSON.parse(require('fs').readFileSync(process.argv[1])).qemuKeycodemap.url" "$repository/packaging/windows/dependencies.json")
25新增:keymap_hash=$(node -p "JSON.parse(require('fs').readFileSync(process.argv[1])).qemuKeycodemap.hash" "$repository/packaging/windows/dependencies.json")
26新增:curl --fail --location --retry 3 -o "$stage/source/keycodemapdb.tar.gz" "$keymap_url"
27新增:printf '%s %s\n' "$keymap_hash" "$stage/source/keycodemapdb.tar.gz" | sha256sum -c -
28新增:while read -r base version; do
29新增: [[ $base =~ ^[a-zA-Z0-9+_.-]+$ && $version =~ ^[a-zA-Z0-9+_.:-]+$ ]] || exit 1
30新增: found=false
31新增: for extension in zst xz gz; do
32新增: name="$base-$version.src.tar.$extension"
33新增: url="https://repo.msys2.org/mingw/sources/$name"
34新增: if curl --fail --location --retry 2 -o "$stage/source/packages/$name" "$url"; then
35新增: curl --fail --location --retry 3 -o "$stage/source/packages/$name.sig" "$url.sig"
36新增: pacman-key --verify "$stage/source/packages/$name.sig" "$stage/source/packages/$name"
37新增: found=true
38新增: break
39新增: fi
40新增: done
41新增: $found || { echo "No verified corresponding source for $base $version" >&2; exit 1; }
42新增:done < "$runtime/build-source-packages.txt"
43新增:# Firmware sources remain unmodified; the Cage patch and reproducible build
44新增:# commands travel beside them. The manifest covers every distributed source.
45新增:find "$stage/source" -name .git -type d -prune -exec rm -rf {} +
46新增:find "$stage/source" -name .git -type f -delete
47新增:(cd "$stage/source" && find . -type f ! -name SHA256SUMS -print0 | sort -z | xargs -0 sha256sum > SHA256SUMS)
48新增:mkdir -p "$(dirname "$archive")"
49新增:tar -czf "$archive.partial" -C "$stage" source
50新增:mv "$archive.partial" "$archive"
51新增:sha256sum "$archive"
新增scripts/bundle-qemu-sources.test.mjs+34 −0看文件
@@ -0,0 +1,34 @@
1新增:import assert from 'node:assert/strict';
2新增:import {execFileSync} from 'node:child_process';
3新增:import {createHash} from 'node:crypto';
4新增:import {chmod,mkdir,mkdtemp,readFile,rm,writeFile} from 'node:fs/promises';
5新增:import {tmpdir} from 'node:os';
6新增:import {join} from 'node:path';
7新增:import {fileURLToPath} from 'node:url';
8新增:import test from 'node:test';
9新增:const collector=fileURLToPath(new URL('./bundle-qemu-sources.sh',import.meta.url));
10新增:test('source collector includes pinned firmware and authenticated package sources with a complete manifest',async t=>{
11新增: const root=await mkdtemp(join(tmpdir(),'cage-qemu-source-test-'));t.after(()=>rm(root,{recursive:true,force:true}));
12新增: const repository=join(root,'repository'),runtime=join(root,'runtime'),bin=join(root,'bin'),artifact=join(root,'bundle.tar.gz');
13新增: for(const path of [bin,runtime,join(repository,'packaging/windows'),join(repository,'scripts'),join(repository,'patches/qemu')])await mkdir(path,{recursive:true});
14新增: const sha='a'.repeat(40),content='fixture source archive\n';
15新增: await writeFile(join(repository,'packaging/windows/dependencies.json'),JSON.stringify({qemuSource:{commit:sha},qemuKeycodemap:{url:'https://source.invalid/keymap.tar.gz',hash:createHash('sha256').update(content).digest('hex')}}));
16新增: for(const name of ['build-source-packages.txt','build-packages.txt','cage-build.json'])await writeFile(join(runtime,name),name==='build-source-packages.txt'?'mingw-w64-fixture 1.2.3-1\n':'fixture');
17新增: for(const name of ['build-qemu-windows.sh','build-qemu-windows.ps1','bundle-qemu-sources.sh'])await writeFile(join(repository,'scripts',name),'fixture build input');
18新增: await writeFile(join(repository,'patches/qemu/fixture.patch'),'fixture patch');
19新增: const command=async(name,body)=>{const path=join(bin,name);await writeFile(path,'#!/bin/bash\nset -e\n'+body+'\n');await chmod(path,0o755)};
20新增: await command('cygpath','printf "%s\\n" "$2"');
21新增: await command('git',`if [[ "$*" == *' init '* ]];then mkdir -p "\${@: -1}/.git";fi
22新增: if [[ "$*" == *rev-parse* ]];then printf '${sha}\\n';fi
23新增: if [[ "$*" == *'submodule update'* ]];then for ((i=1;i<=$#;i++));do if [[ "\${!i}" == -C ]];then j=$((i+1));q="\${!j}";fi;done;mkdir -p "$q/roms/seabios";echo 'firmware code' > "$q/roms/seabios/code.c";echo 'gitdir: private' > "$q/roms/seabios/.git";fi
24新增: if [[ "$*" == *'submodule status'* ]];then printf ' ${sha} roms/seabios\\n';fi`);
25新增: await command('curl',`while [[ $# -gt 0 ]];do if [[ "$1" == -o ]];then shift;destination=$1;fi;shift;done;printf '${content.replaceAll('\n','\\n')}' > "$destination"`);
26新增: await command('pacman-key','printf "%s\\n" "$*" >> "$SOURCE_TEST_VERIFICATIONS"');
27新增: execFileSync('bash',[collector,repository,runtime,artifact],{env:{...process.env,PATH:bin+':'+process.env.PATH,SOURCE_TEST_VERIFICATIONS:join(root,'verified')},stdio:'pipe'});
28新增: const listing=execFileSync('tar',['-tzf',artifact],{encoding:'utf8'});
29新增: for(const path of ['source/firmware-revisions.txt','source/qemu/roms/seabios/code.c','source/packages/mingw-w64-fixture-1.2.3-1.src.tar.zst','source/cage/patches/fixture.patch','source/SHA256SUMS'])assert.ok(listing.includes(path),path);
30新增: assert.ok(!listing.includes('/.git'));
31新增: assert.ok((await readFile(join(root,'verified'),'utf8')).includes('--verify'));
32新增: const extract=join(root,'extracted');await mkdir(extract);execFileSync('tar',['-xzf',artifact,'-C',extract]);
33新增: execFileSync('shasum',['-a','256','-c','SHA256SUMS'],{cwd:join(extract,'source'),stdio:'pipe'});
34新增:});
修改scripts/check-release-readiness.mjs+0 −7看文件
@@ -2,7 +2,6 @@
22const required = [
33 'CAGE_MACOS_P12_BASE64', 'CAGE_MACOS_P12_PASSWORD', 'CAGE_MACOS_SIGNING_IDENTITY',
44 'CAGE_MACOS_NOTARY_KEY_BASE64', 'CAGE_MACOS_NOTARY_KEY_ID', 'CAGE_MACOS_NOTARY_ISSUER_ID',
5删除: 'CAGE_WINDOWS_QEMU_SOURCE_URL', 'CAGE_WINDOWS_QEMU_SOURCE_SHA256',
65];
76const provider = process.env.CAGE_WINDOWS_SIGNING_PROVIDER || 'certificate-store';
87if (provider === 'esigner') {
@@ -21,12 +20,6 @@ if (missing.length) {
2120 !/^[0-9a-f]{32,40}$/i.test(process.env.CAGE_ESIGNER_CERTIFICATE_SERIAL))) {
2221 throw new Error('Invalid eSigner credential ID or expected certificate serial.');
2322 }
24删除: let source;
25删除: try { source = new URL(process.env.CAGE_WINDOWS_QEMU_SOURCE_URL); }
26删除: catch { throw new Error('Reviewed QEMU source requires a valid public HTTPS URL.'); }
27删除: if (source.protocol !== 'https:' || source.username || source.password || source.search || source.hash || !/^[0-9a-f]{64}$/i.test(process.env.CAGE_WINDOWS_QEMU_SOURCE_SHA256)) {
28删除: throw new Error('Reviewed QEMU source requires a credential-free HTTPS URL and SHA-256.');
29删除: }
3023 if (!process.env.CAGE_MACOS_SIGNING_IDENTITY.startsWith('Developer ID Application:')) throw new Error('macOS releases require a Developer ID Application identity.');
3124 console.log('Release configuration is present. Platform jobs will verify the credentials, signatures and corresponding sources.');
3225}
修改scripts/ci-windows-build.ps1+10 −15看文件
@@ -29,21 +29,6 @@ try {
2929 } elseif (-not $env:CAGE_WINDOWS_PFX_BASE64 -or -not $env:CAGE_WINDOWS_PFX_PASSWORD) {
3030 throw 'Configure CAGE_WINDOWS_PFX_BASE64 and CAGE_WINDOWS_PFX_PASSWORD in the cage-release environment.'
3131 }
32删除: $sourceUri = $null
33删除: if (-not [Uri]::TryCreate($env:CAGE_WINDOWS_QEMU_SOURCE_URL, [UriKind]::Absolute, [ref]$sourceUri) -or
34删除: $sourceUri.Scheme -ne 'https' -or $sourceUri.UserInfo -or $sourceUri.Query -or $sourceUri.Fragment -or
35删除: $env:CAGE_WINDOWS_QEMU_SOURCE_SHA256 -notmatch '^[0-9A-Fa-f]{64}$') {
36删除: throw 'Configure CAGE_WINDOWS_QEMU_SOURCE_URL (HTTPS) and CAGE_WINDOWS_QEMU_SOURCE_SHA256 for the reviewed complete source archive.'
37删除: }
38删除: $extension = [IO.Path]::GetExtension($sourceUri.AbsolutePath).ToLowerInvariant()
39删除: if ($extension -notin @('.zip', '.7z', '.tar', '.gz', '.xz', '.bz2', '.zst')) {
40删除: throw 'The reviewed source URL must name a ZIP, 7z, tar or compressed tar archive.'
41删除: }
42删除: $qemuSource = Join-Path $env:RUNNER_TEMP ('qemu-windows-source-' + [guid]::NewGuid().ToString('N') + $extension)
43删除: Invoke-WebRequest -Uri $sourceUri -OutFile $qemuSource -TimeoutSec 600 -MaximumRedirection 5
44删除: if ((Get-FileHash -LiteralPath $qemuSource -Algorithm SHA256).Hash -ne $env:CAGE_WINDOWS_QEMU_SOURCE_SHA256) {
45删除: throw 'Reviewed corresponding-source archive checksum mismatch.'
46删除: }
4732 if ($env:CAGE_WINDOWS_SIGNING_PROVIDER -ne 'esigner') {
4833 $pfx = Join-Path $env:RUNNER_TEMP ('cage-signing-' + [guid]::NewGuid().ToString('N') + '.pfx')
4934 [IO.File]::WriteAllBytes($pfx, [Convert]::FromBase64String($env:CAGE_WINDOWS_PFX_BASE64))
@@ -67,6 +52,16 @@ try {
6752 $windowsPowerShell = Join-Path ([Environment]::SystemDirectory) 'WindowsPowerShell/v1.0/powershell.exe'
6853 & (Join-Path $PSScriptRoot 'test-windows-installation-files.ps1') -HelperShell $windowsPowerShell
6954 & (Join-Path $PSScriptRoot 'build-windows.ps1') -Release:$Release
55新增: if ($Release) {
56新增: $qemuSource = Join-Path $env:RUNNER_TEMP 'qemu-windows-full-source.tar.gz'
57新增: $savedMsystem, $savedChere = $env:MSYSTEM, $env:CHERE_INVOKING
58新增: try {
59新增: $env:MSYSTEM = 'UCRT64'; $env:CHERE_INVOKING = '1'
60新增: Invoke-BuildTool (Join-Path $env:CAGE_MSYS2_ROOT 'usr/bin/bash.exe') @('-l',
61新增: (Join-Path $PSScriptRoot 'bundle-qemu-sources.sh'), $repository,
62新增: (Join-Path $repository '_output/windows-deps/qemu-cage'), $qemuSource)
63新增: } finally { $env:MSYSTEM = $savedMsystem; $env:CHERE_INVOKING = $savedChere }
64新增: }
7065 if (-not $Release) {
7166 $windowsPowerShell = Join-Path ([Environment]::SystemDirectory) 'WindowsPowerShell/v1.0/powershell.exe'
7267 foreach ($test in @('install-guest-powershell.tests.ps1', 'windows-evaluation.tests.ps1')) {
修改scripts/package-windows.ps1+3 −2看文件
@@ -37,7 +37,7 @@ if ($signed) {
3737 if ($env:CAGE_WINDOWS_CERT_SHA1 -notmatch '^[0-9A-Fa-f]{40}$') { throw 'Build and verify the signed app before packaging.' }
3838 if (Test-Path -LiteralPath (Join-Path $AppDirectory 'DEVELOPMENT-BUILD.txt')) { throw 'Rebuild with build-windows.ps1 -Sign or -Release before packaging a signed installer.' }
3939 if ($Release -and (-not $QemuSourceArchive -or -not (Test-Path -LiteralPath $QemuSourceArchive -PathType Leaf))) {
40删除: throw 'Release packaging requires -QemuSourceArchive containing the corresponding patched QEMU and bundled library sources. A generic upstream QEMU tarball is not the source for the Weilnetz build.'
40新增: throw 'Release packaging requires -QemuSourceArchive containing the exact QEMU, firmware and linked library sources. Generate it from the built runtime with bundle-qemu-sources.sh.'
4141 }
4242 if ($Release) { Invoke-BuildTool $sevenZip @('t', '-bso0', '-bsp0', $QemuSourceArchive) }
4343 $signTool = Get-SigningTool
@@ -100,7 +100,8 @@ if (Test-Path (Join-Path $qemuRuntime 'cage-build.json')) {
100100 $releaseFiles += @($keymapSource, $changesSource)
101101}
102102if ($Release) {
103删除: $qemuSourceTarget = Join-Path $OutputDirectory ('qemu-' + $dependencies.qemu.version + '-windows-full-source' + [IO.Path]::GetExtension($QemuSourceArchive))
103新增: $sourceExtension = if ($QemuSourceArchive.EndsWith('.tar.gz', [StringComparison]::OrdinalIgnoreCase)) { '.tar.gz' } else { [IO.Path]::GetExtension($QemuSourceArchive) }
104新增: $qemuSourceTarget = Join-Path $OutputDirectory ('qemu-' + $dependencies.qemu.version + '-windows-full-source' + $sourceExtension)
104105 Copy-Item -LiteralPath $QemuSourceArchive -Destination $qemuSourceTarget -Force
105106 $releaseFiles += $qemuSourceTarget
106107}
修改scripts/release-control.mjs+27 −3看文件
@@ -43,6 +43,17 @@ async function findRelease(api, base, tag) {
4343 }
4444}
4545
46新增:export async function releaseNotes(root, context) {
47新增: if (!context.notesPath) return '';
48新增: if (!/^docs\/(?:[A-Za-z0-9_.-]+\/)*[A-Za-z0-9_.-]+\.md$/.test(context.notesPath) || context.notesPath.split('/').some(part => part === '.' || part === '..')) {
49新增: throw new Error('Release notes must be a committed Markdown file under docs/.');
50新增: }
51新增: if (!shaPattern.test(context.sourceSha)) throw new Error('Invalid release notes source.');
52新增: const body = execFileSync('git', ['show', `${context.sourceSha}:${context.notesPath}`], { cwd: root, encoding: 'utf8', maxBuffer: 1 << 20 }).trim();
53新增: if (!body || Buffer.byteLength(body) > 100000) throw new Error('Release notes must contain 1–100000 UTF-8 bytes.');
54新增: return body;
55新增:}
56新增:
4657// Build expected version files from the immutable source commit, even when
4758// publish is checking out the candidate. This catches unrelated file edits.
4859export async function expectedFiles(root, sourceSha, version) {
@@ -82,6 +93,8 @@ export async function verifyCandidate(api, context, expected) {
8293
8394export async function prepareRelease({ api, root, ...context }) {
8495 checkContext(context);
96新增: if (context.requestedVersion) parseVersion(context.requestedVersion);
97新增: await releaseNotes(root, context);
8598 const base = apiRoot(context);
8699 const main = await api('GET', `${base}/git/ref/heads/${context.defaultBranch}`);
87100 const existing = await optional(api, `${base}/git/ref/heads/${branch(context.runId)}`);
@@ -89,6 +102,7 @@ export async function prepareRelease({ api, root, ...context }) {
89102 const commit = await api('GET', `${base}/git/commits/${existing.object.sha}`);
90103 const version = /^chore\(release\): v([^\n]+)\n\nCage-Release-Run: \d+$/.exec(commit.message)?.[1];
91104 parseVersion(version);
105新增: if (context.requestedVersion && context.requestedVersion !== version) throw new Error('Existing candidate uses another requested version.');
92106 if (main.object.sha !== context.sourceSha && main.object.sha !== existing.object.sha) throw new Error('Main advanced; start a new explicitly requested release.');
93107 const result = { ...context, version, commitSha: existing.object.sha };
94108 await verifyCandidate(api, result, await expectedFiles(root, context.sourceSha, version));
@@ -103,8 +117,16 @@ export async function prepareRelease({ api, root, ...context }) {
103117 reserved.push(...releases.map(release => release.tag_name));
104118 if (releases.length < 100) break;
105119 }
106删除: const version = nextVersion(current, context.bump, reserved);
120新增: const version = context.requestedVersion || nextVersion(current, context.bump, reserved);
107121 if (compareVersions(version, current) <= 0) throw new Error('Release version must advance.');
122新增: if (context.requestedVersion) {
123新增: for (const tag of reserved) {
124新增: if (!tag.startsWith('v')) continue;
125新增: let previous;
126新增: try { previous = parseVersion(tag.slice(1)); } catch { continue; }
127新增: if (previous && compareVersions(version, tag.slice(1)) <= 0) throw new Error('Requested release version must exceed all reserved versions.');
128新增: }
129新增: }
108130 // Tags and draft Releases reserve their version. Never reuse someone else's draft.
109131 if (await findRelease(api, base, `v${version}`)) throw new Error(`Release v${version} is already reserved.`);
110132 const files = await expectedFiles(root, context.sourceSha, version);
@@ -175,6 +197,7 @@ function assertAssets(assets, files) {
175197
176198export async function publishRelease({ api, upload, promote, root, files, ...context }) {
177199 checkContext(context);
200新增: const customNotes = await releaseNotes(root, context);
178201 await verifyCandidate(api, context, await expectedFiles(root, context.sourceSha, context.version));
179202 const base = apiRoot(context);
180203 const main = await api('GET', `${base}/git/ref/heads/${context.defaultBranch}`);
@@ -192,11 +215,11 @@ export async function publishRelease({ api, upload, promote, root, files, ...con
192215 }
193216 await promote(context); // Atomic, fast-forward-only main + tag; never force-push.
194217 if (!release) {
195删除: const notes = await api('POST', `${base}/releases/generate-notes`, { tag_name: `v${context.version}`, target_commitish: context.commitSha });
218新增: const notes = customNotes ? { body: customNotes } : await api('POST', `${base}/releases/generate-notes`, { tag_name: `v${context.version}`, target_commitish: context.commitSha });
196219 release = await api('POST', `${base}/releases`, {
197220 tag_name: `v${context.version}`, target_commitish: context.commitSha,
198221 name: `Cage ${context.version}`, draft: true, prerelease: context.version.includes('-'),
199删除: body: `${marker(context)}\n\n${notes.body || ''}\n\nThree platform builds, package verification and automated checks completed for ${context.commitSha}. Hardware virtualization and real Claude account acceptance are separate checks; see the platform guides.`,
222新增: body: `${marker(context)}\n\n${notes.body || ''}${customNotes ? '' : `\n\nThree platform builds, package verification and automated checks completed for ${context.commitSha}. Hardware virtualization and real Claude account acceptance are separate checks; see the platform guides.`}`,
200223 });
201224 }
202225 const assets = await api('GET', `${base}/releases/${release.id}/assets?per_page=100`);
@@ -220,6 +243,7 @@ export function workflowContext(env, event) {
220243 repository: env.GITHUB_REPOSITORY, sourceSha: env.RELEASE_SOURCE_SHA || env.GITHUB_SHA,
221244 runId: env.GITHUB_RUN_ID, defaultBranch: event.repository?.default_branch, bump: event.inputs?.bump,
222245 version: env.RELEASE_VERSION, commitSha: env.RELEASE_COMMIT_SHA,
246新增: requestedVersion: event.inputs?.version?.replace(/^v/, '') || undefined, notesPath: event.inputs?.notes_path || undefined,
223247 };
224248 checkContext(context);
225249 if (env.GITHUB_ACTIONS !== 'true' || env.GITHUB_EVENT_NAME !== 'workflow_dispatch' || env.GITHUB_REF !== 'refs/heads/main') {
修改scripts/release-control.test.mjs+37 −1看文件
@@ -7,7 +7,7 @@ import { dirname, join } from 'node:path';
77import test from 'node:test';
88import {
99 assembleRelease, expectedFiles, prepareRelease, publishRelease, releaseFiles,
10删除: verifyCandidate, versionPaths, workflowContext,
10新增: verifyCandidate, versionPaths, workflowContext, releaseNotes,
1111} from './release-control.mjs';
1212
1313const repository = 'Lee-xeo/Claude-Cage';
@@ -194,6 +194,42 @@ test('prepare leaves the working version unchanged and reuses the same run candi
194194 assert.equal(f.state.calls.filter(call => call.method === 'POST' && call.path.endsWith('/git/commits')).length, 1);
195195});
196196
197新增:test('exact requested version is retained on preparation and resume, with reserved versions rejected', async t => {
198新增: const f = await repositoryFixture(t);
199新增: f.context.requestedVersion = '99.1.0-rc.1';
200新增: const first = await f.candidate();
201新增: assert.equal(first.version, '99.1.0-rc.1');
202新增: assert.equal((await f.candidate()).commitSha, first.commitSha);
203新增: f.context.requestedVersion = '99.1.0-rc.2';
204新增: await assert.rejects(f.candidate(), /another requested version/);
205新增: const reserved = await repositoryFixture(t);
206新增: reserved.context.requestedVersion = '99.1.0-rc.1';
207新增: reserved.state.otherReleases.push({ tag_name: 'v99.1.0-rc.1', draft: true });
208新增: await assert.rejects(reserved.candidate(), /reserved/);
209新增: assert.equal(reserved.state.calls.some(call => call.method !== 'GET'), false);
210新增:});
211新增:
212新增:test('custom release notes come from the immutable source and are published with RC status', async t => {
213新增: const f = await repositoryFixture(t);
214新增: f.context.notesPath = 'docs/releases/v99.1.0-rc.1.md';
215新增: await mkdir(join(f.root, 'docs/releases'), { recursive: true });
216新增: await writeFile(join(f.root, f.context.notesPath), '# 本轮更新\n\n功能与已验证范围。\n');
217新增: f.git(['add', f.context.notesPath]);
218新增: f.git(['commit', '--quiet', '-m', 'Public release notes']);
219新增: f.context.sourceSha = f.state.main = f.git(['rev-parse', 'HEAD']);
220新增: f.context.requestedVersion = '99.1.0-rc.1';
221新增: const candidate = await f.candidate();
222新增: await writeFile(join(f.root, f.context.notesPath), 'Concurrent local draft, must not be published.');
223新增: const files = await uploadFiles(f.root, candidate.version);
224新增: const release = await publish(f, candidate, files);
225新增: assert.equal(release.prerelease, true);
226新增: assert.ok(release.body.endsWith('# 本轮更新\n\n功能与已验证范围。'));
227新增: assert.equal(f.state.calls.some(call => call.path.endsWith('/generate-notes')), false);
228新增: for (const notesPath of ['../private.md', 'docs/../private.md', '/docs/notes.md', 'docs/notes.txt']) {
229新增: await assert.rejects(releaseNotes(f.root, { ...candidate, notesPath }), /committed Markdown/);
230新增: }
231新增:});
232新增:
197233test('main movement prevents candidate creation and later publication', async t => {
198234 const f = await repositoryFixture(t);
199235 f.state.main = 'b'.repeat(40);