Merge pull request #3 from kyriewxcode/agent/g0-completion #36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CPU Contracts | |
| on: | |
| push: | |
| pull_request: | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: cpu-contracts-${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| cpu-contracts: | |
| name: Windows x64 CPU contracts | |
| runs-on: windows-2022 | |
| timeout-minutes: 20 | |
| defaults: | |
| run: | |
| shell: pwsh | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| fetch-depth: 1 | |
| persist-credentials: false | |
| - name: Select and report toolchain | |
| run: | | |
| $ErrorActionPreference = "Stop" | |
| $MinimumCMakeVersion = [Version]"4.0.1" | |
| function Get-CMakeVersion([string]$Executable) | |
| { | |
| $VersionOutput = @(& $Executable --version 2>&1) | |
| $VersionMatch = [regex]::Match( | |
| [string]::Join("`n", $VersionOutput), | |
| "(?m)^cmake version ([0-9]+(?:\.[0-9]+)+)" | |
| ) | |
| if (-not $VersionMatch.Success) | |
| { | |
| throw "Unable to determine CMake version from $Executable" | |
| } | |
| return [Version]($VersionMatch.Groups[1].Value) | |
| } | |
| $SelectedCMakeVersion = Get-CMakeVersion "cmake" | |
| if ($SelectedCMakeVersion -lt $MinimumCMakeVersion) | |
| { | |
| $AndroidCMakeRoot = Join-Path $env:ANDROID_HOME "cmake" | |
| $Candidates = @( | |
| Get-ChildItem -LiteralPath $AndroidCMakeRoot -Directory -ErrorAction SilentlyContinue | | |
| ForEach-Object { | |
| $CandidateExecutable = Join-Path $_.FullName "bin\cmake.exe" | |
| if (Test-Path -LiteralPath $CandidateExecutable) | |
| { | |
| $CandidateVersion = Get-CMakeVersion $CandidateExecutable | |
| if ($CandidateVersion -ge $MinimumCMakeVersion) | |
| { | |
| [PSCustomObject]@{ | |
| Bin = Split-Path -Parent $CandidateExecutable | |
| Version = $CandidateVersion | |
| } | |
| } | |
| } | |
| } | | |
| Sort-Object Version -Descending | |
| ) | |
| if ($Candidates.Count -eq 0) | |
| { | |
| throw "CMake $MinimumCMakeVersion or newer is not installed on the runner" | |
| } | |
| $Selected = $Candidates[0] | |
| $Selected.Bin | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append | |
| $env:Path = "$($Selected.Bin);$env:Path" | |
| $SelectedCMakeVersion = Get-CMakeVersion "cmake" | |
| } | |
| $PythonVersion = & python --version 2>&1 | Select-Object -First 1 | |
| if ($PythonVersion -notmatch "^Python 3\.") | |
| { | |
| throw "Python 3 is required for the complete CPU contract lane" | |
| } | |
| $VsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" | |
| $VisualStudioVersion = & $VsWhere -latest -products * ` | |
| -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 ` | |
| -property installationVersion | |
| if (-not $VisualStudioVersion) | |
| { | |
| throw "Visual Studio 2022 C++ tools are required" | |
| } | |
| if ($VisualStudioVersion -notmatch "^17\.") | |
| { | |
| throw "Expected Visual Studio 2022, found $VisualStudioVersion" | |
| } | |
| $Commit = git rev-parse HEAD | |
| $EnvironmentEvidence = @( | |
| "## CPU Contract Environment" | |
| "" | |
| "- Commit: ``$Commit``" | |
| "- Runner: ``$env:ImageOS`` / ``$env:ImageVersion``" | |
| "- CMake: ``$SelectedCMakeVersion``" | |
| "- Python: ``$PythonVersion``" | |
| "- Visual Studio: ``$VisualStudioVersion``" | |
| "- Configure preset: ``vs2022-x64``" | |
| "- Build presets: ``cpu-debug``, ``cpu-release``" | |
| "- Test presets: ``test-cpu-debug``, ``test-cpu-release``" | |
| ) | |
| $EnvironmentEvidence | Write-Output | |
| $EnvironmentEvidence | | |
| Add-Content -LiteralPath $env:GITHUB_STEP_SUMMARY -Encoding utf8 | |
| - name: Configure | |
| run: cmake --preset vs2022-x64 | |
| - name: Build CPU contracts (Debug) | |
| run: cmake --build --preset cpu-debug | |
| - name: Test CPU contracts (Debug) | |
| run: ctest --preset test-cpu-debug | |
| - name: Build CPU contracts (Release) | |
| run: cmake --build --preset cpu-release | |
| - name: Test CPU contracts (Release) | |
| run: ctest --preset test-cpu-release | |
| - name: Report CPU contract result | |
| run: | | |
| $ErrorActionPreference = "Stop" | |
| $DebugDiscovery = ctest --preset test-cpu-debug --show-only=json-v1 | | |
| ConvertFrom-Json | |
| if ($LASTEXITCODE -ne 0) | |
| { | |
| throw "Unable to discover Debug CPU tests" | |
| } | |
| $ReleaseDiscovery = ctest --preset test-cpu-release --show-only=json-v1 | | |
| ConvertFrom-Json | |
| if ($LASTEXITCODE -ne 0) | |
| { | |
| throw "Unable to discover Release CPU tests" | |
| } | |
| $ResultEvidence = @( | |
| "" | |
| "## CPU Contract Result" | |
| "" | |
| "- Debug: **Pass** ($($DebugDiscovery.tests.Count) tests)" | |
| "- Release: **Pass** ($($ReleaseDiscovery.tests.Count) tests)" | |
| ) | |
| $ResultEvidence | Write-Output | |
| $ResultEvidence | | |
| Add-Content -LiteralPath $env:GITHUB_STEP_SUMMARY -Encoding utf8 |