diff --git a/.github/workflows/daily-codex-analysis.yml b/.github/workflows/daily-codex-analysis.yml index 433a8963..ef955a13 100644 --- a/.github/workflows/daily-codex-analysis.yml +++ b/.github/workflows/daily-codex-analysis.yml @@ -41,6 +41,8 @@ jobs: PIP_DISABLE_PIP_VERSION_CHECK: "1" TRADINGAGENTS_SITE_DIR: ${{ github.workspace }}\site TRADINGAGENTS_ARCHIVE_DIR: ${{ vars.TRADINGAGENTS_ARCHIVE_DIR }} + CODEX_BINARY: ${{ vars.CODEX_BINARY }} + CODEX_HOME: ${{ vars.CODEX_HOME }} steps: - name: Check out repository uses: actions/checkout@v4 @@ -60,7 +62,68 @@ jobs: python -m pip install -e . if ($LASTEXITCODE) { exit $LASTEXITCODE } + - name: Resolve Codex runtime + if: ${{ github.event.inputs.site_only != 'true' }} + run: | + function Test-CodexCandidate { + param([string]$Candidate) + + if ([string]::IsNullOrWhiteSpace($Candidate) -or -not (Test-Path $Candidate)) { + return $false + } + + try { + & $Candidate --version | Out-Null + return ($LASTEXITCODE -eq 0) + } catch { + Write-Warning "Codex candidate failed: $Candidate :: $($_.Exception.Message)" + return $false + } + } + + $candidates = [System.Collections.Generic.List[string]]::new() + + if (-not [string]::IsNullOrWhiteSpace($env:CODEX_BINARY)) { + $candidates.Add($env:CODEX_BINARY) + } + + $candidates.Add((Join-Path $env:USERPROFILE ".codex\.sandbox-bin\codex.exe")) + + Get-ChildItem -Path "C:\Users\*\.codex\.sandbox-bin\codex.exe" -ErrorAction SilentlyContinue | + Sort-Object LastWriteTime -Descending | + ForEach-Object { $candidates.Add($_.FullName) } + + Get-ChildItem -Path "C:\Users\*\.vscode\extensions\openai.chatgpt-*\bin\windows-x86_64\codex.exe" -ErrorAction SilentlyContinue | + Sort-Object LastWriteTime -Descending | + ForEach-Object { $candidates.Add($_.FullName) } + + $resolvedBinary = $null + foreach ($candidate in $candidates) { + if (Test-CodexCandidate $candidate) { + $resolvedBinary = $candidate + break + } + } + + if (-not $resolvedBinary) { + throw "Could not find a usable Codex binary. Set the CODEX_BINARY repository variable or install Codex for the runner service account." + } + + Add-Content -Path $env:GITHUB_ENV -Value "CODEX_BINARY=$resolvedBinary" + Write-Host "Resolved Codex binary: $resolvedBinary" + + $resolvedHome = $env:CODEX_HOME + if ([string]::IsNullOrWhiteSpace($resolvedHome) -and $resolvedBinary -like "*.codex\.sandbox-bin\codex.exe") { + $resolvedHome = Split-Path (Split-Path $resolvedBinary -Parent) -Parent + } + + if (-not [string]::IsNullOrWhiteSpace($resolvedHome)) { + Add-Content -Path $env:GITHUB_ENV -Value "CODEX_HOME=$resolvedHome" + Write-Host "Using CODEX_HOME: $resolvedHome" + } + - name: Verify Codex login and model availability + if: ${{ github.event.inputs.site_only != 'true' }} run: | $workspaceDir = Join-Path $env:GITHUB_WORKSPACE ".codex-preflight" $script = @(