Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
rnro committed Nov 28, 2024
1 parent bd94260 commit 46f0c52
Show file tree
Hide file tree
Showing 3 changed files with 268 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

unit-tests:
name: Unit tests
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
uses: ./.github/workflows/swift_test_matrix.yml
with:
linux_5_9_arguments_override: "--explicit-target-dependency-import-check error"
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error"
Expand Down
114 changes: 114 additions & 0 deletions .github/workflows/swift_test_matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: Matrix

on:
workflow_call:
inputs:
name:
type: string
description: "The name of the workflow used for the concurrency group."
required: true
matrix_path:
type: string
description: "The path of the test matrix definition."
default: ""
matrix_string:
type: string
description: "The test matrix definition."
default: ""

# We are cancelling previously triggered workflow runs
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.name }}
cancel-in-progress: true

jobs:
generate-matrix:
name: Prepare matrices
runs-on: ubuntu-latest
outputs:
linux-matrix: ${{ steps.load-matrix.outputs.linux-matrix }}
windows-matrix: ${{ steps.load-matrix.outputs.windows-matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Mark the workspace as safe
# https://github.com/actions/checkout/issues/766
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
- id: file_check
run: |
if [ ! -z '${{ inputs.matrix_string }}' ]; then
echo "matrix_string_populated=true" >> $GITHUB_ENV
else
echo "matrix_string_populated=false" >> $GITHUB_ENV
fi
- id: cat-matrix
if: ${{ env.matrix_string_populated == 'false' }}
run: |
jq -c '{linux: .linux}' ${{ inputs.matrix_path }} >| __linux_coverage_matrix.json
jq -c '{windows: .windows}' ${{ inputs.matrix_path }} >| __windows_coverage_matrix.json
- id: write-matrix
if: ${{ env.matrix_string_populated == 'true' }}
run: |
echo '${{ inputs.matrix_string }}' | jq -c '{linux: .linux}' >| __linux_coverage_matrix.json
echo '${{ inputs.matrix_string }}' | jq -c '{windows: .windows}' >| __windows_coverage_matrix.json
cat __linux_coverage_matrix.json
cat __windows_coverage_matrix.json
- id: load-matrix
run: |
{
echo 'linux-matrix<<EOF'
echo "$(cat __linux_coverage_matrix.json)"
echo EOF
} >> "$GITHUB_OUTPUT"
{
echo 'windows-matrix<<EOF'
echo "$(cat __windows_coverage_matrix.json)"
echo EOF
} >> "$GITHUB_OUTPUT"
linux:
name: Linux (${{ matrix.linux.name }})
needs: generate-matrix
runs-on: ${{ matrix.linux.runner }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.generate-matrix.outputs.linux-matrix) }}
container:
image: ${{ matrix.linux.image }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Mark the workspace as safe
# https://github.com/actions/checkout/issues/766
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
- name: Pre-build
if: ${{ matrix.linux.setup_command }}
run: |
${{ matrix.linux.setup_command }}
- name: Run matrix job
run: |
${{ matrix.linux.command }} ${{ matrix.linux.command_arguments }}
windows:
name: Windows (${{ matrix.windows.name }})
needs: generate-matrix
runs-on: ${{ matrix.windows.runner }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.generate-matrix.outputs.windows-matrix) }}
steps:
- name: Pull Docker image
run: docker pull ${{ matrix.windows.image }}
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
submodules: true
- name: Run matrix job
run: |
docker run --env -v ${{ github.workspace }}:C:\source ${{ matrix.swift.image }} cmd /s /c "swift --version & cd C:\source\ & powershell Invoke-Expression ${{ matrix.windows.pre_run_command }} & powershell Invoke-Expression ${{ matrix.windows.command }} ${{ matrix.windows.command_arguments }}"
153 changes: 153 additions & 0 deletions scripts/generate_matrix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#!/bin/bash
##===----------------------------------------------------------------------===##
##
## This source file is part of the SwiftNIO open source project
##
## Copyright (c) 2024 Apple Inc. and the SwiftNIO project authors
## Licensed under Apache License v2.0
##
## See LICENSE.txt for license information
## See CONTRIBUTORS.txt for the list of SwiftNIO project authors
##
## SPDX-License-Identifier: Apache-2.0
##
##===----------------------------------------------------------------------===##

