ci: discover Swift toolchain under Toolchains dir #8
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: Windows spike | |
| # Throwaway spike (step 1 of PLAN.md): try to build the shared core | |
| # (Sources/HeadlessProtocol) with Swift-for-Windows on a real runner. | |
| # Delete this file once the spike outcome is recorded. | |
| on: | |
| push: | |
| branches: [spike/windows-core] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| jobs: | |
| core-build: | |
| runs-on: windows-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Swift toolchain | |
| shell: pwsh | |
| run: | | |
| winget install --id Swift.Toolchain -e --source winget ` | |
| --accept-source-agreements --accept-package-agreements --disable-interactivity | |
| $loc = $null | |
| foreach ($hive in @('HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall', | |
| 'HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall', | |
| 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall')) { | |
| Get-ItemProperty "$hive\*" -ErrorAction SilentlyContinue | | |
| Where-Object { $_.DisplayName -like '*Swift*' } | | |
| ForEach-Object { Write-Host "$($_.DisplayName) -> $($_.InstallLocation)"; if ($_.InstallLocation) { $loc = $_.InstallLocation } } | |
| } | |
| $toolchainBin = Join-Path $env:LOCALAPPDATA 'Programs\Swift\Toolchains' | |
| if (Test-Path $toolchainBin) { | |
| $found = Get-ChildItem $toolchainBin -Directory | Select-Object -First 1 | |
| $loc = Join-Path $found.FullName 'usr' | |
| Write-Host "Discovered toolchain: $($found.FullName)" | |
| } | |
| if (-not $loc -or -not (Test-Path (Join-Path $loc 'bin\swift.exe'))) { | |
| Write-Host '--- fallback: searching C:\ for swift.exe ---' | |
| where.exe /R C:\ swift.exe 2>$null | Select-Object -First 5 | |
| throw 'swift.exe still not located' | |
| } | |
| Add-Content $env:GITHUB_PATH (Join-Path $loc 'bin') | |
| Add-Content $env:GITHUB_PATH (Join-Path $loc 'usr\bin') | |
| - name: Locate toolchain | |
| shell: pwsh | |
| run: | | |
| (Get-Command swift -ErrorAction SilentlyContinue).Source | |
| swift --version | |
| - name: Set up MSVC environment | |
| uses: ilammy/msvc-dev-cmd@v1 | |
| - name: Show toolchain | |
| shell: pwsh | |
| run: swift --version | |
| - name: Build shared core (HeadlessProtocol) | |
| shell: pwsh | |
| working-directory: apps/headless | |
| run: swift build --target HeadlessProtocol --build-tests-off 2>&1 | Tee-Object core-build.log | |
| - name: Build protocol test executable | |
| if: success() || failure() | |
| shell: pwsh | |
| working-directory: apps/headless | |
| run: swift build --product headless-protocol-tests 2>&1 | Tee-Object tests-build.log | |
| - name: Upload build logs | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: windows-spike-logs | |
| path: | | |
| apps/headless/core-build.log | |
| apps/headless/tests-build.log | |
| if-no-files-found: ignore |