mirror of
https://github.com/apple/swift-nio
synced 2026-11-26 04:57:49 +00:00
Matrix custom env vars (#3376)
Allow the specification of custom environment variables in our matrix workflow and those which use it. ### Motivation: It can be useful to supply custom environment variables to control build and runtime options. ### Modifications: Allow users to supply a string of custom environment variable key-value pairs which are supplied to the docker container running the matrix commands. To attempt to avoid issues with this string concatenation the change also allows the user to specify custom list entry and key-value-pair separators. To avoid parameter bloat the env vars are set for all Swift versions, hopefully that's sufficient for now. ### Result: Adopters can Examples of this working on Linux and Windows, note the presence of the test environment variables I injected: - https://github.com/apple/swift-nio/actions/runs/17917619451/job/50943847555?pr=3376 - https://github.com/apple/swift-crypto/pull/413/checks e.g. ``` Executing Docker command: docker run -v /home/runner/work/swift-nio/swift-nio:/swift-nio -w /swift-nio -e CI=true -e GITHUB_ACTIONS=true -e SWIFT_VERSION=6.0 -e workspace=/swift-nio -e TEST_DEBUG=1 -e TEST_LOG_LEVEL=info swift:6.0-jammy bash -c swift --version && swift test -Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error ```
This commit is contained in:
1 parent
6c114e3c62
commit
154706efd3
8 files changed
+264
-66
No files matched your search
@@ -68,6 +68,11 @@ on:
|
||||
description: "Boolean to enable the Windows nightly main Swift version matrix job. Currently has no effect!" # TODO: implement Windows benchmarking
|
||||
default: false
|
||||
|
||||
linux_env_vars:
|
||||
type: string
|
||||
description: "Environment variables for Linux jobs as JSON (e.g., '{\"DEBUG\":\"1\",\"LOG_LEVEL\":\"info\"}')."
|
||||
default: "{}"
|
||||
|
||||
jobs:
|
||||
construct-matrix:
|
||||
name: Construct Benchmarks matrix
|
||||
@@ -80,7 +85,16 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- id: generate-matrix
|
||||
run: echo "benchmarks-matrix=$(curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/generate_matrix.sh | bash)" >> "$GITHUB_OUTPUT"
|
||||
run: |
|
||||
# Validate JSON environment variables
|
||||
linux_env_vars_json='${{ inputs.linux_env_vars }}'
|
||||
|
||||
if ! echo "$linux_env_vars_json" | jq empty 2>/dev/null; then
|
||||
echo "Error: linux_env_vars is not valid JSON"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "benchmarks-matrix=$(curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/generate_matrix.sh | MATRIX_LINUX_ENV_VARS_JSON="${linux_env_vars_json}" bash)" >> "$GITHUB_OUTPUT"
|
||||
env:
|
||||
MATRIX_LINUX_COMMAND: "curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/check_benchmark_thresholds.sh | BENCHMARK_PACKAGE_PATH=${{ inputs.benchmark_package_path }} bash"
|
||||
MATRIX_LINUX_SETUP_COMMAND: "swift --version && apt-get update -y -q && apt-get install -y -q curl libjemalloc-dev && git config --global --add safe.directory /$(basename ${{ github.workspace }})"
|
||||
|
||||
@@ -61,6 +61,15 @@ on:
|
||||
description: "Boolean to enable the Windows nightly main Swift version matrix job. Defaults to false. Currently has no effect!" # TODO: implement Windows Cxx compat checking
|
||||
default: false
|
||||
|
||||
linux_env_vars:
|
||||
type: string
|
||||
description: "Environment variables for Linux jobs as JSON (e.g., '{\"DEBUG\":\"1\",\"LOG_LEVEL\":\"info\"}')."
|
||||
default: "{}"
|
||||
windows_env_vars:
|
||||
type: string
|
||||
description: "Environment variables for Windows jobs as JSON (e.g., '{\"DEBUG\":\"1\",\"LOG_LEVEL\":\"info\"}')."
|
||||
default: "{}"
|
||||
|
||||
jobs:
|
||||
construct-matrix:
|
||||
name: Construct Cxx interop matrix
|
||||
@@ -73,7 +82,22 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- id: generate-matrix
|
||||
run: echo "cxx-interop-matrix=$(curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/generate_matrix.sh | bash)" >> "$GITHUB_OUTPUT"
|
||||
run: |
|
||||
# Validate JSON environment variables
|
||||
linux_env_vars_json='${{ inputs.linux_env_vars }}'
|
||||
windows_env_vars_json='${{ inputs.windows_env_vars }}'
|
||||
|
||||
if ! echo "$linux_env_vars_json" | jq empty 2>/dev/null; then
|
||||
echo "Error: linux_env_vars is not valid JSON"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! echo "$windows_env_vars_json" | jq empty 2>/dev/null; then
|
||||
echo "Error: windows_env_vars is not valid JSON"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "cxx-interop-matrix=$(curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/generate_matrix.sh | MATRIX_LINUX_ENV_VARS_JSON="${linux_env_vars_json}" MATRIX_WINDOWS_ENV_VARS_JSON="${windows_env_vars_json}" bash)" >> "$GITHUB_OUTPUT"
|
||||
env:
|
||||
MATRIX_LINUX_COMMAND: "curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/check-cxx-interop-compatibility.sh | bash"
|
||||
MATRIX_LINUX_SETUP_COMMAND: "swift --version && apt-get update -y -q && apt-get install -y -q curl jq"
|
||||
|
||||
@@ -193,6 +193,11 @@ on:
|
||||
description: "The runner pool which will be requested."
|
||||
default: "nightly"
|
||||
|
||||
env_vars:
|
||||
type: string
|
||||
description: "Environment variables for jobs as JSON (e.g., '{\"DEBUG\":\"1\",\"LOG_LEVEL\":\"info\"}')."
|
||||
default: "{}"
|
||||
|
||||
jobs:
|
||||
construct-matrix:
|
||||
name: Construct Darwin matrix
|
||||
@@ -206,6 +211,15 @@ jobs:
|
||||
persist-credentials: false
|
||||
- id: generate-matrix
|
||||
run: |
|
||||
# Validate and use JSON environment variables directly
|
||||
env_vars_json='${{ inputs.env_vars }}'
|
||||
|
||||
# Validate JSON format
|
||||
if ! echo "$env_vars_json" | jq empty 2>/dev/null; then
|
||||
echo "Error: env_vars is not valid JSON"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cat >> "$GITHUB_OUTPUT" << EOM
|
||||
darwin-matrix=$(
|
||||
runner_pool="${MATRIX_RUNNER_POOL:="nightly"}"
|
||||
@@ -255,7 +269,8 @@ jobs:
|
||||
--arg build_arguments_override "$xcode_15_4_build_arguments_override" \
|
||||
--arg test_arguments_override "$xcode_15_4_test_arguments_override" \
|
||||
--arg runner_pool "$runner_pool" \
|
||||
'.config[.config| length] |= . + { "name": "Xcode 15.4", "xcode_version": "15.4", "xcode_app": "Xcode_15.4.app", "setup_command": $setup_command, "build_arguments_override": $build_arguments_override, "test_arguments_override": $test_arguments_override, "os": "sequoia", "arch": "ARM64", "pool": $runner_pool }')
|
||||
--argjson env_vars "$env_vars_json" \
|
||||
'.config[.config| length] |= . + { "name": "Xcode 15.4", "xcode_version": "15.4", "xcode_app": "Xcode_15.4.app", "setup_command": $setup_command, "build_arguments_override": $build_arguments_override, "test_arguments_override": $test_arguments_override, "os": "sequoia", "arch": "ARM64", "pool": $runner_pool, "env": $env_vars }')
|
||||
fi
|
||||
|
||||
if [[ "$xcode_16_0_enabled" == "true" ]]; then
|
||||
@@ -264,7 +279,8 @@ jobs:
|
||||
--arg build_arguments_override "$xcode_16_0_build_arguments_override" \
|
||||
--arg test_arguments_override "$xcode_16_0_test_arguments_override" \
|
||||
--arg runner_pool "$runner_pool" \
|
||||
'.config[.config| length] |= . + { "name": "Xcode 16.0", "xcode_version": "16.0", "xcode_app": "Xcode_16.0.app", "setup_command": $setup_command, "build_arguments_override": $build_arguments_override, "test_arguments_override": $test_arguments_override, "os": "sequoia", "arch": "ARM64", "pool": $runner_pool }')
|
||||
--argjson env_vars "$env_vars_json" \
|
||||
'.config[.config| length] |= . + { "name": "Xcode 16.0", "xcode_version": "16.0", "xcode_app": "Xcode_16.0.app", "setup_command": $setup_command, "build_arguments_override": $build_arguments_override, "test_arguments_override": $test_arguments_override, "os": "sequoia", "arch": "ARM64", "pool": $runner_pool, "env": $env_vars }')
|
||||
fi
|
||||
|
||||
if [[ "$xcode_16_1_enabled" == "true" ]]; then
|
||||
@@ -273,7 +289,8 @@ jobs:
|
||||
--arg build_arguments_override "$xcode_16_1_build_arguments_override" \
|
||||
--arg test_arguments_override "$xcode_16_1_test_arguments_override" \
|
||||
--arg runner_pool "$runner_pool" \
|
||||
'.config[.config| length] |= . + { "name": "Xcode 16.1", "xcode_version": "16.1", "xcode_app": "Xcode_16.1.app", "setup_command": $setup_command, "build_arguments_override": $build_arguments_override, "test_arguments_override": $test_arguments_override, "os": "sequoia", "arch": "ARM64", "pool": $runner_pool }')
|
||||
--argjson env_vars "$env_vars_json" \
|
||||
'.config[.config| length] |= . + { "name": "Xcode 16.1", "xcode_version": "16.1", "xcode_app": "Xcode_16.1.app", "setup_command": $setup_command, "build_arguments_override": $build_arguments_override, "test_arguments_override": $test_arguments_override, "os": "sequoia", "arch": "ARM64", "pool": $runner_pool, "env": $env_vars }')
|
||||
fi
|
||||
|
||||
if [[ "$xcode_16_2_enabled" == "true" ]]; then
|
||||
@@ -282,7 +299,8 @@ jobs:
|
||||
--arg build_arguments_override "$xcode_16_2_build_arguments_override" \
|
||||
--arg test_arguments_override "$xcode_16_2_test_arguments_override" \
|
||||
--arg runner_pool "$runner_pool" \
|
||||
'.config[.config| length] |= . + { "name": "Xcode 16.2", "xcode_version": "16.2", "xcode_app": "Xcode_16.2.app", "setup_command": $setup_command, "build_arguments_override": $build_arguments_override, "test_arguments_override": $test_arguments_override, "os": "sequoia", "arch": "ARM64", "pool": $runner_pool }')
|
||||
--argjson env_vars "$env_vars_json" \
|
||||
'.config[.config| length] |= . + { "name": "Xcode 16.2", "xcode_version": "16.2", "xcode_app": "Xcode_16.2.app", "setup_command": $setup_command, "build_arguments_override": $build_arguments_override, "test_arguments_override": $test_arguments_override, "os": "sequoia", "arch": "ARM64", "pool": $runner_pool, "env": $env_vars }')
|
||||
fi
|
||||
|
||||
if [[ "$xcode_16_3_enabled" == "true" ]]; then
|
||||
@@ -291,7 +309,8 @@ jobs:
|
||||
--arg build_arguments_override "$xcode_16_3_build_arguments_override" \
|
||||
--arg test_arguments_override "$xcode_16_3_test_arguments_override" \
|
||||
--arg runner_pool "$runner_pool" \
|
||||
'.config[.config| length] |= . + { "name": "Xcode 16.3", "xcode_version": "16.3", "xcode_app": "Xcode_16.3.app", "setup_command": $setup_command, "build_arguments_override": $build_arguments_override, "test_arguments_override": $test_arguments_override, "os": "sequoia", "arch": "ARM64", "pool": $runner_pool }')
|
||||
--argjson env_vars "$env_vars_json" \
|
||||
'.config[.config| length] |= . + { "name": "Xcode 16.3", "xcode_version": "16.3", "xcode_app": "Xcode_16.3.app", "setup_command": $setup_command, "build_arguments_override": $build_arguments_override, "test_arguments_override": $test_arguments_override, "os": "sequoia", "arch": "ARM64", "pool": $runner_pool, "env": $env_vars }')
|
||||
fi
|
||||
|
||||
if [[ "$xcode_16_4_enabled" == "true" ]]; then
|
||||
@@ -300,7 +319,8 @@ jobs:
|
||||
--arg build_arguments_override "$xcode_16_4_build_arguments_override" \
|
||||
--arg test_arguments_override "$xcode_16_4_test_arguments_override" \
|
||||
--arg runner_pool "$runner_pool" \
|
||||
'.config[.config| length] |= . + { "name": "Xcode 16.4", "xcode_version": "16.4", "xcode_app": "Xcode_16.4.app", "setup_command": $setup_command, "build_arguments_override": $build_arguments_override, "test_arguments_override": $test_arguments_override, "os": "sequoia", "arch": "ARM64", "pool": $runner_pool }')
|
||||
--argjson env_vars "$env_vars_json" \
|
||||
'.config[.config| length] |= . + { "name": "Xcode 16.4", "xcode_version": "16.4", "xcode_app": "Xcode_16.4.app", "setup_command": $setup_command, "build_arguments_override": $build_arguments_override, "test_arguments_override": $test_arguments_override, "os": "sequoia", "arch": "ARM64", "pool": $runner_pool, "env": $env_vars }')
|
||||
fi
|
||||
|
||||
if [[ "$xcode_26_0_enabled" == "true" ]]; then
|
||||
@@ -309,7 +329,8 @@ jobs:
|
||||
--arg build_arguments_override "$xcode_26_0_build_arguments_override" \
|
||||
--arg test_arguments_override "$xcode_26_0_test_arguments_override" \
|
||||
--arg runner_pool "$runner_pool" \
|
||||
'.config[.config| length] |= . + { "name": "Xcode 26.0", "xcode_version": "26.0", "xcode_app": "Xcode_26.0.app", "setup_command": $setup_command, "build_arguments_override": $build_arguments_override, "test_arguments_override": $test_arguments_override, "os": "sequoia", "arch": "ARM64", "pool": $runner_pool }')
|
||||
--argjson env_vars "$env_vars_json" \
|
||||
'.config[.config| length] |= . + { "name": "Xcode 26.0", "xcode_version": "26.0", "xcode_app": "Xcode_26.0.app", "setup_command": $setup_command, "build_arguments_override": $build_arguments_override, "test_arguments_override": $test_arguments_override, "os": "sequoia", "arch": "ARM64", "pool": $runner_pool, "env": $env_vars }')
|
||||
fi
|
||||
|
||||
if [[ "$xcode_latest_beta_enabled" == "true" ]]; then
|
||||
@@ -318,7 +339,8 @@ jobs:
|
||||
--arg build_arguments_override "$xcode_latest_beta_build_arguments_override" \
|
||||
--arg test_arguments_override "$xcode_latest_beta_test_arguments_override" \
|
||||
--arg runner_pool "$runner_pool" \
|
||||
'.config[.config| length] |= . + { "name": "Xcode latest beta", "xcode_version": "latest beta", "xcode_app": "Xcode-latest.app", "setup_command": $setup_command, "build_arguments_override": $build_arguments_override, "test_arguments_override": $test_arguments_override, "os": "sequoia", "arch": "ARM64", "pool": $runner_pool }')
|
||||
--argjson env_vars "$env_vars_json" \
|
||||
'.config[.config| length] |= . + { "name": "Xcode latest beta", "xcode_version": "latest beta", "xcode_app": "Xcode-latest.app", "setup_command": $setup_command, "build_arguments_override": $build_arguments_override, "test_arguments_override": $test_arguments_override, "os": "sequoia", "arch": "ARM64", "pool": $runner_pool, "env": $env_vars }')
|
||||
fi
|
||||
|
||||
echo "$matrix" | jq -c
|
||||
@@ -377,6 +399,12 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
submodules: true
|
||||
- name: Export environment variables
|
||||
if: ${{ matrix.config.env != '' && matrix.config.env != '{}'}}
|
||||
run: |
|
||||
echo "Exporting environment variables from matrix configuration..."
|
||||
echo '${{ toJSON(matrix.config.env) }}' | jq -r 'to_entries[] | "\(.key)=\(.value)"' >> $GITHUB_ENV
|
||||
echo '${{ toJSON(matrix.config.env) }}' | jq -r 'to_entries[] | "exporting \(.key)=\(.value)"'
|
||||
- name: Setup command
|
||||
if: ${{ matrix.config.setup_command != '' }}
|
||||
run: bash -c "${{ matrix.config.setup_command }}"
|
||||
|
||||
@@ -93,6 +93,15 @@ on:
|
||||
description: "The arguments passed to swift test in the Windows nightly main Swift version matrix job."
|
||||
default: ""
|
||||
|
||||
linux_env_vars:
|
||||
type: string
|
||||
description: "Environment variables for Linux jobs as JSON (e.g., '{\"DEBUG\":\"1\",\"LOG_LEVEL\":\"info\"}')."
|
||||
default: "{}"
|
||||
windows_env_vars:
|
||||
type: string
|
||||
description: "Environment variables for Windows jobs as JSON (e.g., '{\"DEBUG\":\"1\",\"LOG_LEVEL\":\"info\"}')."
|
||||
default: "{}"
|
||||
|
||||
jobs:
|
||||
construct-matrix:
|
||||
name: Construct release build matrix
|
||||
@@ -105,7 +114,22 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- id: generate-matrix
|
||||
run: echo "release-build-matrix=$(curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/generate_matrix.sh | bash)" >> "$GITHUB_OUTPUT"
|
||||
run: |
|
||||
# Validate JSON environment variables
|
||||
linux_env_vars_json='${{ inputs.linux_env_vars }}'
|
||||
windows_env_vars_json='${{ inputs.windows_env_vars }}'
|
||||
|
||||
if ! echo "$linux_env_vars_json" | jq empty 2>/dev/null; then
|
||||
echo "Error: linux_env_vars is not valid JSON"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! echo "$windows_env_vars_json" | jq empty 2>/dev/null; then
|
||||
echo "Error: windows_env_vars is not valid JSON"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "release-build-matrix=$(curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/generate_matrix.sh | MATRIX_LINUX_ENV_VARS_JSON="${linux_env_vars_json}" MATRIX_WINDOWS_ENV_VARS_JSON="${windows_env_vars_json}" bash)" >> "$GITHUB_OUTPUT"
|
||||
env:
|
||||
MATRIX_LINUX_SETUP_COMMAND: "swift --version"
|
||||
MATRIX_LINUX_COMMAND: "swift build -c release"
|
||||
|
||||
@@ -2,36 +2,69 @@ name: Static SDK
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
env_vars:
|
||||
type: string
|
||||
description: "Environment variables for jobs as JSON (e.g., '{\"DEBUG\":\"1\",\"LOG_LEVEL\":\"info\"}')."
|
||||
default: "{}"
|
||||
|
||||
jobs:
|
||||
construct-matrix:
|
||||
name: Construct Static SDK matrix
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
static-sdk-matrix: '${{ steps.generate-matrix.outputs.static-sdk-matrix }}'
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
- id: generate-matrix
|
||||
run: |
|
||||
# Validate and use JSON environment variables directly
|
||||
env_vars_json='${{ inputs.env_vars }}'
|
||||
|
||||
# Validate JSON format
|
||||
if ! echo "$env_vars_json" | jq empty 2>/dev/null; then
|
||||
echo "Error: env_vars is not valid JSON"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Generate matrix with parsed environment variables
|
||||
cat >> "$GITHUB_OUTPUT" << EOM
|
||||
static-sdk-matrix=$(echo '{
|
||||
"config":[
|
||||
{
|
||||
"name":"latest-release Jammy",
|
||||
"swift_version":"latest-release",
|
||||
"platform":"Linux",
|
||||
"runner":"ubuntu-latest",
|
||||
"image":"ubuntu:jammy",
|
||||
"setup_command":"apt update -q && apt install -y -q curl jq tar && curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/install_swift_prerequisites.sh | bash && curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/install_static_sdk.sh | INSTALL_SWIFT_STATIC_SDK_VERSION=latest INSTALL_SWIFT_STATIC_SDK_ARCH=x86_64 bash && hash -r",
|
||||
"command":"swift build",
|
||||
"command_arguments":"--swift-sdk x86_64-swift-linux-musl",
|
||||
"env":'"$env_vars_json"'
|
||||
},
|
||||
{
|
||||
"name":"main Jammy",
|
||||
"swift_version":"main",
|
||||
"platform":"Linux",
|
||||
"runner":"ubuntu-latest",
|
||||
"image":"ubuntu:jammy",
|
||||
"setup_command":"apt update -q && apt install -y -q curl jq tar && curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/install_swift_prerequisites.sh | bash && curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/install_static_sdk.sh | INSTALL_SWIFT_STATIC_SDK_BRANCH=main INSTALL_SWIFT_STATIC_SDK_ARCH=x86_64 bash && hash -r",
|
||||
"command":"swift build",
|
||||
"command_arguments":"--swift-sdk x86_64-swift-linux-musl",
|
||||
"env":'"$env_vars_json"'
|
||||
}
|
||||
]
|
||||
}' | jq -c)
|
||||
EOM
|
||||
|
||||
static-sdk:
|
||||
name: Static SDK
|
||||
needs: construct-matrix
|
||||
# Workaround https://github.com/nektos/act/issues/1875
|
||||
uses: apple/swift-nio/.github/workflows/swift_test_matrix.yml@main
|
||||
with:
|
||||
name: "Static SDK"
|
||||
matrix_string: >-
|
||||
{
|
||||
"config":[
|
||||
{
|
||||
"name":"latest-release Jammy",
|
||||
"swift_version":"latest-release",
|
||||
"platform":"Linux",
|
||||
"runner":"ubuntu-latest",
|
||||
"image":"ubuntu:jammy",
|
||||
"setup_command":"apt update -q && apt install -y -q curl jq tar && curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/install_swift_prerequisites.sh | bash && curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/install_static_sdk.sh | INSTALL_SWIFT_STATIC_SDK_VERSION=latest INSTALL_SWIFT_STATIC_SDK_ARCH=x86_64 bash && hash -r",
|
||||
"command":"swift build",
|
||||
"command_arguments":"--swift-sdk x86_64-swift-linux-musl"
|
||||
},
|
||||
{
|
||||
"name":"main Jammy",
|
||||
"swift_version":"main",
|
||||
"platform":"Linux",
|
||||
"runner":"ubuntu-latest",
|
||||
"image":"ubuntu:jammy",
|
||||
"setup_command":"apt update -q && apt install -y -q curl jq tar && curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/install_swift_prerequisites.sh | bash && curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/install_static_sdk.sh | INSTALL_SWIFT_STATIC_SDK_BRANCH=main INSTALL_SWIFT_STATIC_SDK_ARCH=x86_64 bash && hash -r",
|
||||
"command":"swift build",
|
||||
"command_arguments":"--swift-sdk x86_64-swift-linux-musl"
|
||||
}
|
||||
]
|
||||
}
|
||||
matrix_string: '${{ needs.construct-matrix.outputs.static-sdk-matrix }}'
|
||||
@@ -41,15 +41,30 @@ jobs:
|
||||
setup_command_expression=""
|
||||
fi
|
||||
workspace="/$(basename ${{ github.workspace }})"
|
||||
docker run -v ${{ github.workspace }}:"$workspace" \
|
||||
-w "$workspace" \
|
||||
-e CI="$CI" \
|
||||
-e GITHUB_ACTIONS="$GITHUB_ACTIONS" \
|
||||
-e SWIFT_VERSION="${{ matrix.config.swift_version }}" \
|
||||
-e setup_command_expression="$setup_command_expression" \
|
||||
-e workspace="$workspace" \
|
||||
${{ matrix.config.image }} \
|
||||
bash -c "$setup_command_expression ${{ matrix.config.command }} ${{ matrix.config.command_arguments }}"
|
||||
|
||||
docker_args=(
|
||||
"run"
|
||||
"-v" "${{ github.workspace }}:$workspace"
|
||||
"-w" "$workspace"
|
||||
"-e" "CI=$CI"
|
||||
"-e" "GITHUB_ACTIONS=$GITHUB_ACTIONS"
|
||||
"-e" "SWIFT_VERSION=${{ matrix.config.swift_version }}"
|
||||
"-e" "workspace=$workspace"
|
||||
)
|
||||
|
||||
if [[ '${{ toJson(matrix.config.env) }}' != '{}' ]]; then
|
||||
while IFS="=" read -r key value; do
|
||||
if [[ -n "$key" && -n "$value" ]]; then
|
||||
docker_args+=("-e" "$key=$value")
|
||||
fi
|
||||
done < <(echo '${{ toJson(matrix.config.env) }}' | jq -r 'to_entries[] | "\(.key)=\(.value)"')
|
||||
fi
|
||||
|
||||
docker_args+=("${{ matrix.config.image }}")
|
||||
docker_args+=("bash" "-c" "$setup_command_expression ${{ matrix.config.command }} ${{ matrix.config.command_arguments }}")
|
||||
|
||||
echo "Executing Docker command: docker ${docker_args[*]}"
|
||||
docker "${docker_args[@]}"
|
||||
- name: Run matrix job (Windows)
|
||||
if: ${{ matrix.config.platform == 'Windows' }}
|
||||
run: |
|
||||
@@ -59,13 +74,29 @@ jobs:
|
||||
$setup_command_expression = ""
|
||||
}
|
||||
$workspace = "C:\" + (Split-Path ${{ github.workspace }} -Leaf)
|
||||
docker run -v ${{ github.workspace }}:$($workspace) `
|
||||
-w $($workspace) `
|
||||
-e CI=%CI% `
|
||||
-e GITHUB_ACTIONS=%GITHUB_ACTIONS% `
|
||||
-e SWIFT_VERSION="${{ matrix.config.swift_version }}" `
|
||||
-e setup_command_expression=%setup_command_expression% `
|
||||
${{ matrix.config.image }} `
|
||||
cmd /s /c "swift --version & $($setup_command_expression) ${{ matrix.config.command }} ${{ matrix.config.command_arguments }}"
|
||||
|
||||
$docker_args = @(
|
||||
"run", "-v", "${{ github.workspace }}:$($workspace)",
|
||||
"-w", $workspace,
|
||||
"-e", "CI=$env:CI",
|
||||
"-e", "GITHUB_ACTIONS=$env:GITHUB_ACTIONS",
|
||||
"-e", "SWIFT_VERSION=${{ matrix.config.swift_version }}"
|
||||
)
|
||||
|
||||
$env_args = @()
|
||||
$env_json = '${{ toJson(matrix.config.env) }}'
|
||||
if ($env_json -ne '{}') {
|
||||
$env_obj = $env_json | ConvertFrom-Json
|
||||
$env_obj.PSObject.Properties | ForEach-Object {
|
||||
$env_args += "-e"
|
||||
$env_args += "$($_.Name)=$($_.Value)"
|
||||
}
|
||||
}
|
||||
$docker_args += $env_args
|
||||
|
||||
$docker_args += @("${{ matrix.config.image }}", "cmd", "/s", "/c", "swift --version & $($setup_command_expression) ${{ matrix.config.command }} ${{ matrix.config.command_arguments }}")
|
||||
|
||||
Write-Host "Executing Docker command: docker $($docker_args -join ' ')"
|
||||
& docker @docker_args
|
||||
env:
|
||||
SWIFT_VERSION: ${{ matrix.config.swift_version }}
|
||||
@@ -133,6 +133,15 @@ on:
|
||||
description: "The arguments passed to swift test in the Windows nightly main Swift version matrix job."
|
||||
default: ""
|
||||
|
||||
linux_env_vars:
|
||||
type: string
|
||||
description: "Environment variables for Linux jobs as JSON (e.g., '{\"DEBUG\":\"1\",\"LOG_LEVEL\":\"info\"}')."
|
||||
default: "{}"
|
||||
windows_env_vars:
|
||||
type: string
|
||||
description: "Environment variables for Windows jobs as JSON (e.g., '{\"DEBUG\":\"1\",\"LOG_LEVEL\":\"info\"}')."
|
||||
default: "{}"
|
||||
|
||||
jobs:
|
||||
construct-matrix:
|
||||
name: Construct unit test matrix
|
||||
@@ -145,7 +154,24 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- id: generate-matrix
|
||||
run: echo "unit-test-matrix=$(curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/generate_matrix.sh | bash)" >> "$GITHUB_OUTPUT"
|
||||
run: |
|
||||
# Validate and use JSON environment variables directly
|
||||
linux_env_vars_json='${{ inputs.linux_env_vars }}'
|
||||
windows_env_vars_json='${{ inputs.windows_env_vars }}'
|
||||
|
||||
# Validate JSON format
|
||||
if ! echo "$linux_env_vars_json" | jq empty 2>/dev/null; then
|
||||
echo "Error: linux_env_vars is not valid JSON"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! echo "$windows_env_vars_json" | jq empty 2>/dev/null; then
|
||||
echo "Error: windows_env_vars is not valid JSON"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Generate matrix
|
||||
echo "unit-test-matrix=$(curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/generate_matrix.sh | MATRIX_LINUX_ENV_VARS_JSON="${linux_env_vars_json}" MATRIX_WINDOWS_ENV_VARS_JSON="${windows_env_vars_json}" bash)" >> "$GITHUB_OUTPUT"
|
||||
env:
|
||||
MATRIX_LINUX_SETUP_COMMAND: "swift --version"
|
||||
MATRIX_LINUX_COMMAND: "swift test"
|
||||
|
||||
+30
-12
@@ -12,6 +12,7 @@
|
||||
## SPDX-License-Identifier: Apache-2.0
|
||||
##
|
||||
##===----------------------------------------------------------------------===##
|
||||
set -x
|
||||
|
||||
# Parameters
|
||||
linux_command="$MATRIX_LINUX_COMMAND" # required if any Linux pipeline is enabled
|
||||
@@ -65,6 +66,10 @@ windows_nightly_next_container_image="swiftlang/swift:nightly-6.2-windowsserverc
|
||||
windows_nightly_main_runner="windows-2022"
|
||||
windows_nightly_main_container_image="swiftlang/swift:nightly-main-windowsservercore-ltsc2022"
|
||||
|
||||
# Get pre-parsed environment variables JSON
|
||||
linux_env_vars_json="${MATRIX_LINUX_ENV_VARS_JSON:-"{}"}"
|
||||
windows_env_vars_json="${MATRIX_WINDOWS_ENV_VARS_JSON:-"{}"}"
|
||||
|
||||
# Create matrix from inputs
|
||||
matrix='{"config": []}'
|
||||
|
||||
@@ -91,7 +96,8 @@ if [[ "$linux_5_9_enabled" == "true" ]]; then
|
||||
--arg command_arguments "$linux_5_9_command_arguments" \
|
||||
--arg container_image "$linux_5_9_container_image" \
|
||||
--arg runner "$linux_runner" \
|
||||
'.config[.config| length] |= . + { "name": "5.9", "image": $container_image, "swift_version": "5.9", "platform": "Linux", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner}')
|
||||
--argjson env_vars "$linux_env_vars_json" \
|
||||
'.config[.config| length] |= . + { "name": "5.9", "image": $container_image, "swift_version": "5.9", "platform": "Linux", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner, "env": $env_vars}')
|
||||
fi
|
||||
|
||||
if [[ "$linux_5_10_enabled" == "true" ]]; then
|
||||
@@ -101,7 +107,8 @@ if [[ "$linux_5_10_enabled" == "true" ]]; then
|
||||
--arg command_arguments "$linux_5_10_command_arguments" \
|
||||
--arg container_image "$linux_5_10_container_image" \
|
||||
--arg runner "$linux_runner" \
|
||||
'.config[.config| length] |= . + { "name": "5.10", "image": $container_image, "swift_version": "5.10", "platform": "Linux", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner}')
|
||||
--argjson env_vars "$linux_env_vars_json" \
|
||||
'.config[.config| length] |= . + { "name": "5.10", "image": $container_image, "swift_version": "5.10", "platform": "Linux", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner, "env": $env_vars}')
|
||||
fi
|
||||
|
||||
if [[ "$linux_6_0_enabled" == "true" ]]; then
|
||||
@@ -111,7 +118,8 @@ if [[ "$linux_6_0_enabled" == "true" ]]; then
|
||||
--arg command_arguments "$linux_6_0_command_arguments" \
|
||||
--arg container_image "$linux_6_0_container_image" \
|
||||
--arg runner "$linux_runner" \
|
||||
'.config[.config| length] |= . + { "name": "6.0", "image": $container_image, "swift_version": "6.0", "platform": "Linux", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner}')
|
||||
--argjson env_vars "$linux_env_vars_json" \
|
||||
'.config[.config| length] |= . + { "name": "6.0", "image": $container_image, "swift_version": "6.0", "platform": "Linux", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner, "env": $env_vars}')
|
||||
fi
|
||||
|
||||
if [[ "$linux_6_1_enabled" == "true" ]]; then
|
||||
@@ -121,7 +129,8 @@ if [[ "$linux_6_1_enabled" == "true" ]]; then
|
||||
--arg command_arguments "$linux_6_1_command_arguments" \
|
||||
--arg container_image "$linux_6_1_container_image" \
|
||||
--arg runner "$linux_runner" \
|
||||
'.config[.config| length] |= . + { "name": "6.1", "image": $container_image, "swift_version": "6.1", "platform": "Linux", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner}')
|
||||
--argjson env_vars "$linux_env_vars_json" \
|
||||
'.config[.config| length] |= . + { "name": "6.1", "image": $container_image, "swift_version": "6.1", "platform": "Linux", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner, "env": $env_vars}')
|
||||
fi
|
||||
|
||||
if [[ "$linux_6_2_enabled" == "true" ]]; then
|
||||
@@ -131,7 +140,8 @@ if [[ "$linux_6_2_enabled" == "true" ]]; then
|
||||
--arg command_arguments "$linux_6_2_command_arguments" \
|
||||
--arg container_image "$linux_6_2_container_image" \
|
||||
--arg runner "$linux_runner" \
|
||||
'.config[.config| length] |= . + { "name": "6.2", "image": $container_image, "swift_version": "6.2", "platform": "Linux", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner}')
|
||||
--argjson env_vars "$linux_env_vars_json" \
|
||||
'.config[.config| length] |= . + { "name": "6.2", "image": $container_image, "swift_version": "6.2", "platform": "Linux", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner, "env": $env_vars}')
|
||||
fi
|
||||
|
||||
if [[ "$linux_nightly_next_enabled" == "true" ]]; then
|
||||
@@ -141,7 +151,8 @@ if [[ "$linux_nightly_next_enabled" == "true" ]]; then
|
||||
--arg command_arguments "$linux_nightly_next_command_arguments" \
|
||||
--arg container_image "$linux_nightly_next_container_image" \
|
||||
--arg runner "$linux_runner" \
|
||||
'.config[.config| length] |= . + { "name": "nightly-next", "image": $container_image, "swift_version": "nightly-next", "platform": "Linux", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner}')
|
||||
--argjson env_vars "$linux_env_vars_json" \
|
||||
'.config[.config| length] |= . + { "name": "nightly-next", "image": $container_image, "swift_version": "nightly-next", "platform": "Linux", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner, "env": $env_vars}')
|
||||
fi
|
||||
|
||||
if [[ "$linux_nightly_main_enabled" == "true" ]]; then
|
||||
@@ -151,12 +162,14 @@ if [[ "$linux_nightly_main_enabled" == "true" ]]; then
|
||||
--arg command_arguments "$linux_nightly_main_command_arguments" \
|
||||
--arg container_image "$linux_nightly_main_container_image" \
|
||||
--arg runner "$linux_runner" \
|
||||
'.config[.config| length] |= . + { "name": "nightly-main", "image": $container_image, "swift_version": "nightly-main", "platform": "Linux", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner}')
|
||||
--argjson env_vars "$linux_env_vars_json" \
|
||||
'.config[.config| length] |= . + { "name": "nightly-main", "image": $container_image, "swift_version": "nightly-main", "platform": "Linux", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner, "env": $env_vars}')
|
||||
fi
|
||||
|
||||
## Windows
|
||||
if [[ \
|
||||
"$windows_6_0_enabled" == "true" || \
|
||||
"$windows_6_1_enabled" == "true" || \
|
||||
"$windows_nightly_next_enabled" == "true" || \
|
||||
"$windows_nightly_main_enabled" == "true" \
|
||||
]]; then
|
||||
@@ -172,7 +185,8 @@ if [[ "$windows_6_0_enabled" == "true" ]]; then
|
||||
--arg command_arguments "$windows_6_0_command_arguments" \
|
||||
--arg container_image "$windows_6_0_container_image" \
|
||||
--arg runner "$windows_6_0_runner" \
|
||||
'.config[.config| length] |= . + { "name": "6.0", "image": $container_image, "swift_version": "6.0", "platform": "Windows", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner }')
|
||||
--argjson env_vars "$windows_env_vars_json" \
|
||||
'.config[.config| length] |= . + { "name": "6.0", "image": $container_image, "swift_version": "6.0", "platform": "Windows", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner, "env": $env_vars }')
|
||||
fi
|
||||
|
||||
if [[ "$windows_6_1_enabled" == "true" ]]; then
|
||||
@@ -182,7 +196,8 @@ if [[ "$windows_6_1_enabled" == "true" ]]; then
|
||||
--arg command_arguments "$windows_6_1_command_arguments" \
|
||||
--arg container_image "$windows_6_1_container_image" \
|
||||
--arg runner "$windows_6_1_runner" \
|
||||
'.config[.config| length] |= . + { "name": "6.1", "image": $container_image, "swift_version": "6.1", "platform": "Windows", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner }')
|
||||
--argjson env_vars "$windows_env_vars_json" \
|
||||
'.config[.config| length] |= . + { "name": "6.1", "image": $container_image, "swift_version": "6.1", "platform": "Windows", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner, "env": $env_vars }')
|
||||
fi
|
||||
|
||||
if [[ "$windows_6_2_enabled" == "true" ]]; then
|
||||
@@ -192,7 +207,8 @@ if [[ "$windows_6_2_enabled" == "true" ]]; then
|
||||
--arg command_arguments "$windows_6_2_command_arguments" \
|
||||
--arg container_image "$windows_6_2_container_image" \
|
||||
--arg runner "$windows_6_2_runner" \
|
||||
'.config[.config| length] |= . + { "name": "6.2", "image": $container_image, "swift_version": "6.2", "platform": "Windows", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner }')
|
||||
--argjson env_vars "$windows_env_vars_json" \
|
||||
'.config[.config| length] |= . + { "name": "6.2", "image": $container_image, "swift_version": "6.2", "platform": "Windows", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner, "env": $env_vars }')
|
||||
fi
|
||||
|
||||
if [[ "$windows_nightly_next_enabled" == "true" ]]; then
|
||||
@@ -202,7 +218,8 @@ if [[ "$windows_nightly_next_enabled" == "true" ]]; then
|
||||
--arg command_arguments "$windows_nightly_next_command_arguments" \
|
||||
--arg container_image "$windows_nightly_next_container_image" \
|
||||
--arg runner "$windows_nightly_next_runner" \
|
||||
'.config[.config| length] |= . + { "name": "nightly-next", "image": $container_image, "swift_version": "nightly-next", "platform": "Windows", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner }')
|
||||
--argjson env_vars "$windows_env_vars_json" \
|
||||
'.config[.config| length] |= . + { "name": "nightly-next", "image": $container_image, "swift_version": "nightly-next", "platform": "Windows", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner, "env": $env_vars }')
|
||||
fi
|
||||
|
||||
if [[ "$windows_nightly_main_enabled" == "true" ]]; then
|
||||
@@ -212,7 +229,8 @@ if [[ "$windows_nightly_main_enabled" == "true" ]]; then
|
||||
--arg command_arguments "$windows_nightly_main_command_arguments" \
|
||||
--arg container_image "$windows_nightly_main_container_image" \
|
||||
--arg runner "$windows_nightly_main_runner" \
|
||||
'.config[.config| length] |= . + { "name": "nightly-main", "image": $container_image, "swift_version": "nightly-main", "platform": "Windows", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner }')
|
||||
--argjson env_vars "$windows_env_vars_json" \
|
||||
'.config[.config| length] |= . + { "name": "nightly-main", "image": $container_image, "swift_version": "nightly-main", "platform": "Windows", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner, "env": $env_vars }')
|
||||
fi
|
||||
|
||||
echo "$matrix" | jq -c
|
||||
Reference in new issue
Block a user