# Parameters
linux_command="$MATRIX_LINUX_COMMAND" # required if any Linux pipeline is enabled
linux_setup_command="$MATRIX_LINUX_SETUP_COMMAND"
linux_5_9_enabled="${MATRIX_LINUX_5_9_ENABLED:true}"
linux_5_9_command_arguments="$MATRIX_LINUX_5_9_COMMAND_ARGUMENTS"
linux_5_10_enabled="${MATRIX_LINUX_5_10_ENABLED:true}"
linux_5_10_command_arguments="$MATRIX_LINUX_5_10_COMMAND_ARGUMENTS"
linux_6_0_enabled="${MATRIX_LINUX_6_0_ENABLED:true}"
linux_6_0_command_arguments="$MATRIX_LINUX_6_0_COMMAND_ARGUMENTS"
linux_nightly_6_0_enabled="${MATRIX_LINUX_NIGHTLY_6_0_ENABLED:true}"
linux_nightly_6_0_command_arguments="$MATRIX_LINUX_NIGHTLY_6_0_COMMAND_ARGUMENTS"
linux_nightly_main_enabled="${MATRIX_LINUX_NIGHTLY_MAIN_ENABLED:true}"
linux_nightly_main_command_arguments="$MATRIX_LINUX_NIGHTLY_MAIN_COMMAND_ARGUMENTS"

windows_command="$MATRIX_WINDOWS_COMMAND" # required if any Windows pipeline is enabled
windows_setup_command="$MATRIX_WINDOWS_SETUP_COMMAND"
windows_6_0_enabled="${MATRIX_WINDOWS_6_0_ENABLED:false}"
windows_6_0_command_arguments="$MATRIX_WINDOWS_6_0_COMMAND_ARGUMENTS"
windows_nightly_6_0_enabled="${MATRIX_WINDOWS_NIGHTLY_6_0_ENABLED:false}"
windows_nightly_6_0_command_arguments="$MATRIX_WINDOWS_NIGHTLY_6_0_COMMAND_ARGUMENTS"
windows_nightly_main_enabled="${MATRIX_WINDOWS_NIGHTLY_MAIN_ENABLED:false}"
windows_nightly_main_command_arguments="$MATRIX_WINDOWS_NIGHTLY_MAIN_COMMAND_ARGUMENTS"

# Defaults
linux_runner="ubuntu-latest"
linux_5_9_container_image="swift:5.9-jammy"
linux_5_10_container_image="swift:5.10-jammy"
linux_6_0_container_image="swift:6.0-jammy"
linux_nightly_6_0_container_image="swiftlang/swift:nightly-6.0-jammy"
linux_nightly_main_container_image="swiftlang/swift:nightly-main-jammy"

windows_6_0_runner="windows-2022"
windows_6_0_container_image="swift:6.0-windowsservercore-ltsc2022"
windows_nightly_6_0_runner="windows-2019"
windows_nightly_6_0_container_image="swift:nightly-6.0-windowsservercore-1809"
windows_nightly_main_runner="windows-2019"
windows_nightly_main_container_image="swift:nightly-main-windowsservercore-1809"

# Create matrix from inputs
matrix='{"linux": [], "windows": [], "macos": []}'

## Linux
if [[ "$linux_5_9_enabled" == "true" || "$linux_5_10_enabled" == "true" || "$linux_6_0_enabled" == "true" || \
"$linux_nightly_6_0_enabled" == "true" || "$linux_nightly_main_enabled" == "true" ]]; then
if [[ -z "$linux_command" ]]; then
echo "No linux command defined"; exit 1
fi
fi


if [[ "$linux_5_9_enabled" == "true" ]]; then
matrix=$(echo "$matrix" | jq -c \
--arg setup_command "$linux_setup_command" \
--arg command "$linux_command" \
--arg command_arguments "$linux_5_9_command_arguments" \
--arg container_image "$linux_5_9_container_image" \
--arg runner "$linux_runner" \
'.linux[.linux| length] |= . + { "name": "5.9", "image": $container_image, "swift_version": "5.9", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner}')
fi

