Skip to content

Commit 95df194

Browse files
committed
Allow execution of a pre-build command before testing a package on Windows
1 parent eb15ee4 commit 95df194

File tree

1 file changed

+39
-7
lines changed

1 file changed

+39
-7
lines changed

.github/workflows/swift_package_test.yml

+39-7
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:
@@ -84,13 +88,27 @@ jobs:
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
93+
- name: Pull Docker image
94+
run: docker pull swift:${{ matrix.swift_version }}-windowsservercore-ltsc2022
95+
- name: Create test script
96+
run: |
97+
mkdir $env:TEMP\test-script
98+
echo @'
99+
Set-PSDebug -Trace 1
100+
$ErrorActionPreference = "Stop"
101+
${{ inputs.windows_pre_build_command }}
102+
'@ >> $env:TEMP\test-script\pre-build.ps1
103+
104+
echo 'swift --version || (exit /b 1)' >> $env:TEMP\test-script\run.cmd
105+
echo 'swift test --version || (exit /b 1)' >> $env:TEMP\test-script\run.cmd
106+
echo 'cd C:\source\ || (exit /b 1)' >> $env:TEMP\test-script\run.cmd
107+
echo 'powershell.exe -NoLogo -File C:\test-script\pre-build.ps1 || (exit /b 1)' >> $env:TEMP\test-script\run.cmd
108+
echo '${{ inputs.windows_build_command }} ${{ inputs.swift_flags }} || (exit /b 1)' >> $env:TEMP\test-script\run.cmd
91109
- name: Build / Test
92110
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 }}"
111+
run: docker run -v ${{ github.workspace }}:C:\source -v $env:TEMP\test-script:C:\test-script swift:${{ matrix.swift_version }}-windowsservercore-ltsc2022 C:\test-script\run.cmd
94112

95113
windows-nightly-build:
96114
name: Windows (${{ matrix.swift_version }} - windows-2019)
@@ -107,6 +125,20 @@ jobs:
107125
run: docker pull swiftlang/swift:${{ matrix.swift_version }}-windowsservercore-1809
108126
- name: Checkout repository
109127
uses: actions/checkout@v4
128+
- name: Create test script
129+
run: |
130+
mkdir $env:TEMP\test-script
131+
echo @'
132+
Set-PSDebug -Trace 1
133+
$ErrorActionPreference = "Stop"
134+
${{ inputs.windows_pre_build_command }}
135+
'@ >> $env:TEMP\test-script\pre-build.ps1
136+
137+
echo 'swift --version || (exit /b 1)' >> $env:TEMP\test-script\run.cmd
138+
echo 'swift test --version || (exit /b 1)' >> $env:TEMP\test-script\run.cmd
139+
echo 'cd C:\source\ || (exit /b 1)' >> $env:TEMP\test-script\run.cmd
140+
echo 'powershell.exe -NoLogo -File C:\test-script\pre-build.ps1 || (exit /b 1)' >> $env:TEMP\test-script\run.cmd
141+
echo '${{ inputs.windows_build_command }} ${{ inputs.swift_flags }} || (exit /b 1)' >> $env:TEMP\test-script\run.cmd
110142
- name: Build / Test
111143
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 }}"
144+
run: docker run -v ${{ github.workspace }}:C:\source -v $env:TEMP\test-script:C:\test-script swiftlang/swift:${{ matrix.swift_version }}-windowsservercore-1809 C:\test-script\run.cmd

0 commit comments

Comments
 (0)