Skip to content

Commit 48e7b83

Browse files
committed
Share docker-less setup with swiftlang github-workflows
(copied file for now for testing)
1 parent 7b21a91 commit 48e7b83

File tree

9 files changed

+237
-57
lines changed

9 files changed

+237
-57
lines changed

.github/workflows/pull_request.yml

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ jobs:
2020

2121
tests:
2222
name: Test
23-
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
23+
uses: ./.github/workflows/swift_package_test.yml
2424
with:
25+
# Linux
2526
linux_exclude_swift_versions: '[{"swift_version": "nightly-main"}]'
2627
linux_env_vars: |
2728
NODE_VERSION=v18.19.0
@@ -36,9 +37,21 @@ jobs:
3637
/bin/bash -c "source $NVM_DIR/nvm.sh && nvm install $NODE_VERSION"
3738
echo "$NODE_PATH" >> $GITHUB_PATH
3839
linux_build_command: ./docker/test.sh
39-
enable_windows_checks: false
40+
enable_linux_checks: false
41+
# Windows
42+
enable_windows_checks: true
43+
enable_windows_docker: false
44+
windows_exclude_swift_versions: '[{"swift_version": "nightly-main"}]'
45+
windows_env_vars: |
46+
CI=1
47+
FAST_TEST_RUN=1
48+
windows_pre_build_command: .github\workflows\scripts\windows\install-nodejs.ps1
49+
windows_build_command: docker\test-windows.ps1
4050

4151
tests-windows:
52+
defaults:
53+
run:
54+
shell: powershell
4255
name: Windows (${{ matrix.swift_version }})
4356
runs-on: ${{ contains(matrix.swift_version, 'nightly') && 'windows-2019' || 'windows-2022' }}
4457
strategy:
@@ -50,18 +63,16 @@ jobs:
5063
uses: actions/checkout@v4
5164
- name: Install node.js
5265
if: ${{ !vars.skip_nodejs_install }}
53-
run: powershell.exe -NoLogo -File $env:GITHUB_WORKSPACE\.github\workflows\scripts\windows\install-nodejs.ps1
66+
run: . .github\workflows\scripts\windows\install-nodejs.ps1
5467
- name: Install Visual Studio Build Tools
5568
if: ${{ !vars.skip_vsb_install }}
56-
run: powershell.exe -NoLogo -File $env:GITHUB_WORKSPACE\.github\workflows\scripts\windows\install-vsb.ps1
69+
run: . .github\workflows\scripts\windows\install-vsb.ps1
5770
- name: Install Swift
5871
if: ${{ !vars.skip_swift_install }}
59-
run: powershell.exe -NoLogo -File $env:GITHUB_WORKSPACE\.github\workflows\scripts\windows\swift\install-swift-${{ matrix.swift_version }}.ps1
60-
- name: Check dependencies
61-
run: |
62-
swift --version
63-
node --version
64-
- name: Create test script
72+
run: . .github\workflows\scripts\windows\swift\install-swift-${{ matrix.swift_version }}.ps1
73+
- name: Build / Test
6574
run: |
6675
cd $env:GITHUB_WORKSPACE
67-
powershell.exe -NoLogo -File docker\test-windows.ps1
76+
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
77+
refreshenv
78+
docker\test-windows.ps1

.github/workflows/scripts/windows/install-nodejs.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
$NODEJS='https://nodejs.org/dist/v18.20.4/node-v18.20.4-x64.msi'
22
$NODEJS_SHA256='c2654d3557abd59de08474c6dd009b1d358f420b8e4010e4debbf130b1dfb90a'
3+
Set-Variable ErrorActionPreference Stop
4+
Set-Variable ProgressPreference SilentlyContinue
35
Write-Host -NoNewLine ('Downloading {0} ... ' -f ${NODEJS})
46
Invoke-WebRequest -Uri ${NODEJS} -OutFile $env:TEMP\node.msi
57
Write-Host 'SUCCESS'

