Skip to content

Commit 908c3bc

Browse files
committed
[CI] Change how we define the matrix
# Motivation # Modification # Result
1 parent be823e6 commit 908c3bc

File tree

3 files changed

+74
-12
lines changed

3 files changed

+74
-12
lines changed

.github/workflows/pull_request.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
unit-tests:
1717
name: Unit tests
1818
# Workaround https://github.com/nektos/act/issues/1875
19-
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
19+
uses: ./.github/workflows/unit_tests.yml
2020
with:
2121
linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
2222
linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"

.github/workflows/swift_matrix.yml

+72-10
Original file line numberDiff line numberDiff line change
@@ -148,31 +148,93 @@ jobs:
148148
apt-get -qq update && apt-get -qq -y install curl
149149
curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/check-matrix-job.sh | bash
150150
151+
generate-matrix:
152+
runs-on: ubuntu-latest
153+
outputs:
154+
linux-matrix: ${{ steps.set-matrix.outputs.linux-matrix }}
155+
windows-matrix: ${{ steps.set-matrix.outputs.windows-matrix }}
156+
windows-nightly-matrix: ${{ steps.set-matrix.outputs.windows-nightly-matrix }}
157+
steps:
158+
- id: set-matrix
159+
env:
160+
LINUX_5_9_ENABLED: ${{ inputs.matrix_linux_5_9_enabled }}
161+
LINUX_5_10_ENABLED: ${{ inputs.matrix_linux_5_10_enabled }}
162+
LINUX_6_0_ENABLED: ${{ inputs.matrix_linux_6_0_enabled }}
163+
LINUX_NIGHTLY_6_0_ENABLED: ${{ inputs.matrix_linux_nightly_6_0_enabled }}
164+
LINUX_NIGHTLY_MAIN_ENABLED: ${{ inputs.matrix_linux_nightly_main_enabled }}
165+
WINDOWS_6_0_ENABLED: ${{ inputs.matrix_windows_6_0_enabled }}
166+
WINDOWS_NIGHTLY_6_0_ENABLED: ${{ inputs.matrix_windows_nightly_6_0_enabled }}
167+
WINDOWS_NIGHTLY_MAIN_ENABLED: ${{ inputs.matrix_windows_nightly_main_enabled }}
168+
run: |
169+
# Linux matrix
170+
linux_matrix='{"swift": []}'
171+
if [[ "${LINUX_5_9_ENABLED}" == "true" ]]; then
172+
linux_matrix=$(echo "$linux_matrix" | jq '.swift[.swift| length] |= . + { "image": "${{ inputs.matrix_linux_5_9_container_image }}", "swift_version": "5.9" }')
173+
elif [[ "${LINUX_5_10_ENABLED}" == "true" ]]; then
174+
linux_matrix=$(echo "$linux_matrix" | jq '.swift[.swift| length] |= . + { "image": "${{ inputs.matrix_linux_5_10_container_image }}", "swift_version": "5.10" }')
175+
elif [[ "${LINUX_6_0_ENABLED}" == "true" ]]; then
176+
linux_matrix=$(echo "$linux_matrix" | jq '.swift[.swift| length] |= . + { "image": "${{ inputs.matrix_linux_6_0_container_image }}", "swift_version": "6.0" }')
177+
elif [[ "${LINUX_NIGHTLY_6_0_ENABLED}" == "true" ]]; then
178+
linux_matrix=$(echo "$linux_matrix" | jq '.swift[.swift| length] |= . + { "image": "${{ inputs.matrix_linux_nightly_6_0_container_image }}", "swift_version": "nightly-6.0" }')
179+
elif [[ "${LINUX_NIGHTLY_MAIN_ENABLED}" == "true" ]]; then
180+
linux_matrix=$(echo "$linux_matrix" | jq '.swift[.swift| length] |= . + { "image": "${{ inputs.matrix_linux_nightly_main_container_image }}", "swift_version": "nightly-main" }')
181+
fi
182+
183+
{
184+
echo 'linx-matrix<<EOF'
185+
echo $linux_matrix
186+
echo EOF
187+
} >> "$GITHUB_OUTPUT"
188+
189+
# Windows matrix
190+
windows_matrix='{"swift": []}'
191+
if [[ "${WINDOWS_6_0_ENABLED}" == "true" ]]; then
192+
windows_matrix=$(echo "$windows_matrix" | jq '.swift[.swift| length] |= . + { "image": "swift:6.0-windowsservercore-ltsc2022", "swift_version": "6.0" }')
193+
fi
194+
195+
{
196+
echo 'windows-matrix<<EOF'
197+
echo $windows_matrix
198+
echo EOF
199+
} >> "$GITHUB_OUTPUT"
200+
201+
# Windows nightly matrix
202+
windows_nightly_matrix='{"swift": []}'
203+
if [[ "${WINDOWS_NIGHTLY_6_0_ENABLED}" == "true" ]]; then
204+
windows_nightly_matrix=$(echo "$windows_nightly_matrix" | jq '.swift[.swift| length] |= . + { "image": "swiftlang/swift:nightly-6.0-windowsservercore-1809", "swift_version": "nightly-6.0" }')
205+
elif [[ "${WINDOWS_NIGHTLY_MAIN_ENABLED}" == "true" ]]; then
206+
windows_nightly_matrix=$(echo "$windows_nightly_matrix" | jq '.swift[.swift| length] |= . + { "image": "swiftlang/swift:nightly-main-windowsservercore-1809", "swift_version": "nightly-main" }')
207+
fi
208+
209+
{
210+
echo 'windows-nightly-matrix<<EOF'
211+
echo $windows_nightly_matrix
212+
echo EOF
213+
} >> "$GITHUB_OUTPUT"
214+
215+
echo "$GITHUB_OUTPUT"
216+
- run: |
217+
echo "${{ steps.set-matrix.outputs.linux-matrix }}"
218+
echo "${{ steps.set-matrix.outputs.windows-matrix }}"
219+
echo "${{ steps.set-matrix.outputs.windows-nightly-matrix }}"
220+
151221
windows:
152222
name: Windows (${{ matrix.swift.swift_version }})
223+
needs: generate-matrix
153224
runs-on: windows-2022
154225
strategy:
155226
fail-fast: false
156-
matrix:
157-
# We are specifying only the major and minor of the docker images to automatically pick up the latest patch release
158-
swift:
159-
- image: swift:6.0-windowsservercore-ltsc2022
160-
swift_version: "6.0"
161-
enabled: ${{ inputs.matrix_windows_6_0_enabled }}
227+
matrix: ${{fromJson(needs.generate-matrix.outputs.windows-matrix)}}
162228
steps:
163229
- name: Pull Docker image
164-
if: ${{ matrix.swift.enabled }}
165230
run: docker pull ${{ matrix.swift.image }}
166231
- name: Checkout repository
167-
if: ${{ matrix.swift.enabled }}
168232
uses: actions/checkout@v4
169233
with:
170234
persist-credentials: false
171235
- name: Donwload matrix script
172-
if: ${{ matrix.swift.enabled }}
173236
run: curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/check-matrix-job.ps1 -o __check-matrix-job.ps1
174237
- name: Run matrix job
175-
if: ${{ matrix.swift.enabled }}
176238
run: |
177239
docker run --env SWIFT_VERSION="${{ matrix.swift.swift_version }}" --env COMMAND="${{ inputs.matrix_windows_command }}" --env COMMAND_OVERRIDE_6_0="${{ inputs.matrix_windows_6_0_command_override }}" -v ${{ github.workspace }}:C:\source ${{ matrix.swift.image }} cmd /s /c "swift --version & cd C:\source\ & powershell -File __check-matrix-job.ps1"
178240

.github/workflows/unit_tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
unit-tests:
7474
name: Unit tests
7575
# Workaround https://github.com/nektos/act/issues/1875
76-
uses: apple/swift-nio/.github/workflows/swift_matrix.yml@main
76+
uses: ./.github/workflows/swift_matrix.yml
7777
with:
7878
name: "Unit tests"
7979
matrix_linux_command: "swift test"

0 commit comments

Comments
 (0)