if [[ "$linux_5_10_enabled" == "true" ]]; then
matrix=$(echo "$matrix" | jq -c \
--arg setup_command "$linux_setup_command" \
--arg command "$linux_command" \
--arg command_arguments "$linux_5_10_command_arguments" \
--arg container_image "$linux_5_10_container_image" \
--arg runner "$linux_runner" \
'.linux[.linux| length] |= . + { "name": "5.10", "image": $container_image, "swift_version": "5.10", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner}')
fi

if [[ "$linux_6_0_enabled" == "true" ]]; then
matrix=$(echo "$matrix" | jq -c \
--arg setup_command "$linux_setup_command" \
--arg command "$linux_command" \
--arg command_arguments "$linux_6_0_command_arguments" \
--arg container_image "$linux_6_0_container_image" \
--arg runner "$linux_runner" \
'.linux[.linux| length] |= . + { "name": "6.0", "image": $container_image, "swift_version": "6.0", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner}')
fi

if [[ "$linux_nightly_6_0_enabled" == "true" ]]; then
matrix=$(echo "$matrix" | jq -c \
--arg setup_command "$linux_setup_command" \
--arg command "$linux_command" \
--arg command_arguments "$linux_nightly_6_0_command_arguments" \
--arg container_image "$linux_nightly_6_0_container_image" \
--arg runner "$linux_runner" \
'.linux[.linux| length] |= . + { "name": "nightly-6.0", "image": $container_image, "swift_version": "nightly-6.0", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner}')
fi

if [[ "$linux_nightly_main_enabled" == "true" ]]; then
matrix=$(echo "$matrix" | jq -c \
--arg setup_command "$linux_setup_command" \
--arg command "$linux_command" \
--arg command_arguments "$linux_nightly_main_command_arguments" \
--arg container_image "$linux_nightly_main_container_image" \
--arg runner "$linux_runner" \
'.linux[.linux| length] |= . + { "name": "nightly-main", "image": $container_image, "swift_version": "nightly-main", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner}')
fi

## Windows
if [[ "$windows_6_0_enabled" == "true" || "$windows_nightly_6_0_enabled" == "true" || "$windows_nightly_main_enabled" == "true" ]]; then
if [[ -z "$windows_command" ]]; then
echo "No windows command defined"; exit 1
fi
fi

if [[ "$windows_6_0_enabled" == "true" ]]; then
matrix=$(echo "$matrix" | jq -c \
--arg setup_command "$windows_setup_command" \
--arg command "$windows_command" \
--arg command_arguments "$windows_6_0_command_arguments" \
--arg container_image "$windows_6_0_container_image" \
--arg runner "$windows_6_0_runner" \
'.windows[.windows| length] |= . + { "name": "6.0", "image": $container_image, "swift_version": "6.0", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner }')
fi

if [[ "$windows_nightly_6_0_enabled" == "true" ]]; then
matrix=$(echo "$matrix" | jq -c \
--arg setup_command "$windows_setup_command" \
--arg command "$windows_command" \
--arg command_arguments "$windows_nightly_6_0_command_arguments" \
--arg container_image "$windows_nightly_6_0_container_image" \
--arg runner "$windows_nightly_6_0_runner" \
'.windows[.windows| length] |= . + { "name": "nightly-6.0", "image": $container_image, "swift_version": "nightly-6.0", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner }')
fi

if [[ "$windows_nightly_main_enabled" == "true" ]]; then
matrix=$(echo "$matrix" | jq -c \
--arg setup_command "$windows_setup_command" \
--arg command "$windows_command" \
--arg command_arguments "$windows_nightly_main_command_arguments" \
--arg container_image "$windows_nightly_main_container_image" \
--arg runner "$windows_nightly_main_runner" \
'.windows[.windows| length] |= . + { "name": "nightly-main", "image": $container_image, "swift_version": "nightly-main", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner }')
fi

echo "$matrix" | jq -c

0 comments on commit 46f0c52

Please sign in to comment.