From 1eb066df4475a83f3f6e1d3af98692397fdaaebc Mon Sep 17 00:00:00 2001 From: Franz Busch Date: Wed, 23 Oct 2024 15:28:32 +0200 Subject: [PATCH] [CI] Change how we define the matrix # Motivation # Modification # Result --- .github/workflows/pull_request.yml | 34 +------- .github/workflows/swift_matrix.yml | 132 +++++++++++++++++++---------- .github/workflows/unit_tests.yml | 8 +- 3 files changed, 90 insertions(+), 84 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index c1ac0581f3..241226d5ba 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -5,46 +5,14 @@ on: types: [opened, reopened, synchronize] jobs: - soundness: - name: Soundness - uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main - with: - license_header_check_project_name: "SwiftNIO" - # We need to move to 6.0 here but have to fix the new warnings first - docs_check_container_image: "swift:5.10-noble" 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" linux_6_0_arguments_override: "--explicit-target-dependency-import-check error" linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error" linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error" - - benchmarks: - name: Benchmarks - # Workaround https://github.com/nektos/act/issues/1875 - uses: apple/swift-nio/.github/workflows/benchmarks.yml@main - with: - benchmark_package_path: "Benchmarks" - - cxx-interop: - name: Cxx interop - # Workaround https://github.com/nektos/act/issues/1875 - uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main - - integration-tests: - name: Integration Tests - # Workaround https://github.com/nektos/act/issues/1875 - uses: apple/swift-nio/.github/workflows/swift_matrix.yml@main - with: - name: "Integration tests" - matrix_linux_command: "apt-get update -y -q && apt-get install -y -q lsof dnsutils netcat-openbsd net-tools curl jq && ./scripts/integration_tests.sh" - - swift-6-language-mode: - name: Swift 6 Language Mode - # Workaround https://github.com/nektos/act/issues/1875 - uses: apple/swift-nio/.github/workflows/swift_6_language_mode.yml@main diff --git a/.github/workflows/swift_matrix.yml b/.github/workflows/swift_matrix.yml index a5d0b798b6..c6ff50c2b4 100644 --- a/.github/workflows/swift_matrix.yml +++ b/.github/workflows/swift_matrix.yml @@ -74,21 +74,21 @@ on: matrix_windows_6_0_enabled: type: boolean description: "Boolean to enable the 6.0 Swift version matrix job. Defaults to true." - default: false + default: true matrix_windows_6_0_command_override: type: string description: "The command of the 6.0 Swift version windows matrix job to execute." matrix_windows_nightly_6_0_enabled: type: boolean description: "Boolean to enable the nightly 6.0 Swift version matrix job. Defaults to true." - default: false + default: true matrix_windows_nightly_6_0_command_override: type: string description: "The command of the nightly 6.0 Swift version windows matrix job to execute." matrix_windows_nightly_main_enabled: type: boolean description: "Boolean to enable the nightly main Swift version matrix job. Defaults to true." - default: false + default: true matrix_windows_nightly_main_command_override: type: string description: "The command of the nightly main Swift version windows matrix job to execute." @@ -99,43 +99,100 @@ concurrency: cancel-in-progress: true jobs: + 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='{"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" }') + fi + + if [[ "${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" }') + fi + + if [[ "${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" }') + fi + + if [[ "${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" }') + fi + + if [[ "${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 'linux-matrix<> "$GITHUB_OUTPUT" + + 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<> "$GITHUB_OUTPUT" + + 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" }') + fi + + if [[ "${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<> "$GITHUB_OUTPUT" + - name: Echo matrix configuration + run: | + echo "${{ steps.set-matrix.outputs.linux-matrix }}" + echo "${{ steps.set-matrix.outputs.windows-matrix }}" + echo "${{ steps.set-matrix.outputs.windows-nightly-matrix }}" + linux: name: Linux (${{ matrix.swift.swift_version }}) + needs: generate-matrix runs-on: ubuntu-latest 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: ${{ inputs.matrix_linux_5_9_container_image }} - swift_version: "5.9" - enabled: ${{ inputs.matrix_linux_5_9_enabled }} - - image: ${{ inputs.matrix_linux_5_10_container_image }} - swift_version: "5.10" - enabled: ${{ inputs.matrix_linux_5_10_enabled }} - - image: ${{ inputs.matrix_linux_6_0_container_image }} - swift_version: "6.0" - enabled: ${{ inputs.matrix_linux_6_0_enabled }} - - image: ${{ inputs.matrix_linux_nightly_6_0_container_image }} - swift_version: "nightly-6.0" - enabled: ${{ inputs.matrix_linux_nightly_6_0_enabled }} - - image: ${{ inputs.matrix_linux_nightly_main_container_image }} - swift_version: "nightly-main" - enabled: ${{ inputs.matrix_linux_nightly_main_enabled }} + matrix: ${{fromJson(needs.generate-matrix.outputs.linux-matrix)}} container: image: ${{ matrix.swift.image }} steps: - name: Checkout repository - if: ${{ matrix.swift.enabled }} uses: actions/checkout@v4 with: persist-credentials: false - name: Mark the workspace as safe - if: ${{ matrix.swift.enabled }} # https://github.com/actions/checkout/issues/766 run: git config --global --add safe.directory ${GITHUB_WORKSPACE} - name: Run matrix job - if: ${{ matrix.swift.enabled }} env: SWIFT_VERSION: ${{ matrix.swift.swift_version }} COMMAND: ${{ inputs.matrix_linux_command }} @@ -150,59 +207,40 @@ jobs: 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" windows-nightly: name: Windows (${{ matrix.swift.swift_version }}) + needs: generate-matrix runs-on: windows-2019 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: swiftlang/swift:nightly-6.0-windowsservercore-1809 - swift_version: "nightly-6.0" - enabled: ${{ inputs.matrix_windows_nightly_6_0_enabled }} - - image: swiftlang/swift:nightly-main-windowsservercore-1809 - swift_version: "nightly-main" - enabled: ${{ inputs.matrix_windows_nightly_main_enabled }} + matrix: ${{fromJson(needs.generate-matrix.outputs.windows-nightly-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_NIGHTLY_6_0="${{ inputs.matrix_windows_nightly_6_0_command_override }}" --env COMMAND_OVERRIDE_NIGHTLY_MAIN="${{ inputs.matrix_windows_nightly_main_command_override }}" -v ${{ github.workspace }}:C:\source ${{ matrix.swift.image }} cmd /s /c "swift --version & cd C:\source\ & powershell -File __check-matrix-job.ps1" diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 8a70518bb6..9765bb430a 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -47,7 +47,7 @@ on: windows_6_0_enabled: type: boolean description: "Boolean to enable the Windows 6.0 Swift version matrix job. Defaults to true." - default: false + default: true windows_6_0_arguments_override: type: string description: "The arguments passed to swift test in the Windows 6.0 Swift version matrix job." @@ -55,7 +55,7 @@ on: windows_nightly_6_0_enabled: type: boolean description: "Boolean to enable the Windows nightly 6.0 Swift version matrix job. Defaults to true." - default: false + default: true windows_nightly_6_0_arguments_override: type: string description: "The arguments passed to swift test in the Windows nightly 6.0 Swift version matrix job." @@ -63,7 +63,7 @@ on: windows_nightly_main_enabled: type: boolean description: "Boolean to enable the Windows nightly main Swift version matrix job. Defaults to true." - default: false + default: true windows_nightly_main_arguments_override: type: string description: "The arguments passed to swift test in the Windows nightly main Swift version matrix job." @@ -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"