Skip to content

Commit 236a54f

Browse files
authored
Merge pull request #45 from ahoppen/windows-pre-build
Allow execution of a pre-build command before testing a package on Windows
2 parents ef820df + a77f41b commit 236a54f

File tree

1 file changed

+34
-26
lines changed

1 file changed

+34
-26
lines changed

.github/workflows/swift_package_test.yml

+34-26
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,22 @@ on:
2929
default: ""
3030
linux_build_command:
3131
type: string
32-
description: "Linux Build command default is swift test"
32+
description: "Linux command to build and test the package"
3333
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: ""
3438
windows_build_command:
3539
type: string
36-
description: "Linux Build command default is swift test"
40+
description: "Windows Command Prompt command to build and test the package"
3741
default: "swift test"
3842
linux_env_vars:
3943
description: "List of environment variables"
4044
type: string
4145
enable_windows_checks:
4246
type: boolean
43-
description: "Boolean to enable windows testing. Defaults to true."
47+
description: "Boolean to enable windows testing. Defaults to true"
4448
default: true
4549

4650
jobs:
@@ -76,37 +80,41 @@ jobs:
7680
windows-build:
7781
name: Windows (${{ matrix.swift_version }} - windows-2022)
7882
if: ${{ inputs.enable_windows_checks }}
79-
runs-on: windows-2022
83+
runs-on: ${{ contains(matrix.swift_version, 'nightly') && 'windows-2019' || 'windows-2022' }}
8084
strategy:
8185
fail-fast: false
8286
matrix:
83-
swift_version: ['5.9', '6.0']
87+
swift_version: ['5.9', '6.0', 'nightly', 'nightly-6.0']
8488
exclude:
8589
- ${{ fromJson(inputs.windows_exclude_swift_versions) }}
8690
steps:
87-
- name: Pull Docker image
88-
run: docker pull swift:${{ matrix.swift_version }}-windowsservercore-ltsc2022
8991
- name: Checkout repository
9092
uses: actions/checkout@v4
91-
- name: Build / Test
92-
timeout-minutes: 60
93-
run: docker run -v ${{ github.workspace }}:C:\source swift:${{ matrix.swift_version }}-windowsservercore-ltsc2022 cmd /s /c "swift --version & swift test --version & cd C:\source\ & ${{ inputs.windows_build_command }} ${{ inputs.swift_flags }}"
94-
95-
windows-nightly-build:
96-
name: Windows (${{ matrix.swift_version }} - windows-2019)
97-
if: ${{ inputs.enable_windows_checks }}
98-
runs-on: windows-2019
99-
strategy:
100-
fail-fast: false
101-
matrix:
102-
swift_version: ['nightly', 'nightly-6.0']
103-
exclude:
104-
- ${{ fromJson(inputs.windows_exclude_swift_versions) }}
105-
steps:
10693
- name: Pull Docker image
107-
run: docker pull swiftlang/swift:${{ matrix.swift_version }}-windowsservercore-1809
108-
- name: Checkout repository
109-
uses: actions/checkout@v4
94+
id: pull_docker_image
95+
run: |
96+
if ("${{ matrix.swift_version }}".Contains("nightly")) {
97+
$Image = "swiftlang/swift:${{ matrix.swift_version }}-windowsservercore-1809"
98+
} else {
99+
$Image = "swift:${{ matrix.swift_version }}-windowsservercore-ltsc2022"
100+
}
101+
docker pull $Image
102+
echo "image=$Image" >> "$env:GITHUB_OUTPUT"
103+
- name: Create test script
104+
run: |
105+
mkdir $env:TEMP\test-script
106+
echo @'
107+
Set-PSDebug -Trace 1
108+
$ErrorActionPreference = "Stop"
109+
${{ inputs.windows_pre_build_command }}
110+
'@ >> $env:TEMP\test-script\pre-build.ps1
111+
112+
echo 'swift --version || (exit /b 1)' >> $env:TEMP\test-script\run.cmd
113+
echo 'swift test --version || (exit /b 1)' >> $env:TEMP\test-script\run.cmd
114+
echo 'cd C:\source\ || (exit /b 1)' >> $env:TEMP\test-script\run.cmd
115+
echo 'powershell.exe -NoLogo -File C:\test-script\pre-build.ps1 || (exit /b 1)' >> $env:TEMP\test-script\run.cmd
116+
echo '${{ inputs.windows_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }} || (exit /b 1)' >> $env:TEMP\test-script\run.cmd
110117
- name: Build / Test
111118
timeout-minutes: 60
112-
run: docker run -v ${{ github.workspace }}:C:\source swiftlang/swift:${{ matrix.swift_version }}-windowsservercore-1809 cmd /s /c "swift --version & swift test --version & cd C:\source\ & ${{ inputs.windows_build_command }} ${{ inputs.swift_nightly_flags }}"
119+
run: |
120+
docker run -v ${{ github.workspace }}:C:\source -v $env:TEMP\test-script:C:\test-script ${{ steps.pull_docker_image.outputs.image }} C:\test-script\run.cmd

0 commit comments

Comments
 (0)