|
| 1 | +[CmdletBinding()] |
| 2 | +param( |
| 3 | + [string]$Repository = 'ngallodev/codebase-memory-cli', |
| 4 | + [string]$ReleaseTag = '', |
| 5 | + [string]$Root = 'C:\cbm-benchmark', |
| 6 | + [int]$Repeats = 5 |
| 7 | +) |
| 8 | + |
| 9 | +$ErrorActionPreference = 'Stop' |
| 10 | +if ($PSVersionTable.PSVersion.Major -lt 7) { throw 'PowerShell 7 or newer is required' } |
| 11 | +foreach ($command in @('git.exe', 'python.exe')) { |
| 12 | + if (-not (Get-Command $command -ErrorAction SilentlyContinue)) { throw "$command is required" } |
| 13 | +} |
| 14 | + |
| 15 | +$stamp = [DateTime]::UtcNow.ToString('yyyyMMddTHHmmssZ') |
| 16 | +$runRoot = Join-Path $Root "run-$stamp" |
| 17 | +$sourceRoot = Join-Path $runRoot 'source' |
| 18 | +$artifactRoot = Join-Path $runRoot 'artifact' |
| 19 | +$installRoot = Join-Path $runRoot 'install' |
| 20 | +$workspaceRoot = Join-Path $runRoot 'repos' |
| 21 | +$resultsRoot = Join-Path $runRoot 'results' |
| 22 | +New-Item -ItemType Directory -Force $artifactRoot, $installRoot, $workspaceRoot, $resultsRoot | Out-Null |
| 23 | + |
| 24 | +$apiRoot = "https://api.github.com/repos/$Repository/releases" |
| 25 | +$release = if ($ReleaseTag) { |
| 26 | + Invoke-RestMethod -Uri "$apiRoot/tags/$ReleaseTag" -Headers @{ 'User-Agent' = 'codebase-memory-cli-benchmark' } |
| 27 | +} else { |
| 28 | + Invoke-RestMethod -Uri "$apiRoot/latest" -Headers @{ 'User-Agent' = 'codebase-memory-cli-benchmark' } |
| 29 | +} |
| 30 | +$ReleaseTag = [string]$release.tag_name |
| 31 | +if (-not $ReleaseTag) { throw 'GitHub release has no tag name' } |
| 32 | +$zipAsset = @($release.assets | Where-Object name -eq 'codebase-memory-cli-windows-amd64.zip') |
| 33 | +$sumAsset = @($release.assets | Where-Object name -eq 'checksums.txt') |
| 34 | +if ($zipAsset.Count -ne 1 -or $sumAsset.Count -ne 1) { throw "release $ReleaseTag is missing the Windows package or checksums.txt" } |
| 35 | +$zipPath = Join-Path $artifactRoot $zipAsset[0].name |
| 36 | +$sumPath = Join-Path $artifactRoot $sumAsset[0].name |
| 37 | +Invoke-WebRequest -Uri $zipAsset[0].browser_download_url -OutFile $zipPath |
| 38 | +Invoke-WebRequest -Uri $sumAsset[0].browser_download_url -OutFile $sumPath |
| 39 | +$publishedHash = (Select-String -LiteralPath $sumPath -Pattern "^([0-9A-Fa-f]{64})\s+\*?$([regex]::Escape($zipAsset[0].name))$").Matches | Select-Object -First 1 |
| 40 | +if (-not $publishedHash) { throw "checksums.txt has no entry for $($zipAsset[0].name)" } |
| 41 | +$actualHash = (Get-FileHash -LiteralPath $zipPath -Algorithm SHA256).Hash.ToLowerInvariant() |
| 42 | +if ($actualHash -ne $publishedHash.Groups[1].Value.ToLowerInvariant()) { throw 'Windows package checksum mismatch' } |
| 43 | + |
| 44 | +$extractRoot = Join-Path $artifactRoot 'extracted' |
| 45 | +Expand-Archive -LiteralPath $zipPath -DestinationPath $extractRoot |
| 46 | +$candidate = @(Get-ChildItem -LiteralPath $extractRoot -Recurse -File -Filter 'codebase-memory-cli.exe') |
| 47 | +if ($candidate.Count -ne 1) { throw "expected one codebase-memory-cli.exe, found $($candidate.Count)" } |
| 48 | + |
| 49 | +& git.exe clone --depth 1 --branch $ReleaseTag "https://github.com/$Repository.git" $sourceRoot |
| 50 | +if ($LASTEXITCODE) { throw "could not clone source tag $ReleaseTag" } |
| 51 | +$sourceCommit = (& git.exe -C $sourceRoot rev-parse HEAD).Trim() |
| 52 | + |
| 53 | +$setup = Join-Path $sourceRoot 'scripts\setup-windows.ps1' |
| 54 | +& pwsh.exe -NoProfile -File $setup -Binary $candidate[0].FullName -InstallDir $installRoot -NoPathPrompt |
| 55 | +if ($LASTEXITCODE) { throw 'binary installation failed' } |
| 56 | +$installed = Join-Path $installRoot 'codebase-memory-cli.exe' |
| 57 | + |
| 58 | +$corpus = Join-Path $sourceRoot 'scripts\qualification\run-windows-benchmark-corpus.ps1' |
| 59 | +& pwsh.exe -NoProfile -File $corpus ` |
| 60 | + -CandidateBinary $installed ` |
| 61 | + -WorkspaceRoot $workspaceRoot ` |
| 62 | + -ResultsRoot $resultsRoot ` |
| 63 | + -CodebaseMemoryRef $sourceCommit ` |
| 64 | + -Repeats $Repeats ` |
| 65 | + -Initialize |
| 66 | +if ($LASTEXITCODE) { throw 'Windows benchmark failed' } |
| 67 | + |
| 68 | +Write-Host "Benchmark complete: $runRoot" |
| 69 | +Write-Host "Release tag: $ReleaseTag" |
| 70 | +Write-Host "Source commit: $sourceCommit" |
0 commit comments