Skip to content

Commit bc31587

Browse files
authored
Merge pull request #67 from award999/dockerless-windows
Dockerless windows
2 parents aced105 + 948d7c6 commit bc31587

8 files changed

+223
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift.org open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0 with Runtime Library Exception
7+
##
8+
## See https://swift.org/LICENSE.txt for license information
9+
## See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
##
11+
##===----------------------------------------------------------------------===##
12+
$VSB='https://download.visualstudio.microsoft.com/download/pr/5536698c-711c-4834-876f-2817d31a2ef2/c792bdb0fd46155de19955269cac85d52c4c63c23db2cf43d96b9390146f9390/vs_BuildTools.exe'
13+
$VSB_SHA256='C792BDB0FD46155DE19955269CAC85D52C4C63C23DB2CF43D96B9390146F9390'
14+
Set-Variable ErrorActionPreference Stop
15+
Set-Variable ProgressPreference SilentlyContinue
16+
Write-Host -NoNewLine ('Downloading {0} ... ' -f ${VSB})
17+
Invoke-WebRequest -Uri $VSB -OutFile $env:TEMP\vs_buildtools.exe
18+
Write-Host 'SUCCESS'
19+
Write-Host -NoNewLine ('Verifying SHA256 ({0}) ... ' -f $VSB_SHA256)
20+
$Hash = Get-FileHash $env:TEMP\vs_buildtools.exe -Algorithm sha256
21+
if ($Hash.Hash -eq $VSB_SHA256) {
22+
Write-Host 'SUCCESS'
23+
} else {
24+
Write-Host ('FAILED ({0})' -f $Hash.Hash)
25+
exit 1
26+
}
27+
Write-Host -NoNewLine 'Installing Visual Studio Build Tools ... '
28+
$Process =
29+
Start-Process $env:TEMP\vs_buildtools.exe -Wait -PassThru -NoNewWindow -ArgumentList @(
30+
'--quiet',
31+
'--wait',
32+
'--norestart',
33+
'--nocache',
34+
'--add', 'Microsoft.VisualStudio.Component.Windows11SDK.22000',
35+
'--add', 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64'
36+
)
37+
if ($Process.ExitCode -eq 0 -or $Process.ExitCode -eq 3010) {
38+
Write-Host 'SUCCESS'
39+
} else {
40+
Write-Host ('FAILED ({0})' -f $Process.ExitCode)
41+
exit 1
42+
}
43+
Remove-Item -Force $env:TEMP\vs_buildtools.exe
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift.org open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0 with Runtime Library Exception
7+
##
8+
## See https://swift.org/LICENSE.txt for license information
9+
## See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
##
11+
##===----------------------------------------------------------------------===##
12+
. $PSScriptRoot\install-swift.ps1
13+
14+
$SWIFT='https://download.swift.org/swift-5.10.1-release/windows10/swift-5.10.1-RELEASE/swift-5.10.1-RELEASE-windows10.exe'
15+
$SWIFT_SHA256='3027762138ACFA1BBE3050FF6613BBE754332E84C9EFA5C23984646009297286'
16+
17+
Install-Swift -Url $SWIFT -Sha256 $SWIFT_SHA256
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift.org open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0 with Runtime Library Exception
7+
##
8+
## See https://swift.org/LICENSE.txt for license information
9+
## See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
##
11+
##===----------------------------------------------------------------------===##
12+
. $PSScriptRoot\install-swift.ps1
13+
14+
$SWIFT='https://download.swift.org/swift-5.9.2-release/windows10/swift-5.9.2-RELEASE/swift-5.9.2-RELEASE-windows10.exe'
15+
$SWIFT_SHA256='D78A717551C78E824C9B74B0CFB1AD86060FC286EA071FDDB26DF18F56DC7212'
16+
17+
Install-Swift -Url $SWIFT -Sha256 $SWIFT_SHA256
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift.org open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0 with Runtime Library Exception
7+
##
8+
## See https://swift.org/LICENSE.txt for license information
9+
## See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
##
11+
##===----------------------------------------------------------------------===##
12+
. $PSScriptRoot\install-swift.ps1
13+
14+
$SWIFT='https://download.swift.org/swift-6.0.2-release/windows10/swift-6.0.2-RELEASE/swift-6.0.2-RELEASE-windows10.exe'
15+
$SWIFT_SHA256='516FE8E64713BD92F03C01E5198011B74A27F8C1C88627607A2F421718636126'
16+
17+
Install-Swift -Url $SWIFT -Sha256 $SWIFT_SHA256
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift.org open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0 with Runtime Library Exception
7+
##
8+
## See https://swift.org/LICENSE.txt for license information
9+
## See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
##
11+
##===----------------------------------------------------------------------===##
12+
. $PSScriptRoot\install-swift.ps1
13+
14+
$SWIFT_RELEASE_METADATA='http://download.swift.org/swift-6.0-branch/windows10/latest-build.json'
15+
$Release = curl.exe -sL ${SWIFT_RELEASE_METADATA}
16+
$SWIFT_URL = "https://download.swift.org/swift-6.0-branch/windows10/$($($Release | ConvertFrom-JSON).dir)/$($($Release | ConvertFrom-JSON).download)"
17+
18+
Install-Swift -Url $SWIFT_URL -Sha256 ""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift.org open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0 with Runtime Library Exception
7+
##
8+
## See https://swift.org/LICENSE.txt for license information
9+
## See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
##
11+
##===----------------------------------------------------------------------===##
12+
. $PSScriptRoot\install-swift.ps1
13+
14+
$SWIFT_RELEASE_METADATA='http://download.swift.org/development/windows10/latest-build.json'
15+
$Release = curl.exe -sL ${SWIFT_RELEASE_METADATA}
16+
$SWIFT_URL = "https://download.swift.org/development/windows10/$($($Release | ConvertFrom-JSON).dir)/$($($Release | ConvertFrom-JSON).download)"
17+
18+
Install-Swift -Url $SWIFT_URL -Sha256 ""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift.org open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0 with Runtime Library Exception
7+
##
8+
## See https://swift.org/LICENSE.txt for license information
9+
## See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
##
11+
##===----------------------------------------------------------------------===##
12+
function Install-Swift {
13+
param (
14+
[string]$Url,
15+
[string]$Sha256
16+
)
17+
Set-Variable ErrorActionPreference Stop
18+
Set-Variable ProgressPreference SilentlyContinue
19+
Write-Host -NoNewLine ('Downloading {0} ... ' -f $url)
20+
Invoke-WebRequest -Uri $url -OutFile installer.exe
21+
Write-Host 'SUCCESS'
22+
Write-Host -NoNewLine ('Verifying SHA256 ({0}) ... ' -f $Sha256)
23+
$Hash = Get-FileHash installer.exe -Algorithm sha256
24+
if ($Hash.Hash -eq $Sha256 -or $Sha256 -eq "") {
25+
Write-Host 'SUCCESS'
26+
} else {
27+
Write-Host ('FAILED ({0})' -f $Hash.Hash)
28+
exit 1
29+
}
30+
Write-Host -NoNewLine 'Installing Swift ... '
31+
$Process = Start-Process installer.exe -Wait -PassThru -NoNewWindow -ArgumentList @(
32+
'/quiet',
33+
'/norestart'
34+
)
35+
if ($Process.ExitCode -eq 0) {
36+
Write-Host 'SUCCESS'
37+
} else {
38+
Write-Host ('FAILED ({0})' -f $Process.ExitCode)
39+
exit 1
40+
}
41+
Remove-Item -Force installer.exe
42+
}

