Skip to content

Commit a66746b

Browse files
committed
Allow running windows tests in docker-less environment
The vscode-swift extension needs to open the VS Code UI to run tests. As such we cannot run these tests under a docker container as there is no tool like xvfb for Windows. This PR provides powershell scripts to install the VS Build Tools and apporpirate version of Swift. Projects can use this workflow by setting the input enable_windows_docker: false
1 parent 717bc4b commit a66746b

File tree

8 files changed

+128
-0
lines changed

8 files changed

+128
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
. $PSScriptRoot\install-swift.ps1
2+
3+
$SWIFT='https://download.swift.org/swift-5.10.1-release/windows10/swift-5.10.1-RELEASE/swift-5.10.1-RELEASE-windows10.exe'
4+
$SWIFT_SHA256='3027762138ACFA1BBE3050FF6613BBE754332E84C9EFA5C23984646009297286'
5+
6+
Install-Swift -Url $SWIFT -Sha256 $SWIFT_SHA256
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
. $PSScriptRoot\install-swift.ps1
2+
3+
$SWIFT='https://download.swift.org/swift-5.9.2-release/windows10/swift-5.9.2-RELEASE/swift-5.9.2-RELEASE-windows10.exe'
4+
$SWIFT_SHA256='D78A717551C78E824C9B74B0CFB1AD86060FC286EA071FDDB26DF18F56DC7212'
5+
6+
Install-Swift -Url $SWIFT -Sha256 $SWIFT_SHA256
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
. $PSScriptRoot\install-swift.ps1
2+
3+
$SWIFT='https://download.swift.org/swift-6.0.2-release/windows10/swift-6.0.2-RELEASE/swift-6.0.2-RELEASE-windows10.exe'
4+
$SWIFT_SHA256='516FE8E64713BD92F03C01E5198011B74A27F8C1C88627607A2F421718636126'
5+
6+
Install-Swift -Url $SWIFT -Sha256 $SWIFT_SHA256
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
. $PSScriptRoot\install-swift.ps1
2+
3+
$SWIFT_RELEASE_METADATA='http://download.swift.org/swift-6.0-branch/windows10/latest-build.json'
4+
$Release = curl.exe -sL ${SWIFT_RELEASE_METADATA}
5+
$SWIFT_URL = "https://download.swift.org/swift-6.0-branch/windows10/$($($Release | ConvertFrom-JSON).dir)/$($($Release | ConvertFrom-JSON).download)"
6+
7+
Install-Swift -Url $SWIFT_URL -Sha256 ""
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
. $PSScriptRoot\install-swift.ps1
2+
3+
$SWIFT_RELEASE_METADATA='http://download.swift.org/development/windows10/latest-build.json'
4+
$Release = curl.exe -sL ${SWIFT_RELEASE_METADATA}
5+
$SWIFT_URL = "https://download.swift.org/development/windows10/$($($Release | ConvertFrom-JSON).dir)/$($($Release | ConvertFrom-JSON).download)"
6+
7+
Install-Swift -Url $SWIFT_URL -Sha256 ""
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function Install-Swift {
2+
param (
3+
[string]$Url,
4+
[string]$Sha256
5+
)
6+
Set-Variable ErrorActionPreference Stop
7+
Set-Variable ProgressPreference SilentlyContinue
8+
Write-Host -NoNewLine ('Downloading {0} ... ' -f $url)
9+
Invoke-WebRequest -Uri $url -OutFile installer.exe
10+
Write-Host 'SUCCESS'
11+
Write-Host -NoNewLine ('Verifying SHA256 ({0}) ... ' -f $Sha256)
12+
$Hash = Get-FileHash installer.exe -Algorithm sha256
13+
if ($Hash.Hash -eq $Sha256 -or $Sha256 -eq "") {
14+
Write-Host 'SUCCESS'
15+
} else {
16+
Write-Host ('FAILED ({0})' -f $Hash.Hash)
17+
exit 1
18+
}
19+
Write-Host -NoNewLine 'Installing Swift ... '
20+
$Process = Start-Process installer.exe -Wait -PassThru -NoNewWindow -ArgumentList @(
21+
'/quiet',
22+
'/norestart'
23+
)
24+
if ($Process.ExitCode -eq 0) {
25+
Write-Host 'SUCCESS'
26+
} else {
27+
Write-Host ('FAILED ({0})' -f $Process.ExitCode)
28+
exit 1
29+
}
30+
Remove-Item -Force installer.exe
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
$VSB='https://aka.ms/vs/17/release/vs_buildtools.exe'
2+
$VSB_SHA256='99C7677154366062A43082921F40F3CE00EF2614DBF94DB23B244DD13DC9443D'
3+
Set-Variable ErrorActionPreference Stop
4+
Set-Variable ProgressPreference SilentlyContinue
5+
Write-Host -NoNewLine ('Downloading {0} ... ' -f ${VSB})
6+
Invoke-WebRequest -Uri $VSB -OutFile $env:TEMP\vs_buildtools.exe
7+
Write-Host 'SUCCESS'
8+
Write-Host -NoNewLine ('Verifying SHA256 ({0}) ... ' -f $VSB_SHA256)
9+
$Hash = Get-FileHash $env:TEMP\vs_buildtools.exe -Algorithm sha256
10+
if ($Hash.Hash -eq $VSB_SHA256) {
11+
Write-Host 'SUCCESS'
12+
} else {
13+
Write-Host ('FAILED ({0})' -f $Hash.Hash)
14+
exit 1
15+
}
16+
Write-Host -NoNewLine 'Installing Visual Studio Build Tools ... '
17+
$Process =
18+
Start-Process $env:TEMP\vs_buildtools.exe -Wait -PassThru -NoNewWindow -ArgumentList @(
19+
'--quiet',
20+
'--wait',
21+
'--norestart',
22+
'--nocache',
23+
'--add', 'Microsoft.VisualStudio.Component.Windows11SDK.22000',
24+
'--add', 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64'
25+
)
26+
if ($Process.ExitCode -eq 0 -or $Process.ExitCode -eq 3010) {
27+
Write-Host 'SUCCESS'
28+
} else {
29+
Write-Host ('FAILED ({0})' -f $Process.ExitCode)
30+
exit 1
31+
}
32+
Remove-Item -Force $env:TEMP\vs_buildtools.exe

.github/workflows/swift_package_test.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,26 @@ on:
4545
linux_env_vars:
4646
description: "List of environment variables"
4747
type: string
48+
windows_env_vars:
49+
description: "List of environment variables"
50+
type: string
51+
enable_linux_checks:
52+
type: boolean
53+
description: "Boolean to enable linux testing. Defaults to true"
54+
default: true
4855
enable_windows_checks:
4956
type: boolean
5057
description: "Boolean to enable windows testing. Defaults to true"
5158
default: true
59+
enable_windows_docker:
60+
type: boolean
61+
description: "Boolean to enable running build in windows docker container. Defaults to true"
62+
default: true
5263

5364
jobs:
5465
linux-build:
5566
name: Linux (${{ matrix.swift_version }} - ${{ matrix.os_version }})
67+
if: ${{ inputs.enable_linux_checks }}
5668
runs-on: ubuntu-latest
5769
strategy:
5870
fail-fast: false
@@ -97,8 +109,16 @@ jobs:
97109
uses: actions/checkout@v4
98110
with:
99111
ref: ${{ github.ref }} # Include changes to the target branch when action is re-run https://github.com/actions/checkout/issues/1036
112+
- name: Set environment variables
113+
if: ${{ inputs.windows_env_vars }}
114+
run: |
115+
$lines = "${{ inputs.windows_env_vars }}" -split "`r`n"
116+
foreach ($line in $lines) {
117+
echo $line | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
118+
}
100119
- name: Pull Docker image
101120
id: pull_docker_image
121+
if: ${{ inputs.enable_windows_docker }}
102122
run: |
103123
if ("${{ matrix.swift_version }}".Contains("nightly")) {
104124
$Image = "swiftlang/swift:${{ matrix.swift_version }}-windowsservercore-1809"
@@ -107,6 +127,12 @@ jobs:
107127
}
108128
docker pull $Image
109129
echo "image=$Image" >> "$env:GITHUB_OUTPUT"
130+
- name: Install Visual Studio Build Tools
131+
if: ${{ !inputs.enable_windows_docker }}
132+
run: . .github\workflows\scripts\windows\install-vsb.ps1
133+
- name: Install Swift
134+
if: ${{ !inputs.enable_windows_docker }}
135+
run: . .github\workflows\scripts\windows\swift\install-swift-${{ matrix.swift_version }}.ps1
110136
- name: Create test script
111137
run: |
112138
mkdir $env:TEMP\test-script
@@ -127,7 +153,14 @@ jobs:
127153
${{ inputs.windows_pre_build_command }}
128154
Invoke-Program ${{ inputs.windows_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
129155
'@ >> $env:TEMP\test-script\run.ps1
156+
# Docker build
130157
- name: Build / Test
131158
timeout-minutes: 60
159+
if: ${{ !inputs.enable_windows_docker }}
132160
run: |
133161
docker run -v ${{ github.workspace }}:C:\source -v $env:TEMP\test-script:C:\test-script ${{ steps.pull_docker_image.outputs.image }} powershell.exe -NoLogo -File C:\test-script\run.ps1
162+
# Docker-less build
163+
- name: Build / Test
164+
timeout-minutes: 60
165+
if: ${{ inputs.enable_windows_docker }}
166+
run: powershell.exe -NoLogo -File $env:TEMP\test-script\run.ps1

0 commit comments

Comments
 (0)