-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
226 lines (221 loc) · 12.9 KB
/
action.yml
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
name: 'Swift Env'
description: 'A GitHub Action that sets up a Swift environment for cross-platform'
author: 'Koichi Yokota'
branding:
icon: 'package'
color: 'purple'
inputs:
swift-version:
description: 'Swift version to use'
required: true
default: '5.4.2'
winsdk-version:
description: 'WinSDK version to use on Windows'
required: false
default: ''
runs:
using: 'composite'
steps:
- name: Set up Swift ${{ inputs.swift-version }}
if: runner.os == 'macOS'
shell: bash
run: |
set -eu
# Input values.
SWIFT_VERSION='${{ inputs.swift-version }}' # e.g.'5.4.2' '5.5' '2021-12-23-a'
# Install Ninja.
if ! type ninja > /dev/null 2>&1; then
brew update && brew install ninja
fi
ninja --version
# Remove the Swift minor version if it is 0.
if [[ ! $SWIFT_VERSION =~ [0-9]{4}-[0-9]{2}-[0-9]{2}-[a-z] ]]; then
split_version=(${SWIFT_VERSION//./ })
if [ ${#split_version[@]} -eq 3 ] && [ ${split_version[2]} -eq 0 ]; then
SWIFT_VERSION=${split_version[0]}.${split_version[1]}
fi
fi
# Check the Swift version whether it is already installed or not.
if `type swift > /dev/null 2>&1` && [[ $(swift --version | head -n 1) =~ " Swift version $SWIFT_VERSION " ]]; then
echo "Swift ${SWIFT_VERSION} is already installed."
swift --version
exit 0
fi
# Install Swift Toolchain.
if [[ $SWIFT_VERSION =~ [0-9]{4}-[0-9]{2}-[0-9]{2}-[a-z] ]]; then
echo "Download Swift snapshot version: ${SWIFT_VERSION} ..."
curl -sL "https://download.swift.org/development/xcode/swift-DEVELOPMENT-SNAPSHOT-${SWIFT_VERSION}/swift-DEVELOPMENT-SNAPSHOT-${SWIFT_VERSION}-osx.pkg" -o "/tmp/swift-DEVELOPMENT-SNAPSHOT-${SWIFT_VERSION}-osx.pkg"
echo "Successfully downloaded!"
xattr -dr "/tmp/swift-DEVELOPMENT-SNAPSHOT-${SWIFT_VERSION}-osx.pkg"
sudo installer -pkg "/tmp/swift-DEVELOPMENT-SNAPSHOT-${SWIFT_VERSION}-osx.pkg" -target LocalSystem
export TOOLCHAINS=$(/usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier:' "/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-${SWIFT_VERSION}.xctoolchain/Info.plist")
echo TOOLCHAINS=$(/usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier:' "/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-${SWIFT_VERSION}.xctoolchain/Info.plist") >> $GITHUB_ENV
else
echo "Download Swift release version: ${SWIFT_VERSION} ..."
curl -sL "https://download.swift.org/swift-${SWIFT_VERSION}-release/xcode/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE-osx.pkg" -o "/tmp/swift-${SWIFT_VERSION}-RELEASE-osx.pkg"
echo "Successfully downloaded!"
xattr -dr "/tmp/swift-${SWIFT_VERSION}-RELEASE-osx.pkg"
sudo installer -pkg "/tmp/swift-${SWIFT_VERSION}-RELEASE-osx.pkg" -target LocalSystem
export TOOLCHAINS=$(/usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier:' "/Library/Developer/Toolchains/swift-${SWIFT_VERSION}-RELEASE.xctoolchain/Info.plist")
echo TOOLCHAINS=$(/usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier:' "/Library/Developer/Toolchains/swift-${SWIFT_VERSION}-RELEASE.xctoolchain/Info.plist") >> $GITHUB_ENV
fi
# Output Swift version.
swift --version
- name: Set up Swift ${{ inputs.swift-version }}
if: runner.os == 'Linux'
shell: bash
run: |
set -eu
# Input values.
SWIFT_VERSION='${{ inputs.swift-version }}' # e.g.'5.4.2' '5.5' '2021-12-23-a'
# Install Ninja.
if ! type ninja > /dev/null 2>&1; then
sudo apt-get -q update && sudo apt-get -q install -y ninja-build
fi
ninja --version
# Remove the Swift minor version if it is 0.
if [[ ! $SWIFT_VERSION =~ [0-9]{4}-[0-9]{2}-[0-9]{2}-[a-z] ]]; then
split_version=(${SWIFT_VERSION//./ })
if [ ${#split_version[@]} -eq 3 ] && [ ${split_version[2]} -eq 0 ]; then
SWIFT_VERSION=${split_version[0]}.${split_version[1]}
fi
fi
# Check the Swift version whether it is already installed or not.
if `type swift > /dev/null 2>&1` && [[ $(swift --version | head -n 1) =~ " Swift version $SWIFT_VERSION " ]]; then
echo "Swift ${SWIFT_VERSION} is already installed."
swift --version
exit 0
fi
# Get distribution info.
DISTRO_NAME=$(cat /etc/os-release | grep '^NAME=' | awk -F['='] '{print $2}' | sed -e 's/"//g')
DISTRO_VERSION_ID=$(cat /etc/os-release | grep '^VERSION_ID=' | awk -F['='] '{print $2}' | sed -e 's/"//g')
if [ "${DISTRO_NAME}" != 'Ubuntu' ]; then
echo 'unsupported distribution name'
exit 1
fi
if [ "${DISTRO_VERSION_ID}" != '18.04' ] && [ "${DISTRO_VERSION_ID}" != '20.04' ] && [ "${DISTRO_VERSION_ID}" != '22.04' ]; then
echo 'unsupported distribution version'
exit 1
fi
DISTRO_NAME_LOWERCASE=$(echo "${DISTRO_NAME}" | tr "[:upper:]" "[:lower:]")
DISTRO_VERSION_ID_WO_DOT=$(echo "${DISTRO_VERSION_ID}" | sed -e 's/\.//g')
# Install Swift Toolchain.
if [[ $SWIFT_VERSION =~ [0-9]{4}-[0-9]{2}-[0-9]{2}-[a-z] ]]; then
echo "Download Swift snapshot version: ${SWIFT_VERSION} ..."
curl -sL "https://download.swift.org/development/${DISTRO_NAME_LOWERCASE}${DISTRO_VERSION_ID_WO_DOT}/swift-DEVELOPMENT-SNAPSHOT-${SWIFT_VERSION}/swift-DEVELOPMENT-SNAPSHOT-${SWIFT_VERSION}-${DISTRO_NAME_LOWERCASE}${DISTRO_VERSION_ID}.tar.gz" -o "/tmp/swift-DEVELOPMENT-SNAPSHOT-${SWIFT_VERSION}-${DISTRO_NAME_LOWERCASE}${DISTRO_VERSION_ID}.tar.gz"
echo "Successfully downloaded!"
tar xfz "/tmp/swift-DEVELOPMENT-SNAPSHOT-${SWIFT_VERSION}-${DISTRO_NAME_LOWERCASE}${DISTRO_VERSION_ID}.tar.gz" -C /opt
export PATH="/opt/swift-DEVELOPMENT-SNAPSHOT-${SWIFT_VERSION}-${DISTRO_NAME_LOWERCASE}${DISTRO_VERSION_ID}/usr/bin:${PATH}"
echo "/opt/swift-DEVELOPMENT-SNAPSHOT-${SWIFT_VERSION}-${DISTRO_NAME_LOWERCASE}${DISTRO_VERSION_ID}/usr/bin" >> $GITHUB_PATH
else
echo "Download Swift release version: ${SWIFT_VERSION} ..."
curl -sL "https://download.swift.org/swift-${SWIFT_VERSION}-release/${DISTRO_NAME_LOWERCASE}${DISTRO_VERSION_ID_WO_DOT}/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE-${DISTRO_NAME_LOWERCASE}${DISTRO_VERSION_ID}.tar.gz" -o "/tmp/swift-${SWIFT_VERSION}-RELEASE-${DISTRO_NAME_LOWERCASE}${DISTRO_VERSION_ID}.tar.gz"
echo "Successfully downloaded!"
tar xfz "/tmp/swift-${SWIFT_VERSION}-RELEASE-${DISTRO_NAME_LOWERCASE}${DISTRO_VERSION_ID}.tar.gz" -C /opt
export PATH="/opt/swift-${SWIFT_VERSION}-RELEASE-${DISTRO_NAME_LOWERCASE}${DISTRO_VERSION_ID}/usr/bin:${PATH}"
echo "/opt/swift-${SWIFT_VERSION}-RELEASE-${DISTRO_NAME_LOWERCASE}${DISTRO_VERSION_ID}/usr/bin" >> $GITHUB_PATH
fi
# Output Swift version.
swift --version
- name: Set up Swift ${{ inputs.swift-version }} with WinSDK ${{ inputs.winsdk-version }}
if: runner.os == 'Windows'
shell: pwsh
run: |
# Input values.
[string]$SwiftVersion = '${{ inputs.swift-version }}' # e.g. '5.4.2' '5.5' '2021-12-23-a'
[string]$Arch = 'x64' #
[string]$WinSDK = '${{ inputs.winsdk-version }}' # e.g. '', '10.019041.0', '10.0.20348.0'
### Ninja
# Install Ninja.
choco install ninja --yes --no-progress
ninja --version
### Swift Toolchain
# Remove the Swift minor version if it is 0.
if (-Not($SwiftVersion -match '\d{4}-\d{2}-\d{2}-\D')) {
$SplitVersion = $SwiftVersion.Split('.')
if (($SplitVersion.Length -eq 3) -and ($SplitVersion[2] -eq 0)) {
$SwiftVersion = $SplitVersion[0] + '.' + $SplitVersion[1]
}
}
# Check the Swift version whether it is already installed or not.
if ($NULL -ne (Get-Command swift -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Definition -First 1)) {
$CommandResult = swift --version | Select-Object -First 1
if ($CommandResult -cmatch " Swift version $SwiftVersion ") {
Write-Output "Swift $SwiftVersion is already installed."
swift --version
exit 0
}
}
# Install Swift Toolchain.
$exitCode = 0
if ($SwiftVersion -match '\d{4}-\d{2}-\d{2}-\D') {
Write-Output "Download Swift snapshot version: $SwiftVersion ..."
curl.exe -sL "https://download.swift.org/development/windows10/swift-DEVELOPMENT-SNAPSHOT-$SwiftVersion/swift-DEVELOPMENT-SNAPSHOT-$SwiftVersion-windows10.exe" -o "$Env:TEMP/swift-DEVELOPMENT-SNAPSHOT-$SwiftVersion-windows10.exe"
Write-Output "🎉 Successfully downloaded!"
$process = Start-Process -FilePath "$Env:TEMP/swift-DEVELOPMENT-SNAPSHOT-$SwiftVersion-windows10.exe" -ArgumentList -q -Wait -PassThru
$exitCode = $process.ExitCode
} else {
Write-Output "Download Swift release version: $SwiftVersion ..."
curl.exe -sL "https://download.swift.org/swift-$SwiftVersion-release/windows10/swift-$SwiftVersion-RELEASE/swift-$SwiftVersion-RELEASE-windows10.exe" -o "$Env:TEMP/swift-$SwiftVersion-RELEASE-windows10.exe"
Write-Output "🎉 Successfully downloaded!"
$process = Start-Process -FilePath "$Env:TEMP/swift-$SwiftVersion-RELEASE-windows10.exe" -ArgumentList -q -Wait -PassThru
$exitCode = $process.ExitCode
}
if (($exitCode -eq 0) -or ($exitCode -eq 3010)) {
Write-Output "🎉 Successfully installed!"
} else {
Write-Output "🚫 Failed to install..."
exit $exitCode
}
# Get environment variables in the current session.
foreach($level in 'Machine', 'User') {
[Environment]::GetEnvironmentVariables($level).GetEnumerator() | ForEach-Object {
if($_.Name -eq 'Path') {
$_.Value = ($((Get-Content "Env:$($_.Name)") + ";$($_.Value)") -split ';' | Select-Object -unique) -join ';'
}
$_
} | Set-Content -Path { "Env:$($_.Name)" }
}
# Set environment variables.
Write-Output "$Env:Path" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8
Get-ChildItem Env: | ForEach-Object { Write-Output "$($_.Name)=$($_.Value)" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append }
### Visual Studio
# Set up Visual Studio.
$InstallationPath = Get-VSSetupInstance | Select-Object -ExpandProperty InstallationPath
$vcvarsallPath = Join-Path $InstallationPath 'VC\Auxiliary\Build\vcvarsall.bat'
cmd.exe -Verb runas /c "call `"$vcvarsallPath`" $Arch $WinSDK && set > %TEMP%\vcvars.txt"
Get-Content "$Env:TEMP\vcvars.txt" | Foreach-Object {
if ($_ -match "^(.*?)=(.*)$") {
$key=$matches[1].ToString()
$value=$matches[2].ToString()
# Sets environment variables for this step.
switch ($key) {
'UniversalCRTSdkDir' { $Env:UniversalCRTSdkDir = $value }
'UCRTVersion' { $Env:UCRTVersion = $value }
'VCToolsInstallDir' { $Env:VCToolsInstallDir = $value }
Default { }
}
# Sets environments variables for subsequent steps(not this step).
if ($key -eq 'Path') {
Write-Output "$Env:Path" | Out-File -FilePath $Env:GITHUB_PATH -Encoding utf-8 -Append
} else {
Write-Output "$key=$value" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
}
}
}
Write-Output $Env:Path
Write-Output $Env:UniversalCRTSdkDir
Write-Output $Env:UCRTVersion
Write-Output $Env:VCToolsInstallDir
# Add supporting files.
Copy-Item -Path "$Env:SDKROOT\usr\share\ucrt.modulemap" -Destination "$Env:UniversalCRTSdkDir\Include\$Env:UCRTVersion\ucrt\module.modulemap" -Force
if (Test-Path -Path "$env:SDKROOT\usr\share\vcruntime.modulemap") {
Copy-Item -Path "$env:SDKROOT\usr\share\vcruntime.modulemap" -Destination "$env:VCToolsInstallDir\include\module.modulemap" -Force
Copy-Item -Path "$env:SDKROOT\usr\share\vcruntime.apinotes" -Destination "$env:VCToolsInstallDir\include\vcruntime.apinotes" -Force
} else {
Copy-Item -Path "$Env:SDKROOT\usr\share\visualc.modulemap" -Destination "$Env:VCToolsInstallDir\include\module.modulemap" -Force
Copy-Item -Path "$Env:SDKROOT\usr\share\visualc.apinotes" -Destination "$Env:VCToolsInstallDir\include\visualc.apinotes" -Force
}
Copy-Item -Path "$Env:SDKROOT\usr\share\winsdk.modulemap" -Destination "$Env:UniversalCRTSdkDir\Include\$Env:UCRTVersion\um\module.modulemap" -Force
# Output Swift version.
swift --version