.github/workflows/swift_package_test.yml

+51-3
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
@@ -87,14 +99,22 @@ jobs:
8799
strategy:
88100
fail-fast: false
89101
matrix:
90-
swift_version: ['5.9', '6.0', 'nightly', 'nightly-6.0']
102+
swift_version: ['5.9', '5.10', '6.0', 'nightly', 'nightly-6.0']
91103
exclude:
92104
- ${{ fromJson(inputs.windows_exclude_swift_versions) }}
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,9 +123,27 @@ 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: |
129+
Invoke-WebRequest -Uri https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/windows/install-vsb.ps1 -OutFile $env:TEMP\install-vsb.ps1
130+
. $env:TEMP\install-vsb.ps1
131+
del $env:TEMP\install-vsb.ps1
132+
- name: Install Swift
133+
if: ${{ !inputs.enable_windows_docker }}
134+
run: |
135+
Invoke-WebRequest -Uri https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/windows/swift/install-swift.ps1 -OutFile $env:TEMP\install-swift.ps1
136+
Invoke-WebRequest -Uri https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/windows/swift/install-swift-${{ matrix.swift_version }}.ps1 -OutFile $env:TEMP\install-swift-${{ matrix.swift_version }}.ps1
137+
. $env:TEMP\install-swift-${{ matrix.swift_version }}.ps1
138+
del $env:TEMP\install-swift*.ps1
106139
- name: Create test script
107140
run: |
108141
mkdir $env:TEMP\test-script
142+
if ("${{ inputs.enable_windows_docker }}" -eq "true") {
143+
$Source = C:\source
144+
} else {
145+
$Source = $env:GITHUB_WORKSPACE
146+
}
109147
echo @'
110148
Set-PSDebug -Trace 1
111149
@@ -119,11 +157,21 @@ jobs:
119157
}
120158
Invoke-Program swift --version
121159
Invoke-Program swift test --version
122-
Invoke-Program cd C:\source\
160+
Invoke-Program cd $Source
123161
${{ inputs.windows_pre_build_command }}
124162
Invoke-Program ${{ inputs.windows_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
125163
'@ >> $env:TEMP\test-script\run.ps1
126-
- name: Build / Test
164+
# Docker build
165+
- name: Docker Build / Test
127166
timeout-minutes: 60
167+
if: ${{ inputs.enable_windows_docker }}
128168
run: |
129169
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
170+
# Docker-less build
171+
- name: Build / Test
172+
timeout-minutes: 60
173+
if: ${{ !inputs.enable_windows_docker }}
174+
run: |
175+
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
176+
RefreshEnv
177+
powershell.exe -NoLogo -File $env:TEMP\test-script\run.ps1; exit $LastExitCode

0 commit comments

Comments
 (0)