diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 785e22b66e..16e658f8f3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,6 +37,7 @@ jobs: scripts: ${{ steps.groups.outputs.scripts }} macos_scripts: ${{ steps.groups.outputs.macos_scripts }} dependencies: ${{ steps.groups.outputs.dependencies }} + platforms: ${{ steps.groups.outputs.platforms }} steps: - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 with: @@ -121,30 +122,7 @@ jobs: shell: powershell env: CACHE_STAMP: ${{ hashFiles('rust-toolchain.toml') }}-${{ env.CARGO_PROFILE_DEV_DEBUG }} - run: | - $targetDir = [System.IO.Path]::GetFullPath($env:CARGO_TARGET_DIR) - $stampFile = Join-Path $targetDir '.cache-stamp' - $maxBytes = 12GB - $reset = $false - if (Test-Path $targetDir) { - $current = if (Test-Path $stampFile) { (Get-Content -Raw $stampFile).Trim() } else { '' } - if ($current -ne $env:CACHE_STAMP) { - Write-Output 'Resetting Windows target cache (toolchain or profile stamp changed).' - $reset = $true - } else { - $bytes = (Get-ChildItem -LiteralPath $targetDir -Recurse -File -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum - if ($bytes -gt $maxBytes) { - Write-Output "Resetting Windows target cache ($([math]::Round($bytes / 1GB, 2)) GiB exceeded 12 GiB budget)." - $reset = $true - } - } - } - if ($reset) { - Remove-Item -LiteralPath $targetDir -Recurse -Force - } - New-Item -ItemType Directory -Path $targetDir -Force | Out-Null - Set-Content -LiteralPath $stampFile -Value $env:CACHE_STAMP -NoNewline - "CARGO_TARGET_DIR=$targetDir" >> $env:GITHUB_ENV + run: '& "$env:GITHUB_WORKSPACE\scripts\ci-windows-target.ps1"' - name: Verify native Windows CLI boundaries run: cargo test --locked -p dim-cli --lib - uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0 @@ -163,30 +141,7 @@ jobs: CMAKE_SHA256: 'd163cd3ab4959b0a53fa8988f2ddbd2e6c501658201e6a154386bad9dbe4f836' NASM_VERSION: '2.16.03' NASM_SHA256: '3ee4782247bcb874378d02f7eab4e294a84d3d15f3f6ee2de2f47a46aa7226e6' - run: | - $ProgressPreference = 'SilentlyContinue' - function Add-PortableTool { - param([string]$Name, [string]$Version, [string]$Sha256, [string]$Url, [string]$VersionFlag) - if (Get-Command $Name -ErrorAction SilentlyContinue) { - Write-Output "Using the $Name already on PATH" - return - } - $archive = Join-Path $env:RUNNER_TEMP "$Name-$Version.zip" - Invoke-WebRequest -Uri $Url -OutFile $archive -UseBasicParsing - $actual = (Get-FileHash -Algorithm SHA256 -LiteralPath $archive).Hash.ToLowerInvariant() - if ($actual -ne $Sha256) { throw "$Name sha256 $actual does not match $Sha256" } - $directory = Join-Path $env:RUNNER_TEMP "dim-windows-native-$Name-$Version" - if (Test-Path $directory) { Remove-Item -LiteralPath $directory -Recurse -Force } - Expand-Archive -LiteralPath $archive -DestinationPath $directory -Force - $executable = Get-ChildItem -LiteralPath $directory -Recurse -File -Filter "$Name.exe" | Select-Object -First 1 - if (-not $executable) { throw "$Name archive holds no $Name.exe" } - [System.IO.File]::AppendAllText($env:GITHUB_PATH, "$($executable.DirectoryName)`n") - & $executable.FullName $VersionFlag - if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } - Write-Output "Provisioned $Name $Version from $Url" - } - Add-PortableTool -Name 'cmake' -Version $env:CMAKE_VERSION -Sha256 $env:CMAKE_SHA256 -Url "https://github.com/Kitware/CMake/releases/download/v$env:CMAKE_VERSION/cmake-$env:CMAKE_VERSION-windows-x86_64.zip" -VersionFlag '--version' - Add-PortableTool -Name 'nasm' -Version $env:NASM_VERSION -Sha256 $env:NASM_SHA256 -Url "https://www.nasm.us/pub/nasm/releasebuilds/$env:NASM_VERSION/win64/nasm-$env:NASM_VERSION-win64.zip" -VersionFlag '-v' + run: '& "$env:GITHUB_WORKSPACE\scripts\ci-windows-native-tools.ps1"' - name: Verify native Windows boundary flows # Scheduled sweeps select every check group, so they run these flows too. if: needs.changes.outputs.windows_native == 'true' @@ -206,29 +161,7 @@ jobs: node-version-file: .node-version package-manager-cache: false - name: Build and test the Web workspace - run: | - $declarations = 'web/src/auto-imports.d.ts', 'web/src/components.d.ts' - $original = @{} - foreach ($file in $declarations) { - $original[$file] = (Get-Content -Raw -Encoding UTF8 $file).Replace("`r`n", "`n") - } - $version = node -p "require('./npm/package.json').version" - if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } - $env:Path = "$env:WINDIR\System32;$env:Path" - node scripts/stage-web.mjs staging/release-web $version $env:GITHUB_SHA - if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } - $notices = tar.exe -xOzf "staging/release-web/dimcode-web-$version.tar.gz" dimcode-web/web/THIRD-PARTY-NOTICES.txt - if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } - foreach ($package in 'vue', 'vue-router', 'pinia') { - $entry = $notices -cmatch "^${package}@" - if (-not $entry) { throw "Missing third-party notice for $package" } - Write-Output $entry - } - foreach ($file in $declarations) { - if ((Get-Content -Raw -Encoding UTF8 $file).Replace("`r`n", "`n") -cne $original[$file]) { - throw "Generated declaration changed: $file" - } - } + run: '& "$env:GITHUB_WORKSPACE\scripts\ci-web-check.ps1"' - name: Test the Web workspace run: npm.cmd test --prefix web - name: Test the chat-ui package @@ -272,7 +205,7 @@ jobs: strategy: fail-fast: false matrix: - platform: ${{ fromJSON(github.event_name == 'pull_request' && '["linux"]' || github.event_name == 'push' && '["macos"]' || '["linux","macos"]') }} + platform: ${{ fromJSON(needs.changes.outputs.platforms) }} runs-on: ${{ matrix.platform == 'linux' && fromJSON('["self-hosted","linux","x64","dim-verify"]') || fromJSON('["self-hosted","macOS","ARM64"]') }} timeout-minutes: 75 env: @@ -323,6 +256,11 @@ jobs: cargo build --locked -p xtask fi target/debug/xtask check + - name: Derive test concurrency + if: needs.changes.outputs.rust == 'true' + id: concurrency + shell: bash + run: node scripts/ci-test-concurrency.mjs >> "$GITHUB_OUTPUT" - name: Run compiled workspace tests if: needs.changes.outputs.rust == 'true' shell: bash @@ -330,33 +268,8 @@ jobs: DIM_TEST_TIMEOUT_MS: "900000" run: | set -euo pipefail - if [[ "$RUNNER_OS" == Linux ]]; then - cpus=$(nproc) - # Runner hosts may share their physical cores between instances and - # report SMT siblings as CPUs; scale by the cores this job can use. - if command -v lscpu >/dev/null; then - cores=$(lscpu -p=Core,Socket | grep -v '^#' | sort -u | wc -l) - logical=$(lscpu -p=CPU | grep -vc '^#') - (( cores > 0 )) || cores=1 - smt=$(( logical / cores )) - (( smt < 1 )) && smt=1 - physical=$(( cpus / smt )) - else - physical=$cpus - fi - (( physical < 1 )) && physical=1 - test_jobs=$(( physical / 3 )) - (( test_jobs < 3 )) && test_jobs=3 - (( test_jobs > 8 )) && test_jobs=8 - test_threads=$(( physical / 4 )) - (( test_threads < 2 )) && test_threads=2 - (( test_threads > 6 )) && test_threads=6 - else - test_jobs=3 - test_threads=3 - fi - echo "Workspace tests: DIM_TEST_JOBS=$test_jobs --test-threads=$test_threads" - DIM_TEST_JOBS="$test_jobs" node scripts/run-rust-test.mjs target/test-artifacts.jsonl --workspace "--test-threads=$test_threads" + echo "Workspace tests: DIM_TEST_JOBS=${{ steps.concurrency.outputs.jobs }} --test-threads=${{ steps.concurrency.outputs.threads }}" + DIM_TEST_JOBS='${{ steps.concurrency.outputs.jobs }}' node scripts/run-rust-test.mjs target/test-artifacts.jsonl --workspace "--test-threads=${{ steps.concurrency.outputs.threads }}" cargo test --workspace --doc --locked ${{ needs.changes.outputs.eval == 'true' && '--features xtask/eval-tests' || '' }} - name: Verify debug-only CLI tests if: needs.changes.outputs.debug == 'true' diff --git a/docs/architecture/build.md b/docs/architecture/build.md index 781d14ce9a..e4ddcecf88 100644 --- a/docs/architecture/build.md +++ b/docs/architecture/build.md @@ -332,12 +332,12 @@ Per [ADR 026](../adr/026-verification-tiers-and-ci-governance.md) D4, synchronou | `changes` (routing + ADR freeze) | L1 | Self-hosted | ≤ 1 min | 5 min | Shallow fetch (`depth=2`), Node only | | `dependencies` (`cargo-deny`) | L1 | Self-hosted Windows x64 | ≤ 2 min | 15 min | `cargo install --jobs 2` on miss | | `web` (stage + test + lint + build) | L1 / L2 | Self-hosted Windows x64 | ≤ 5 min | 15 min | Isolated npm workspace check | -| `windows-cli` (`dim-cli --lib`, native flows) | L3 | Self-hosted Windows x64 | `dim-cli --lib`: ≤ 1 min warm (≤ 4 min cold); native flows: not yet measured | 15 min | Per-runner target dir capped at 12 GiB | +| `windows-cli` (`dim-cli --lib`, native flows) | L3 | Self-hosted Windows x64 | `dim-cli --lib`: ≤ 1 min warm (≤ 4 min cold); native flows: 1.1–4.4 min across 25 runs, p90 pending | 15 min | Per-runner target dir capped at 12 GiB | | `macos-native` (macOS Rust + packaging) | L3 | Self-hosted macOS ARM64 | ≤ 6 min | 30 min | `CARGO_BUILD_JOBS=4`, checkout `target/` | -| `verify (linux)` (build + clippy + tests) | L1 / L2 / L3 | Self-hosted Linux x64 (`dim-verify`) | ≤ 15 min target (steady state not yet measured at these settings) | 75 min | `CARGO_BUILD_JOBS=8`, `CARGO_PROFILE_DEV_DEBUG=0`, CPU-scaled `DIM_TEST_JOBS` / `--test-threads`, 15 min target cap | +| `verify (linux)` (build + clippy + tests) | L1 / L2 / L3 | Self-hosted Linux x64 (`dim-verify`) | ≤ 15 min target (four post-change runs 8m12s–14m18s; p90 pending) | 75 min | `CARGO_BUILD_JOBS=8`, `CARGO_PROFILE_DEV_DEBUG=0`, CPU-scaled `DIM_TEST_JOBS` / `--test-threads`, 15 min target cap | | `code-layout` (native layout matrix) | L3 | Hosted Linux, macOS, Windows | Not yet recorded | 10 / 30 / 240 min per job | Hosted runners; `native-layout` runs on layout changes | -The `verify (linux)` row records a target rather than a measurement: no full green run exists at these settings yet. The last six full runs on the `dim-verify` pool before this change completed in 18m17s (44724315336), 21m18s (44722644428), 23m42s (44719273152), 21m29s (44718768375), 30m49s (44717853591) and 25m38s (44716244403). Record the new steady state once a full green run at these settings completes. +The `verify (linux)` row is measured from full runs on the `dim-verify` pool: 8m12s (45931687899), 11m24s (45932777661), 11m48s (45932038211) and 14m18s (45933158819), against 18m17s–30m49s in the six runs recorded before the CPU-scaled test settings (44724315336, 44722644428, 44719273152, 44718768375, 44717853591, 44716244403). p90 is not recorded yet; it needs ten green runs spanning both group selections. Approaching or exceeding a steady-state budget is treated as a regression and resolved by narrowing path scope, optimizing slow tests, improving parallelism or demoting heavy cases to Retained — never by raising job or target timeouts alone. Any change that adds a required PR check or widens path selection must disclose its incremental wall-clock cost, added compile dependencies and target runner pool. @@ -349,7 +349,7 @@ The root `./dev` entry performs incremental CLI/App Server builds without disabl The [Web workspace](../design/web-workspace.md) frontend in `web/` is a separate artifact (`scripts/stage-web.mjs` builds it; the CLI finds the installed `dimcode-web` package or a `web/` directory beside the executable or in the product home, or `DIMCODE_WEB_ASSETS` names one), so building `dim-app-server` and `dimcode` needs neither Node nor npm. Only `cargo build --features embedded-web` compiles the frontend in; then `build.rs` runs `npm ci` and `npm run build` when that frontend changed, and a host without npm fails the build. Otherwise Node is only needed for packaging, packaging checks and TypeScript plugin execution/development. `.node-version` pins the Node version bundled into account-enabled releases. The `runtime/package-lock.json` fixes the rutis Node runtime and its transitive dependencies; `npm ci --ignore-scripts --prefix runtime` installs them for local bridge testing. -Pull requests run workspace verification on self-hosted Linux x64 runners labelled `dim-verify`, with eight Cargo build jobs. The job checks that bubblewrap can create the sandbox the confined tests use (a user namespace with a private `/proc`) before running them. The macOS ARM64 runners use four Cargo jobs for the native Rust checks on pull requests and for full workspace verification on `main`. Use `node scripts/test-macos-native.mjs --list` to inspect the Rust selection from the current Cargo targets, Rust platform guards and host-specific test fixtures. On an Apple Silicon Mac, run `node scripts/test-macos-native.mjs` to build those targets and check each selected name against its compiled test binary before execution. Tests marked for manual execution keep their normal ignore status. The [workflow guide](../release/README.md#github-workflows) describes path selection, native packaging checks and manual dispatch. The separate `windows-cli` job runs the `dim-cli` library tests on a self-hosted Windows x64 runner, where its fixture writes to the clipboard. When a pull request changes Windows storage, host-platform, named-pipe or worktree-removal paths, when a push to `main` changes a path that selects the job, and on scheduled sweeps and manual dispatch, the same job also builds and runs the Windows-only boundary flows (`file_storage_flow`'s Windows checks, `host_platform_windows_flow`, `named_pipe_flow` and `worktree_removal_flow`) in that directory; `node scripts/test-windows-native.mjs --list` prints the selection and a run checks every selected name against its compiled test binary. The job keeps its fifteen-minute hard timeout, and the first cold compile of the `dim-app-server` graph that the step adds may not fit it; no run has measured that yet and it cannot be reproduced locally. The layout workflow uses hosted `windows-2022` and `windows-11-arm` runners, with Python 3.13 and the pinned native MSVC Rust host toolchain provisioned explicitly. Release builds use GitHub-hosted VMs matching each target OS and CPU. See the [runner setup and release matrix](../release/README.md#runner-setup). +Pull requests run workspace verification on self-hosted Linux x64 runners labelled `dim-verify`, with eight Cargo build jobs. The job checks that bubblewrap can create the sandbox the confined tests use (a user namespace with a private `/proc`) before running them. The macOS ARM64 runners use four Cargo jobs for the native Rust checks on pull requests and for full workspace verification on `main`. Use `node scripts/test-macos-native.mjs --list` to inspect the Rust selection from the current Cargo targets, Rust platform guards and host-specific test fixtures. On an Apple Silicon Mac, run `node scripts/test-macos-native.mjs` to build those targets and check each selected name against its compiled test binary before execution. Tests marked for manual execution keep their normal ignore status. The [workflow guide](../release/README.md#github-workflows) describes path selection, native packaging checks and manual dispatch. The separate `windows-cli` job runs the `dim-cli` library tests on a self-hosted Windows x64 runner, where its fixture writes to the clipboard. When a pull request changes Windows storage, host-platform, named-pipe or worktree-removal paths, when a push to `main` changes a path that selects the job, and on scheduled sweeps and manual dispatch, the same job also builds and runs the Windows-only boundary flows (`file_storage_flow`'s Windows checks, `host_platform_windows_flow`, `named_pipe_flow` and `worktree_removal_flow`) in that directory; `node scripts/test-windows-native.mjs --list` prints the selection and a run checks every selected name against its compiled test binary. The job keeps its fifteen-minute hard timeout. Across 25 sampled runs the whole job took 2.2–6.8 minutes and the native-flows step 1.1–4.4 minutes, so the compile that the step adds fits the budget. The layout workflow uses hosted `windows-2022` and `windows-11-arm` runners, with Python 3.13 and the pinned native MSVC Rust host toolchain provisioned explicitly. Release builds use GitHub-hosted VMs matching each target OS and CPU. See the [runner setup and release matrix](../release/README.md#runner-setup). The macOS clipboard flows use private pasteboards and serialize access to the shared pasteboard server; other tests remain parallel. diff --git a/scripts/ci-changes.mjs b/scripts/ci-changes.mjs index d6b95c4aaf..c426d1ad15 100644 --- a/scripts/ci-changes.mjs +++ b/scripts/ci-changes.mjs @@ -46,6 +46,10 @@ const rules=[ [/^scripts\/run-rust-test\.mjs$/,groups], [/^scripts\/test-macos-native(?:\.test)?\.mjs$/,['rust','scripts']], [/^scripts\/stage-web\.mjs$/,['scripts','web']], + [/^scripts\/ci-test-concurrency\.mjs$/,['rust','scripts']], + [/^scripts\/ci-web-check\.ps1$/,['scripts','web']], + [/^scripts\/ci-windows-target\.ps1$/,['scripts','windows']], + [/^scripts\/ci-windows-native-tools\.ps1$/,['scripts','windows','windows_native']], [/^scripts\/(code-layout\/|code-layout-darwin\.test\.mjs$)/,['scripts','macos_scripts']], [/^scripts\/(stage-release|pack-release|native-binary|store-formats|release\.test)\.mjs$/,['scripts','macos_scripts']], [/^scripts\//,['scripts']], @@ -77,6 +81,14 @@ const rules=[ [/^(crates|tests|vendor|runtime|npm)\//,['rust','node']], ]; +// The platforms full verification runs on for an event: pull requests verify +// Linux, a `main` push verifies macOS, and a sweep or manual run covers both. +export function platforms(event) { + if (event === 'pull_request') return ['linux']; + if (event === 'push') return ['macos']; + return ['linux', 'macos']; +} + export function classify(files) { const needed=new Set(); for (const file of files) { @@ -120,5 +132,5 @@ if (import.meta.main) { } const lines=Object.entries(result).map(([group,value])=>`${group}=${value}`); console.log(lines.join('\n')); - if (process.env.GITHUB_OUTPUT) appendFileSync(process.env.GITHUB_OUTPUT,lines.join('\n')+'\n'); + if(process.env.GITHUB_OUTPUT) appendFileSync(process.env.GITHUB_OUTPUT,`${lines.join('\n')}\nplatforms=${JSON.stringify(platforms(process.env.GITHUB_EVENT_NAME))}\n`); } diff --git a/scripts/ci-changes.test.mjs b/scripts/ci-changes.test.mjs index 8545933208..ab66a06803 100644 --- a/scripts/ci-changes.test.mjs +++ b/scripts/ci-changes.test.mjs @@ -5,7 +5,7 @@ import os from 'node:os'; import path from 'node:path'; import {test} from 'node:test'; import {pathToFileURL} from 'node:url'; -import {classify,groups} from './ci-changes.mjs'; +import {classify,groups,platforms} from './ci-changes.mjs'; const only=(...names)=>Object.fromEntries(groups.map(group=>[group,names.includes(group)])); const hasGit=spawnSync('git',['--version']).status===0; @@ -229,3 +229,25 @@ test('main push checks use the whole push range in a shallow checkout',{skip:!ha assert.equal(clientPush.windows,true,'a push changing crates/dim-client/src/lib.rs keeps Windows verification'); assert.deepEqual(clientPush,only(...groups),'code pushes keep the full main run until the scheduled sweep is verified'); }); + +test('the moved job scripts select the jobs that run them', () => { + assert.deepEqual( + classify(['scripts/ci-test-concurrency.mjs']), + only('rust', 'scripts'), + 'the helper runs in the verify step that hands it the workspace job', + ); + assert.deepEqual(classify(['scripts/ci-web-check.ps1']), only('scripts', 'web')); + assert.deepEqual(classify(['scripts/ci-windows-target.ps1']), only('scripts', 'windows')); + assert.deepEqual( + classify(['scripts/ci-windows-native-tools.ps1']), + only('scripts', 'windows', 'windows_native'), + 'the tools step only runs for a windows_native change', + ); +}); + +test('each event verifies its own platforms', () => { + assert.deepEqual(platforms('pull_request'), ['linux'], 'a pull request verifies the primary platform'); + assert.deepEqual(platforms('push'), ['macos'], 'a main push verifies the secondary platform'); + assert.deepEqual(platforms('schedule'), ['linux', 'macos'], 'a sweep verifies both'); + assert.deepEqual(platforms('workflow_dispatch'), ['linux', 'macos'], 'a manual run verifies both'); +}); diff --git a/scripts/ci-test-concurrency.mjs b/scripts/ci-test-concurrency.mjs new file mode 100644 index 0000000000..3f619c74d1 --- /dev/null +++ b/scripts/ci-test-concurrency.mjs @@ -0,0 +1,31 @@ +import {execFileSync} from 'node:child_process'; +import {availableParallelism} from 'node:os'; + +// The workspace test plan: runner hosts may share their physical cores +// between instances and report SMT siblings as CPUs, so the plan scales by +// the cores this job can use instead of its CPU count. +export function plan(platform,cpus,cores,logical){ + if(platform!=='linux') return {jobs:3,threads:3}; + const smt=Math.max(1,Math.floor(logical/Math.max(1,cores))); + const physical=Math.max(1,Math.floor(cpus/smt)); + return { + jobs:Math.min(8,Math.max(3,Math.floor(physical/3))), + threads:Math.min(6,Math.max(2,Math.floor(physical/4))), + }; +} + +function topology(args){ + try{ + return execFileSync('lscpu',args,{encoding:'utf8'}).split('\n').filter(line=>line&&!line.startsWith('#')); + }catch{ + return []; + } +} + +if(import.meta.main){ + const cores=new Set(topology(['-p=Core,Socket'])).size; + const logical=topology(['-p=CPU']).length; + const {jobs,threads}=plan(process.platform,availableParallelism(),cores,logical); + console.log(`jobs=${jobs}`); + console.log(`threads=${threads}`); +} diff --git a/scripts/ci-test-concurrency.test.mjs b/scripts/ci-test-concurrency.test.mjs new file mode 100644 index 0000000000..6f0ff7807e --- /dev/null +++ b/scripts/ci-test-concurrency.test.mjs @@ -0,0 +1,34 @@ +import assert from 'node:assert/strict'; +import {spawnSync} from 'node:child_process'; +import {test} from 'node:test'; +import {plan} from './ci-test-concurrency.mjs'; + +test('the plan scales by physical cores', () => { + assert.deepEqual(plan('linux', 32, 16, 32), {jobs: 5, threads: 4}, 'sixteen physical cores'); + assert.deepEqual(plan('linux', 8, 8, 8), {jobs: 3, threads: 2}, 'no SMT siblings'); + assert.deepEqual(plan('linux', 64, 32, 64), {jobs: 8, threads: 6}, 'the upper clamps'); +}); + +test('the plan falls back to the CPU count without a topology', () => { + assert.deepEqual(plan('linux', 16, 0, 0), {jobs: 5, threads: 4}); + assert.deepEqual(plan('linux', 4, 0, 0), {jobs: 3, threads: 2}); +}); + +test('the plan holds the macOS settings on other platforms', () => { + assert.deepEqual(plan('darwin', 32, 16, 32), {jobs: 3, threads: 3}); +}); + +test('the command writes the outputs the job hands to the test runner', () => { + const run = spawnSync(process.execPath, ['scripts/ci-test-concurrency.mjs'], {encoding: 'utf8'}); + assert.equal(run.status, 0, run.stderr); + const lines = run.stdout.trim().split('\n'); + assert.deepEqual( + lines.map((line) => line.split('=')[0]), + ['jobs', 'threads'], + 'the step writes exactly the two outputs it hands on', + ); + const [, jobs] = lines[0].match(/^jobs=(\d+)$/) ?? []; + const [, threads] = lines[1].match(/^threads=(\d+)$/) ?? []; + assert.ok(Number(jobs) >= 3 && Number(jobs) <= 8, lines[0]); + assert.ok(Number(threads) >= 2 && Number(threads) <= 6, lines[1]); +}); diff --git a/scripts/ci-web-check.ps1 b/scripts/ci-web-check.ps1 new file mode 100644 index 0000000000..21da9c2ee4 --- /dev/null +++ b/scripts/ci-web-check.ps1 @@ -0,0 +1,22 @@ +$declarations = 'web/src/auto-imports.d.ts', 'web/src/components.d.ts' +$original = @{} +foreach ($file in $declarations) { + $original[$file] = (Get-Content -Raw -Encoding UTF8 $file).Replace("`r`n", "`n") +} +$version = node -p "require('./npm/package.json').version" +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } +$env:Path = "$env:WINDIR\System32;$env:Path" +node scripts/stage-web.mjs staging/release-web $version $env:GITHUB_SHA +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } +$notices = tar.exe -xOzf "staging/release-web/dimcode-web-$version.tar.gz" dimcode-web/web/THIRD-PARTY-NOTICES.txt +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } +foreach ($package in 'vue', 'vue-router', 'pinia') { + $entry = $notices -cmatch "^${package}@" + if (-not $entry) { throw "Missing third-party notice for $package" } + Write-Output $entry +} +foreach ($file in $declarations) { + if ((Get-Content -Raw -Encoding UTF8 $file).Replace("`r`n", "`n") -cne $original[$file]) { + throw "Generated declaration changed: $file" + } +} diff --git a/scripts/ci-windows-native-tools.ps1 b/scripts/ci-windows-native-tools.ps1 new file mode 100644 index 0000000000..e1cd10cc1a --- /dev/null +++ b/scripts/ci-windows-native-tools.ps1 @@ -0,0 +1,23 @@ +$ProgressPreference = 'SilentlyContinue' +function Add-PortableTool { + param([string]$Name, [string]$Version, [string]$Sha256, [string]$Url, [string]$VersionFlag) + if (Get-Command $Name -ErrorAction SilentlyContinue) { + Write-Output "Using the $Name already on PATH" + return + } + $archive = Join-Path $env:RUNNER_TEMP "$Name-$Version.zip" + Invoke-WebRequest -Uri $Url -OutFile $archive -UseBasicParsing + $actual = (Get-FileHash -Algorithm SHA256 -LiteralPath $archive).Hash.ToLowerInvariant() + if ($actual -ne $Sha256) { throw "$Name sha256 $actual does not match $Sha256" } + $directory = Join-Path $env:RUNNER_TEMP "dim-windows-native-$Name-$Version" + if (Test-Path $directory) { Remove-Item -LiteralPath $directory -Recurse -Force } + Expand-Archive -LiteralPath $archive -DestinationPath $directory -Force + $executable = Get-ChildItem -LiteralPath $directory -Recurse -File -Filter "$Name.exe" | Select-Object -First 1 + if (-not $executable) { throw "$Name archive holds no $Name.exe" } + [System.IO.File]::AppendAllText($env:GITHUB_PATH, "$($executable.DirectoryName)`n") + & $executable.FullName $VersionFlag + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + Write-Output "Provisioned $Name $Version from $Url" +} +Add-PortableTool -Name 'cmake' -Version $env:CMAKE_VERSION -Sha256 $env:CMAKE_SHA256 -Url "https://github.com/Kitware/CMake/releases/download/v$env:CMAKE_VERSION/cmake-$env:CMAKE_VERSION-windows-x86_64.zip" -VersionFlag '--version' +Add-PortableTool -Name 'nasm' -Version $env:NASM_VERSION -Sha256 $env:NASM_SHA256 -Url "https://www.nasm.us/pub/nasm/releasebuilds/$env:NASM_VERSION/win64/nasm-$env:NASM_VERSION-win64.zip" -VersionFlag '-v' diff --git a/scripts/ci-windows-target.ps1 b/scripts/ci-windows-target.ps1 new file mode 100644 index 0000000000..7f5cb607bd --- /dev/null +++ b/scripts/ci-windows-target.ps1 @@ -0,0 +1,23 @@ +$targetDir = [System.IO.Path]::GetFullPath($env:CARGO_TARGET_DIR) +$stampFile = Join-Path $targetDir '.cache-stamp' +$maxBytes = 12GB +$reset = $false +if (Test-Path $targetDir) { + $current = if (Test-Path $stampFile) { (Get-Content -Raw $stampFile).Trim() } else { '' } + if ($current -ne $env:CACHE_STAMP) { + Write-Output 'Resetting Windows target cache (toolchain or profile stamp changed).' + $reset = $true + } else { + $bytes = (Get-ChildItem -LiteralPath $targetDir -Recurse -File -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum + if ($bytes -gt $maxBytes) { + Write-Output "Resetting Windows target cache ($([math]::Round($bytes / 1GB, 2)) GiB exceeded 12 GiB budget)." + $reset = $true + } + } +} +if ($reset) { + Remove-Item -LiteralPath $targetDir -Recurse -Force +} +New-Item -ItemType Directory -Path $targetDir -Force | Out-Null +Set-Content -LiteralPath $stampFile -Value $env:CACHE_STAMP -NoNewline +"CARGO_TARGET_DIR=$targetDir" >> $env:GITHUB_ENV