@@ -38,5 +38,50 @@ function Install-Swift {
3838 Write-Host (' FAILED ({0})' -f $Process.ExitCode )
3939 exit 1
4040 }
41+ Write-Host - NoNewLine ' Adding Swift to PATH ... '
42+ # Older toolchains modify the Machine PATH to include \Library\Developer\Toolchains
43+ foreach ($Item in [Environment ]::GetEnvironmentVariables(' Machine' )[' Path' ].Split(' ;' )) {
44+ if ($Item.Contains (' Swift' ) -or $Item.Contains (' Library\Developer\Toolchains' )) {
45+ GitHubActions- AddPath - Item $Item
46+ }
47+ }
48+ # Newer toolchains modify the User PATH to include a path to a Swift directory
49+ foreach ($Item in [Environment ]::GetEnvironmentVariables(' User' )[' Path' ].Split(' ;' )) {
50+ if ($Item.Contains (' Swift' )) {
51+ GitHubActions- AddPath - Item $Item
52+ }
53+ }
54+ # Find and export the SDKROOT environment variable
55+ $MachineSDKROOT = [Environment ]::GetEnvironmentVariables(' Machine' )[' SDKROOT' ]
56+ $UserSDKROOT = [Environment ]::GetEnvironmentVariables(' User' )[' SDKROOT' ]
57+ if ($MachineSDKROOT ) {
58+ GitHubActions- ExportVariable - Name " SDKROOT" - Value $MachineSDKROOT
59+ } elseif ($UserSDKROOT ) {
60+ GitHubActions- ExportVariable - Name " SDKROOT" - Value $UserSDKROOT
61+ }
62+ Write-Host ' SUCCESS'
4163 Remove-Item - Force installer.exe
42- }
64+ }
65+
66+ function GitHubActions-AddPath {
67+ param (
68+ [string ]$Item
69+ )
70+ $FilePath = $env: GITHUB_PATH
71+ if ($FilePath ) {
72+ Add-Content - Path " $FilePath " - Value " $Item `r`n "
73+ }
74+ $env: Path = $Item + " ;" + $env: Path
75+ }
76+
77+ function GitHubActions-ExportVariable {
78+ param (
79+ [string ]$Name ,
80+ [string ]$Value
81+ )
82+ $FilePath = $env: GITHUB_ENV
83+ if ($FilePath ) {
84+ Add-Content - Path " $FilePath " - Value " $Name =$Value `r`n "
85+ }
86+ Set-Content env:\$Name $Value
87+ }
0 commit comments