Skip to content

Commit

Permalink
[CI] Change how we define the matrix
Browse files Browse the repository at this point in the history
# Motivation

# Modification

# Result
  • Loading branch information
FranzBusch committed Oct 24, 2024
1 parent be823e6 commit 908c3bc
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
unit-tests:
name: Unit tests
# Workaround https://github.com/nektos/act/issues/1875
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
uses: ./.github/workflows/unit_tests.yml
with:
linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
Expand Down
82 changes: 72 additions & 10 deletions .github/workflows/swift_matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,31 +148,93 @@ jobs:
apt-get -qq update && apt-get -qq -y install curl
curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/check-matrix-job.sh | bash
generate-matrix:
runs-on: ubuntu-latest
outputs:
linux-matrix: ${{ steps.set-matrix.outputs.linux-matrix }}
windows-matrix: ${{ steps.set-matrix.outputs.windows-matrix }}
windows-nightly-matrix: ${{ steps.set-matrix.outputs.windows-nightly-matrix }}
steps:
- id: set-matrix
env:
LINUX_5_9_ENABLED: ${{ inputs.matrix_linux_5_9_enabled }}
LINUX_5_10_ENABLED: ${{ inputs.matrix_linux_5_10_enabled }}
LINUX_6_0_ENABLED: ${{ inputs.matrix_linux_6_0_enabled }}
LINUX_NIGHTLY_6_0_ENABLED: ${{ inputs.matrix_linux_nightly_6_0_enabled }}
LINUX_NIGHTLY_MAIN_ENABLED: ${{ inputs.matrix_linux_nightly_main_enabled }}
WINDOWS_6_0_ENABLED: ${{ inputs.matrix_windows_6_0_enabled }}
WINDOWS_NIGHTLY_6_0_ENABLED: ${{ inputs.matrix_windows_nightly_6_0_enabled }}
WINDOWS_NIGHTLY_MAIN_ENABLED: ${{ inputs.matrix_windows_nightly_main_enabled }}
run: |
# Linux matrix
linux_matrix='{"swift": []}'
if [[ "${LINUX_5_9_ENABLED}" == "true" ]]; then
linux_matrix=$(echo "$linux_matrix" | jq '.swift[.swift| length] |= . + { "image": "${{ inputs.matrix_linux_5_9_container_image }}", "swift_version": "5.9" }')
elif [[ "${LINUX_5_10_ENABLED}" == "true" ]]; then
linux_matrix=$(echo "$linux_matrix" | jq '.swift[.swift| length] |= . + { "image": "${{ inputs.matrix_linux_5_10_container_image }}", "swift_version": "5.10" }')
elif [[ "${LINUX_6_0_ENABLED}" == "true" ]]; then
linux_matrix=$(echo "$linux_matrix" | jq '.swift[.swift| length] |= . + { "image": "${{ inputs.matrix_linux_6_0_container_image }}", "swift_version": "6.0" }')
elif [[ "${LINUX_NIGHTLY_6_0_ENABLED}" == "true" ]]; then
linux_matrix=$(echo "$linux_matrix" | jq '.swift[.swift| length] |= . + { "image": "${{ inputs.matrix_linux_nightly_6_0_container_image }}", "swift_version": "nightly-6.0" }')
elif [[ "${LINUX_NIGHTLY_MAIN_ENABLED}" == "true" ]]; then
linux_matrix=$(echo "$linux_matrix" | jq '.swift[.swift| length] |= . + { "image": "${{ inputs.matrix_linux_nightly_main_container_image }}", "swift_version": "nightly-main" }')
fi
{
echo 'linx-matrix<<EOF'
echo $linux_matrix
echo EOF
} >> "$GITHUB_OUTPUT"
# Windows matrix
windows_matrix='{"swift": []}'
if [[ "${WINDOWS_6_0_ENABLED}" == "true" ]]; then
windows_matrix=$(echo "$windows_matrix" | jq '.swift[.swift| length] |= . + { "image": "swift:6.0-windowsservercore-ltsc2022", "swift_version": "6.0" }')
fi
{
echo 'windows-matrix<<EOF'
echo $windows_matrix
echo EOF
} >> "$GITHUB_OUTPUT"
# Windows nightly matrix
windows_nightly_matrix='{"swift": []}'
if [[ "${WINDOWS_NIGHTLY_6_0_ENABLED}" == "true" ]]; then
windows_nightly_matrix=$(echo "$windows_nightly_matrix" | jq '.swift[.swift| length] |= . + { "image": "swiftlang/swift:nightly-6.0-windowsservercore-1809", "swift_version": "nightly-6.0" }')
elif [[ "${WINDOWS_NIGHTLY_MAIN_ENABLED}" == "true" ]]; then
windows_nightly_matrix=$(echo "$windows_nightly_matrix" | jq '.swift[.swift| length] |= . + { "image": "swiftlang/swift:nightly-main-windowsservercore-1809", "swift_version": "nightly-main" }')
fi
{
echo 'windows-nightly-matrix<<EOF'
echo $windows_nightly_matrix
echo EOF
} >> "$GITHUB_OUTPUT"
echo "$GITHUB_OUTPUT"
- run: |
echo "${{ steps.set-matrix.outputs.linux-matrix }}"
echo "${{ steps.set-matrix.outputs.windows-matrix }}"
echo "${{ steps.set-matrix.outputs.windows-nightly-matrix }}"
windows:
name: Windows (${{ matrix.swift.swift_version }})
needs: generate-matrix
runs-on: windows-2022
strategy:
fail-fast: false
matrix:
# We are specifying only the major and minor of the docker images to automatically pick up the latest patch release
swift:
- image: swift:6.0-windowsservercore-ltsc2022
swift_version: "6.0"
enabled: ${{ inputs.matrix_windows_6_0_enabled }}
matrix: ${{fromJson(needs.generate-matrix.outputs.windows-matrix)}}
steps:
- name: Pull Docker image
if: ${{ matrix.swift.enabled }}
run: docker pull ${{ matrix.swift.image }}
- name: Checkout repository
if: ${{ matrix.swift.enabled }}
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Donwload matrix script
if: ${{ matrix.swift.enabled }}
run: curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/check-matrix-job.ps1 -o __check-matrix-job.ps1
- name: Run matrix job
if: ${{ matrix.swift.enabled }}
run: |
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"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
unit-tests:
name: Unit tests
# Workaround https://github.com/nektos/act/issues/1875
uses: apple/swift-nio/.github/workflows/swift_matrix.yml@main
uses: ./.github/workflows/swift_matrix.yml
with:
name: "Unit tests"
matrix_linux_command: "swift test"
Expand Down

0 comments on commit 908c3bc

Please sign in to comment.