@@ -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+ }
0 commit comments