Skip to content

Commit 2b396de

Browse files
Install Python 3.10 in dockerless Windows builds (#201)
* install Python 3.10 in dockerless Windows builds * update environment variables after installing Swift on Windows
1 parent 7e706d0 commit 2b396de

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

.github/workflows/scripts/windows/swift/install-swift.ps1

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,50 @@ function Install-Swift {
175175
exit 1
176176
}
177177
Remove-FileWithRetry -Path installer.exe
178-
}
178+
179+
Write-Host -NoNewLine 'Adding Swift to PATH ... '
180+
# Older toolchains modify the Machine PATH to include \Library\Developer\Toolchains
181+
foreach ($Item in [Environment]::GetEnvironmentVariables('Machine')['Path'].Split(';')) {
182+
if ($Item.Contains('Swift') -or $Item.Contains('Library\Developer\Toolchains')) {
183+
GitHubActions-AddPath -Item $Item
184+
}
185+
}
186+
# Newer toolchains modify the User PATH to include a path to a Swift directory
187+
foreach ($Item in [Environment]::GetEnvironmentVariables('User')['Path'].Split(';')) {
188+
if ($Item.Contains('Swift')) {
189+
GitHubActions-AddPath -Item $Item
190+
}
191+
}
192+
# Find and export the SDKROOT environment variable
193+
$MachineSDKROOT = [Environment]::GetEnvironmentVariables('Machine')['SDKROOT']
194+
$UserSDKROOT = [Environment]::GetEnvironmentVariables('User')['SDKROOT']
195+
if ($MachineSDKROOT) {
196+
GitHubActions-ExportVariable -Name "SDKROOT" -Value $MachineSDKROOT
197+
} elseif ($UserSDKROOT) {
198+
GitHubActions-ExportVariable -Name "SDKROOT" -Value $UserSDKROOT
199+
}
200+
Write-Host 'SUCCESS'
201+
}
202+
203+
function GitHubActions-AddPath {
204+
param (
205+
[string]$Item
206+
)
207+
$FilePath = $env:GITHUB_PATH
208+
if ($FilePath) {
209+
Add-Content -Path "$FilePath" -Value "$Item`r`n"
210+
}
211+
$env:Path = $Item + ";" + $env:Path
212+
}
213+
214+
function GitHubActions-ExportVariable {
215+
param (
216+
[string]$Name,
217+
[string]$Value
218+
)
219+
$FilePath = $env:GITHUB_ENV
220+
if ($FilePath) {
221+
Add-Content -Path "$FilePath" -Value "$Name=$Value`r`n"
222+
}
223+
Set-Content env:\$Name $Value
224+
}

.github/workflows/swift_package_test.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,12 @@ jobs:
677677
}
678678
docker pull $Image
679679
echo "image=$Image" >> "$env:GITHUB_OUTPUT"
680+
- name: "Install Python 3.10"
681+
if: ${{ !inputs.enable_windows_docker }}
682+
uses: actions/setup-python@v6
683+
with:
684+
python-version: "3.10"
685+
architecture: "x86"
680686
- name: Install Visual Studio Build Tools
681687
if: ${{ !inputs.enable_windows_docker }}
682688
run: . ${{ steps.script_path.outputs.root }}/.github/workflows/scripts/windows/install-vsb.ps1
@@ -730,7 +736,4 @@ jobs:
730736
- name: Build / Test
731737
timeout-minutes: 60
732738
if: ${{ !inputs.enable_windows_docker }}
733-
run: |
734-
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
735-
RefreshEnv
736-
powershell.exe -NoLogo -File $env:TEMP\test-script\run.ps1; exit $LastExitCode
739+
run: powershell.exe -NoLogo -File $env:TEMP\test-script\run.ps1; exit $LastExitCode

0 commit comments

Comments
 (0)