.github/workflows/scripts/windows/install-vsb.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
$VSB='https://aka.ms/vs/17/release/vs_buildtools.exe'
22
$VSB_SHA256='99C7677154366062A43082921F40F3CE00EF2614DBF94DB23B244DD13DC9443D'
3+
Set-Variable ErrorActionPreference Stop
4+
Set-Variable ProgressPreference SilentlyContinue
35
Write-Host -NoNewLine ('Downloading {0} ... ' -f ${VSB})
46
Invoke-WebRequest -Uri $VSB -OutFile $env:TEMP\vs_buildtools.exe
57
Write-Host 'SUCCESS'
Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,6 @@
1+
. $PSScriptRoot\install-swift.ps1
2+
13
$SWIFT='https://download.swift.org/swift-5.10.1-release/windows10/swift-5.10.1-RELEASE/swift-5.10.1-RELEASE-windows10.exe'
24
$SWIFT_SHA256='3027762138ACFA1BBE3050FF6613BBE754332E84C9EFA5C23984646009297286'
3-
Write-Host -NoNewLine ('Downloading {0} ... ' -f ${env:SWIFT})
4-
Invoke-WebRequest -Uri ${env:SWIFT} -OutFile installer.exe
5-
Write-Host 'SUCCESS'
6-
Write-Host -NoNewLine ('Verifying SHA256 ({0}) ... ' -f ${env:SWIFT_SHA256})
7-
$Hash = Get-FileHash installer.exe -Algorithm sha256
8-
if ($Hash.Hash -eq ${env:SWIFT_SHA256}) {
9-
Write-Host 'SUCCESS'
10-
} else {
11-
Write-Host ('FAILED ({0})' -f $Hash.Hash)
12-
exit 1
13-
}
14-
Write-Host -NoNewLine 'Installing Swift ... '
15-
$Process = Start-Process installer.exe -Wait -PassThru -NoNewWindow -ArgumentList @(
16-
'/quiet',
17-
'/norestart'
18-
)
19-
if ($Process.ExitCode -eq 0) {
20-
Write-Host 'SUCCESS'
21-
} else {
22-
Write-Host ('FAILED ({0})' -f $Process.ExitCode)
23-
exit 1
24-
}
25-
Remove-Item -Force installer.exe
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: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,6 @@
1+
. $PSScriptRoot\install-swift.ps1
2+
13
$SWIFT='https://download.swift.org/swift-6.0.2-release/windows10/swift-6.0.2-RELEASE/swift-6.0.2-RELEASE-windows10.exe'
24
$SWIFT_SHA256='516FE8E64713BD92F03C01E5198011B74A27F8C1C88627607A2F421718636126'
3-
Write-Host -NoNewLine ('Downloading {0} ... ' -f $SWIFT)
4-
Invoke-WebRequest -Uri $SWIFT -OutFile installer.exe
5-
Write-Host 'SUCCESS'
6-
Write-Host -NoNewLine ('Verifying SHA256 ({0}) ... ' -f $SWIFT_SHA256)
7-
$Hash = Get-FileHash installer.exe -Algorithm sha256
8-
if ($Hash.Hash -eq $SWIFT_SHA256) {
9-
Write-Host 'SUCCESS'
10-
} else {
11-
Write-Host ('FAILED ({0})' -f $Hash.Hash)
12-
exit 1
13-
}
14-
Write-Host -NoNewLine 'Installing Swift ... '
15-
$Process = Start-Process installer.exe -Wait -PassThru -NoNewWindow -ArgumentList @(
16-
'/quiet',
17-
'/norestart'
18-
)
19-
if ($Process.ExitCode -eq 0) {
20-
Write-Host 'SUCCESS'
21-
} else {
22-
Write-Host ('FAILED ({0})' -f $Process.ExitCode)
23-
exit 1
24-
}
25-
Remove-Item -Force installer.exe
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: 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: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
name: Swift Linux Matrix
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
linux_exclude_swift_versions:
7+
type: string
8+
description: "Exclude Linux Swift version list (JSON)"
9+
default: "[{\"swift_version\": \"\"}]"
10+
linux_os_versions:
11+
type: string
12+
description: "Linux OS version list (JSON)"
13+
default: "[\"jammy\"]"
14+
windows_exclude_swift_versions:
15+
type: string
16+
description: "Exclude Windows Swift version list (JSON)"
17+
default: "[{\"swift_version\": \"\"}]"
18+
swift_flags:
19+
type: string
20+
description: "Swift flags for release version"
21+
default: ""
22+
swift_nightly_flags:
23+
type: string
24+
description: "Swift flags for nightly version"
25+
default: ""
26+
linux_pre_build_command:
27+
type: string
28+
description: "Linux command to execute before building the Swift package"
29+
default: ""
30+
linux_build_command:
31+
type: string
32+
description: "Linux command to build and test the package"
33+
default: "swift test"
34+
windows_pre_build_command:
35+
type: string
36+
description: "Windows Command Prompt command to execute before building the Swift package"
37+
default: ""
38+
windows_build_command:
39+
type: string
40+
description: "Windows Command Prompt command to build and test the package"
41+
default: "swift test"
42+
linux_env_vars:
43+
description: "List of environment variables"
44+
type: string
45+
windows_env_vars:
46+
description: "List of environment variables"
47+
type: string
48+
enable_linux_checks:
49+
type: boolean
50+
description: "Boolean to enable linux testing. Defaults to true"
51+
default: true
52+
enable_windows_checks:
53+
type: boolean
54+
description: "Boolean to enable windows testing. Defaults to true"
55+
default: true
56+
enable_windows_docker:
57+
type: boolean
58+
description: "Boolean to enable running build in windows docker container. Defaults to true"
59+
default: true
60+
61+
jobs:
62+
linux-build:
63+
name: Linux (${{ matrix.swift_version }} - ${{ matrix.os_version }})
64+
if: ${{ inputs.enable_linux_checks }}
65+
runs-on: ubuntu-latest
66+
strategy:
67+
fail-fast: false
68+
matrix:
69+
swift_version: ['5.8', '5.9', '5.10', '6.0', 'nightly-main', 'nightly-6.0']
70+
os_version: ${{ fromJson(inputs.linux_os_versions) }}
71+
exclude:
72+
- ${{ fromJson(inputs.linux_exclude_swift_versions) }}
73+
container:
74+
image: ${{ (contains(matrix.swift_version, 'nightly') && 'swiftlang/swift') || 'swift' }}:${{ matrix.swift_version }}-${{ matrix.os_version }}
75+
steps:
76+
- name: Swift version
77+
run: swift --version
78+
- name: Checkout repository
79+
uses: actions/checkout@v4
80+
- name: Set environment variables
81+
if: ${{ inputs.linux_env_vars }}
82+
run: |
83+
for i in "${{ inputs.linux_env_vars }}"
84+
do
85+
printf "%s\n" $i | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
86+
done
87+
- name: Pre-build
88+
run: ${{ inputs.linux_pre_build_command }}
89+
- name: Build / Test
90+
run: ${{ inputs.linux_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
91+
92+
windows-build:
93+
name: Windows (${{ matrix.swift_version }} - windows-2022)
94+
if: ${{ inputs.enable_windows_checks }}
95+
runs-on: ${{ contains(matrix.swift_version, 'nightly') && 'windows-2019' || 'windows-2022' }}
96+
outputs:
97+
image: ${{ steps.pull_docker_image.outputs.image }}
98+
strategy:
99+
fail-fast: false
100+
matrix:
101+
swift_version: ['5.9', '5.10', '6.0', 'nightly', 'nightly-6.0']
102+
exclude:
103+
- ${{ fromJson(inputs.windows_exclude_swift_versions) }}
104+
steps:
105+
- name: Checkout repository
106+
uses: actions/checkout@v4
107+
- name: Set environment variables
108+
if: ${{ inputs.windows_env_vars }}
109+
run: |
110+
$lines = "${{ inputs.windows_env_vars }}" -split "`r`n"
111+
foreach ($line in $lines) {
112+
echo $line | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
113+
}
114+
- name: Pull Docker image
115+
id: pull_docker_image
116+
if: ${{ inputs.enable_windows_docker }}
117+
run: |
118+
if ("${{ matrix.swift_version }}".Contains("nightly")) {
119+
$Image = "swiftlang/swift:${{ matrix.swift_version }}-windowsservercore-1809"
120+
} else {
121+
$Image = "swift:${{ matrix.swift_version }}-windowsservercore-ltsc2022"
122+
}
123+
docker pull $Image
124+
echo "image='$Image'" >> $env:GITHUB_OUTPUT
125+
cat "$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
132+
- name: Create test script
133+
run: |
134+
mkdir $env:TEMP\test-script
135+
echo 'Set-PSDebug -Trace 1' >> $env:TEMP\test-script\run.ps1
136+
echo '$ErrorActionPreference = "Stop"' >> $env:TEMP\test-script\run.ps1
137+
echo 'swift --version' >> $env:TEMP\test-script\run.ps1
138+
echo 'swift test --version' >> $env:TEMP\test-script\run.ps1
139+
echo 'cd C:\source\' >> $env:TEMP\test-script\run.ps1
140+
echo @'
141+
${{ inputs.windows_pre_build_command }}
142+
'@ >> $env:TEMP\test-script\run.ps1
143+
echo '${{ inputs.windows_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}' >> $env:TEMP\test-script\run.ps1
144+
# Docker build
145+
- name: Build / Test
146+
timeout-minutes: 60
147+
if: ${{ !inputs.enable_windows_docker }}
148+
run: |
149+
if ("${{ matrix.swift_version }}".Contains("nightly")) {
150+
$Image = "swiftlang/swift:${{ matrix.swift_version }}-windowsservercore-1809"
151+
} else {
152+
$Image = "swift:${{ matrix.swift_version }}-windowsservercore-ltsc2022"
153+
}
154+
docker run -v ${{ github.workspace }}:C:\source -v $env:TEMP\test-script:C:\test-script "$Image" powershell.exe -NoLogo -File C:\test-script\run.ps1
155+
# Docker-less build
156+
- name: Build / Test
157+
timeout-minutes: 60
158+
if: ${{ inputs.enable_windows_docker }}
159+
run: . $env:TEMP\test-script\run.ps1

0 commit comments

Comments
 (0)