-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathaction.yml
More file actions
407 lines (360 loc) · 18.5 KB
/
action.yml
File metadata and controls
407 lines (360 loc) · 18.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
name: Install Swift
description: Install Swift Release
inputs:
source:
description: "Where to source the Swift installer. Specify either 'swift.org' or 'custom' (Github release)"
required: true
default: 'swift.org'
type: choice
options:
- swift.org
- custom
# for swift.org toolchains:
swift-version:
description: 'Swift version identifier for swift.org builds (e.g., swift-5.5-release, development). Only specify when using official Swift toolchains from swift.org'
required: false
swift-build:
description: 'Swift build identifier for swift.org builds (e.g., 5.5-RELEASE, DEVELOPMENT-SNAPSHOT-2021-09-18-a). Only specify when using official Swift toolchains from swift.org'
required: false
build_arch:
description: 'Build architecture (amd64 or arm64). Only specify when using official Swift toolchains from swift.org'
default: 'amd64'
required: true
# deprecated parameters (for backward compatibility)
branch:
description: '[DEPRECATED] Use swift-version instead. Branch for swift.org builds. Only specify when using official Swift toolchains from swift.org'
required: false
tag:
description: '[DEPRECATED] Use swift-build instead. Tag for swift.org builds. Only specify when using official Swift toolchains from swift.org'
required: false
# for custom toolchains:
github-repo:
description: 'Github repo in "owner/repo" format. Only specify when using custom toolchains from Github releases.'
required: false
release-tag-name:
description: 'Release tag name. Only specify when using custom toolchains from Github releases.'
required: false
release-asset-name:
description: 'Asset name for the Swift installer executable in the release. Only specify when using custom toolchains from Github releases.'
required: false
github-token:
description: 'Optional Github token for fetching a release. Only specify when using custom toolchains from non-public Github releases.'
required: false
# common
installer-args:
description: 'Additional arguments to pass to the installer, space-delimited (double quotes are not supported)'
required: false
default: ''
update-sdk-modules:
description: 'Update SDK module definitions to latest version after installation (Windows only)'
required: false
default: 'false'
type: boolean
cache:
description: 'Cache downloaded toolchains'
required: false
default: 'false'
type: boolean
runs:
using: 'composite'
steps:
- name: Handle deprecated parameters and validate inputs
run: |
# Handle backward compatibility for deprecated parameters
$SwiftVersion = "${{ inputs.swift-version }}"
$SwiftBuild = "${{ inputs.swift-build }}"
# Ensure that only the deprecated or the new parameter set is used at one time.
$errors = @(
if (![String]::IsNullOrEmpty("${{ inputs.branch }}") -and ![String]::IsNullOrEmpty($SwiftVersion)) { "Cannot specify both 'branch' (deprecated) and 'swift-version'. Please use only 'swift-version'." }
if (![String]::IsNullOrEmpty("${{ inputs.tag }}") -and ![String]::IsNullOrEmpty($SwiftBuild)) { "Cannot specify both 'tag' (deprecated) and 'swift-build'. Please use only 'swift-build'." }
)
foreach ($error in $errors) { Write-Host "::error::$error" }
if ($errors) { exit 1 }
# Handle deprecated parameters with warnings.
if (![String]::IsNullOrEmpty("${{ inputs.branch }}")) {
Write-Host "::warning::The 'branch' input is deprecated and will be removed in a future version. Please use 'swift-version' instead."
$SwiftVersion = "${{ inputs.branch }}"
}
if (![String]::IsNullOrEmpty("${{ inputs.tag }}")) {
Write-Host "::warning::The 'tag' input is deprecated and will be removed in a future version. Please use 'swift-build' instead."
$SwiftBuild = "${{ inputs.tag }}"
}
switch ("${{ inputs.source }}") {
"swift.org" {
if (-not $SwiftVersion) {
Write-Host "::error::swift-version is required when using swift.org source"
exit 1
}
if (-not $SwiftBuild) {
Write-Host "::error::swift-build is required when using swift.org source"
exit 1
}
}
"custom" {
if (-not "${{ inputs.github-repo }}") {
Write-Host "::error::github-repo is required when using custom source"
exit 1
}
if (-not "${{ inputs.release-tag-name }}") {
Write-Host "::error::release-tag-name is required when using custom source"
exit 1
}
if (-not "${{ inputs.release-asset-name }}") {
Write-Host "::error::release-asset-name is required when using custom source"
exit 1
}
}
}
# Export resolved values for use in subsequent steps.
Write-Output "RESOLVED_SWIFT_VERSION=$SwiftVersion" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
Write-Output "RESOLVED_SWIFT_BUILD=$SwiftBuild" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
shell: pwsh
- name: Validate Linux distribution
if: runner.os == 'Linux'
run: |
source /etc/os-release
echo ${ID} ${VERSION_ID}
case ${ID} in
ubuntu)
case ${VERSION_ID} in
16.04|18.04|20.04|22.04|24.04)
;;
*)
echo "::error file=/etc/os-release,title=Unsupported::unsupported ${ID} release (${VERSION_ID})"
exit 1
esac
;;
*)
echo ::error unknown Linux distribution
exit 1
esac
shell: bash
- name: Generate cache key (Windows)
if: runner.os == 'Windows' && inputs.cache == 'true'
id: cache-key
run: |
if ("${{ inputs.source }}" -eq "swift.org") {
$CacheKey = "swift-toolchain-windows-${{ inputs.build_arch }}-${env:RESOLVED_SWIFT_VERSION}-${env:RESOLVED_SWIFT_BUILD}"
} else {
$CacheKey = "swift-toolchain-windows-custom-${{ inputs.github-repo }}-${{ inputs.release-tag-name }}-${{ inputs.release-asset-name }}".Replace("/", "-")
}
"key=$CacheKey" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
$CachePath = [IO.Path]::Combine(${env:Temp}, "installer.exe")
"path=$CachePath" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
shell: pwsh
- name: Generate cache key (Linux/macOS)
if: runner.os != 'Windows' && inputs.cache == 'true'
id: cache-key-posix
run: |
OS=$(echo "${{ runner.os }}" | tr '[:upper:]' '[:lower:]')
if [[ "${{ inputs.source }}" == "swift.org" ]]; then
CACHE_KEY="swift-toolchain-${OS}-${{ inputs.build_arch }}-${RESOLVED_SWIFT_VERSION}-${RESOLVED_SWIFT_BUILD}"
else
CACHE_KEY="swift-toolchain-${OS}-custom-${{ inputs.github-repo }}-${{ inputs.release-tag-name }}-${{ inputs.release-asset-name }}"
CACHE_KEY="${CACHE_KEY//\//-}"
fi
echo "key=${CACHE_KEY}" >> $GITHUB_OUTPUT
# Set cache path based on OS
if [[ "${{ runner.os }}" == "Linux" ]]; then
CACHE_PATH="swift-toolchain.tar.gz"
else
CACHE_PATH="swift-${RESOLVED_SWIFT_BUILD}-osx.pkg"
fi
echo "path=${CACHE_PATH}" >> $GITHUB_OUTPUT
shell: bash
- name: Restore cached toolchain
if: inputs.cache == 'true'
id: cache-restore
uses: actions/cache/restore@v4
with:
path: ${{ runner.os == 'Windows' && steps.cache-key.outputs.path || steps.cache-key-posix.outputs.path }}
key: ${{ runner.os == 'Windows' && steps.cache-key.outputs.key || steps.cache-key-posix.outputs.key }}
- name: Fetch installer from GitHub release (Windows)
if: runner.os == 'Windows' && inputs.source == 'custom' && (inputs.cache != 'true' || steps.cache-restore.outputs.cache-hit != 'true')
env:
GH_TOKEN: ${{ inputs.github-token }}
run: |
gh release download "${{ inputs.release-tag-name }}" --skip-existing --repo "${{ inputs.github-repo }}" --pattern "${{ inputs.release-asset-name }}" --output $([IO.Path]::Combine(${env:Temp}, "installer.exe"))
shell: pwsh
- name: Fetch installer from GitHub release (Linux/macOS)
if: runner.os != 'Windows' && inputs.source == 'custom' && (inputs.cache != 'true' || steps.cache-restore.outputs.cache-hit != 'true')
env:
GH_TOKEN: ${{ inputs.github-token }}
run: |
gh release download "${{ inputs.release-tag-name }}" --skip-existing --repo "${{ inputs.github-repo }}" --pattern "${{ inputs.release-asset-name }}"
if [[ "${{ runner.os }}" == "Linux" ]]; then
mv "${{ inputs.release-asset-name }}" swift-toolchain.tar.gz
else
mv "${{ inputs.release-asset-name }}" swift-${RESOLVED_SWIFT_BUILD}-osx.pkg
fi
shell: bash
- name: Fetch installer from swift.org
if: runner.os == 'Windows' && inputs.source == 'swift.org' && (inputs.cache != 'true' || steps.cache-restore.outputs.cache-hit != 'true')
run: |
# Download the appropriate installer
$URL = if ("${{ inputs.build_arch }}" -eq "amd64") {
"https://download.swift.org/${env:RESOLVED_SWIFT_VERSION}/windows10/swift-${env:RESOLVED_SWIFT_BUILD}/swift-${env:RESOLVED_SWIFT_BUILD}-windows10.exe"
} else {
"https://download.swift.org/${env:RESOLVED_SWIFT_VERSION}/windows10-${{ inputs.build_arch }}/swift-${env:RESOLVED_SWIFT_BUILD}/swift-${env:RESOLVED_SWIFT_BUILD}-windows10-${{ inputs.build_arch }}.exe"
}
$Path = [IO.Path]::Combine(${env:Temp}, "installer.exe")
Write-Host "Downloading package from $URL to $Path..."
try {
(New-Object System.Net.WebClient).DownloadFile($URL, $Path)
} catch {
Write-Host "::error::Package download failed: $($_.Exception.Message)"
}
shell: pwsh
- name: Fetch installer from swift.org (Linux)
if: runner.os == 'Linux' && inputs.source == 'swift.org' && (inputs.cache != 'true' || steps.cache-restore.outputs.cache-hit != 'true')
run: |
source /etc/os-release
curl -sL https://download.swift.org/${RESOLVED_SWIFT_VERSION}/ubuntu${VERSION_ID/./}/swift-${RESOLVED_SWIFT_BUILD}/swift-${RESOLVED_SWIFT_BUILD}-ubuntu${VERSION_ID}.tar.gz -o swift-toolchain.tar.gz
shell: bash
- name: Fetch installer from swift.org (macOS)
if: runner.os == 'macOS' && inputs.source == 'swift.org' && (inputs.cache != 'true' || steps.cache-restore.outputs.cache-hit != 'true')
run: |
curl -sOL https://download.swift.org/${RESOLVED_SWIFT_VERSION}/xcode/swift-${RESOLVED_SWIFT_BUILD}/swift-${RESOLVED_SWIFT_BUILD}-osx.pkg
shell: bash
- name: Save toolchain to cache
if: inputs.cache == 'true' && steps.cache-restore.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: ${{ runner.os == 'Windows' && steps.cache-key.outputs.path || steps.cache-key-posix.outputs.path }}
key: ${{ runner.os == 'Windows' && steps.cache-key.outputs.key || steps.cache-key-posix.outputs.key }}
- name: Install Swift
id: install-swift
if: runner.os == 'Windows'
run: |
# Perform installation
$Installer = [IO.Path]::Combine(${env:Temp}, "installer.exe")
$Arguments = "/quiet /log ${env:Temp}\install.log ${{ inputs.installer-args }}".Split(" ", [StringSplitOptions]"RemoveEmptyEntries")
Write-Host "::debug::Installer Arguments: $($Arguments -join ' ')"
try {
$Process = Start-Process -FilePath $Installer -ArgumentList $Arguments -Wait -PassThru -Verb RunAs
switch ($Process.ExitCode) {
0 { Write-Host "::debug::Installation successful" }
3010 { Write-Host "::notice::Installation successful; reboot required"}
default {
Write-Host "::error::Installation process returned unexpected exit code: $_"
exit $_
}
}
} catch {
Write-Host "::error::Installation failed: $($_.Exception.Message)"
exit 1
}
foreach ($level in "Machine", "User") {
[Environment]::GetEnvironmentVariables($level).GetEnumerator() | ForEach-Object {
# For Path variables, append the new values, if they're not already in there
if ($_.Name -eq "Path") {
$_.Value = ("${env:Path};$($_.Value)" -Split ';' | Select -Unique) -Join ';'
}
$_
} | Set-Content -Path { "Env:$($_.Name)" }
}
# Reset Path and environment
Write-Output "$env:Path" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8
Get-ChildItem Env: | ForEach-Object { echo "$($_.Name)=$($_.Value)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append }
shell: pwsh
- name: Upload Error Logs
if: runner.os == 'Windows' && failure() && steps.install-swift.outcome == 'failure'
uses: actions/upload-artifact@v4
with:
name: installer-logs
path: ${env:Temp}/install*.log*
- name: Check Swift version
if: runner.os == 'Windows'
id: swift-version
run: |
$Output = swift --version
if ($LASTEXITCODE -ne 0) {
Write-Host "::error::Swift exited with code $LASTEXITCODE"
exit 1
}
if ($Output.Length -eq 0) {
Write-Host "::error::`swift --version` output is empty"
exit 1
}
$Match = ([regex]"\d+.\d+(.\d+)?").Match($Output)
if ($Match.Success) {
$SwiftVersion = [System.Version]($Match.Groups[0].Value)
Write-Output is_newer_than_5_9=$($SwiftVersion -gt [System.Version]"5.9") | Out-File $env:GITHUB_OUTPUT -Append -Encoding UTF8
}
shell: pwsh
- name: VS2022 Compatibility Setup
if: runner.os == 'Windows' && steps.swift-version.outputs.is_newer_than_5_9 == 'false'
uses: compnerd/gha-setup-vsdevenv@f1ba60d553a3216ce1b89abe0201213536bc7557 # v6
- name: VS2022 Compatibility Installation
if: runner.os == 'Windows' && steps.swift-version.outputs.is_newer_than_5_9 == 'false'
run: |
Copy-Item "$env:SDKROOT\usr\share\ucrt.modulemap" -destination "$env:UniversalCRTSdkDir\Include\$env:UCRTVersion\ucrt\module.modulemap"
if (Test-Path -Path "$env:SDKROOT\usr\share\vcruntime.modulemap") {
Copy-Item "$env:SDKROOT\usr\share\vcruntime.modulemap" -destination "$env:VCToolsInstallDir\include\module.modulemap"
Copy-Item "$env:SDKROOT\usr\share\vcruntime.apinotes" -destination "$env:VCToolsInstallDir\include\vcruntime.apinotes"
} else {
Copy-Item "$env:SDKROOT\usr\share\visualc.modulemap" -destination "$env:VCToolsInstallDir\include\module.modulemap"
Copy-Item "$env:SDKROOT\usr\share\visualc.apinotes" -destination "$env:VCToolsInstallDir\include\visualc.apinotes"
}
Copy-Item "$env:SDKROOT\usr\share\winsdk.modulemap" -destination "$env:UniversalCRTSdkDir\Include\$env:UCRTVersion\um\module.modulemap"
shell: pwsh
- name: Update SDK Module Definitions
if: runner.os == 'Windows' && inputs.update-sdk-modules == 'true'
run: |
Write-Host "::notice::Updating SDK module definitions to latest version..."
$SwiftRoot = Split-Path -Path (Split-Path -Path (Get-Command swift).Source -Parent) -Parent
$ModuleDefinitions = @{
"(Legacy) WinSDK Module Map" = @{
URL = "https://raw.githubusercontent.com/swiftlang/swift/main/stdlib/public/Platform/winsdk_um.modulemap";
Destination = "$([IO.Path]::Combine("${env:SDKROOT}", "usr", "share", "winsdk.modulemap"))";
};
"WinSDK(UM) Module Map" = @{
URL = "https://raw.githubusercontent.com/swiftlang/swift/main/stdlib/public/Platform/winsdk_um.modulemap";
Destination = "$([IO.Path]::Combine("${env:SDKROOT}", "usr", "share", "winsdk_um.modulemap"))";
};
"WinSDK(Shared) Module Map" = @{
URL = "https://raw.githubusercontent.com/swiftlang/swift/main/stdlib/public/Platform/winsdk_shared.modulemap";
Destination = "$([IO.Path]::Combine("${env:SDKROOT}", "usr", "share", "winsdk_shared.modulemap"))";
};
"UCRT Module Map" = @{
URL = "https://raw.githubusercontent.com/swiftlang/swift/main/stdlib/public/Platform/ucrt.modulemap";
Destination = "$([IO.Path]::Combine("${env:SDKROOT}", "usr", "share", "ucrt.modulemap"))";
};
"VCRuntime Module Map" = @{
URL = "https://raw.githubusercontent.com/swiftlang/swift/main/stdlib/public/Platform/vcruntime.modulemap";
Destination = "$([IO.Path]::Combine("${env:SDKROOT}", "usr", "share", "vcruntime.modulemap"))";
};
"VCRuntime API Notes" = @{
URL = "https://raw.githubusercontent.com/swiftlang/swift/main/stdlib/public/Platform/vcruntime.apinotes";
Destination = "$([IO.Path]::Combine("${env:SDKROOT}", "usr", "share", "vcruntime.apinotes"))";
};
"Clang Module Map" = @{
URL = "https://raw.githubusercontent.com/llvm/llvm-project/main/clang/lib/Headers/module.modulemap";
Destination = "$([IO.Path]::Combine("$SwiftRoot", "lib", "swift", "clang", "include", "module.modulemap"))";
};
}
$ModuleDefinitions.GetEnumerator() | ForEach-Object {
Write-Host "::notice::Updating $($_.Value.Destination)"
& curl.exe --fail --silent --show-error --retry 3 --retry-delay 5 --output "$($_.Value.Destination)" --location $_.Value.URL
if ($LASTEXITCODE -ne 0) {
Write-Host "::error::Failed to update $($_.Key)"
exit 1
}
}
Write-Host "::notice::SDK module definitions updated successfully"
shell: pwsh
- name: Install Swift
if: runner.os == 'Linux'
run: |
tar zxf swift-toolchain.tar.gz -C ${HOME}
rm -f swift-toolchain.tar.gz
echo "${HOME}/usr/bin" >> $GITHUB_PATH
shell: bash
- name: Install Swift
if: runner.os == 'macOS'
run: |
xattr -dr com.apple.quarantine swift-${RESOLVED_SWIFT_BUILD}-osx.pkg
installer -pkg swift-${RESOLVED_SWIFT_BUILD}-osx.pkg -target CurrentUserHomeDirectory
rm -f swift-${RESOLVED_SWIFT_BUILD}-osx.pkg
echo "TOOLCHAINS=$(plutil -extract 'CFBundleIdentifier' xml1 -o - ${HOME}/Library/Developer/Toolchains/swift-${RESOLVED_SWIFT_BUILD}.xctoolchain/Info.plist | xmllint --xpath '//plist/string/text()' -)" >> $GITHUB_ENV
shell: bash