Skip to content

Commit b2fa3d6

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 3fca720 commit b2fa3d6

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
@@ -93,8 +105,16 @@ jobs:
93105
steps:
94106
- name: Checkout repository
95107
uses: actions/checkout@v4
108+
- name: Set environment variables
109+
if: ${{ inputs.windows_env_vars }}
110+
run: |
111+
$lines = "${{ inputs.windows_env_vars }}" -split "`r`n"
112+
foreach ($line in $lines) {
113+
echo $line | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
114+
}
96115
- name: Pull Docker image
97116
id: pull_docker_image
117+
if: ${{ inputs.enable_windows_docker }}
98118
run: |
99119
if ("${{ matrix.swift_version }}".Contains("nightly")) {
100120
$Image = "swiftlang/swift:${{ matrix.swift_version }}-windowsservercore-1809"
@@ -103,6 +123,12 @@ jobs:
103123
}
104124
docker pull $Image
105125
echo "image=$Image" >> "$env:GITHUB_OUTPUT"
126+
- name: Install Visual Studio Build Tools
127+
if: ${{ !inputs.enable_windows_docker }}
128+
run: . .github\workflows\scripts\windows\install-vsb.ps1
129+
- name: Install Swift
130+
if: ${{ !inputs.enable_windows_docker }}
131+
run: . .github\workflows\scripts\windows\swift\install-swift-${{ matrix.swift_version }}.ps1
106132
- name: Create test script
107133
run: |
108134
mkdir $env:TEMP\test-script
@@ -123,7 +149,14 @@ jobs:
123149
${{ inputs.windows_pre_build_command }}
124150
Invoke-Program ${{ inputs.windows_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
125151
'@ >> $env:TEMP\test-script\run.ps1
152+
# Docker build
126153
- name: Build / Test
127154
timeout-minutes: 60
155+
if: ${{ !inputs.enable_windows_docker }}
128156
run: |
129157
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
158+
# Docker-less build
159+
- name: Build / Test
160+
timeout-minutes: 60
161+
if: ${{ inputs.enable_windows_docker }}
162+
run: powershell.exe -NoLogo -File $env:TEMP\test-script\run.ps1

0 commit comments

Comments
 (0)