Skip to content

Commit

Permalink
no container
Browse files Browse the repository at this point in the history
  • Loading branch information
rnro committed Dec 2, 2024
1 parent d6e8a7f commit 66008bb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 57 deletions.
77 changes: 29 additions & 48 deletions .github/workflows/swift_test_matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ jobs:
name: Prepare matrices
runs-on: ubuntu-latest
outputs:
linux-matrix: ${{ steps.load-matrix.outputs.linux-matrix }}
windows-matrix: ${{ steps.load-matrix.outputs.windows-matrix }}
swift-matrix: ${{ steps.load-matrix.outputs.swift-matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -46,75 +45,57 @@ jobs:
- 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
jq -c '.' ${{ inputs.matrix_path }} >| __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
echo '${{ inputs.matrix_string }}' | jq -c '.' >| __coverage_matrix.json
- id: load-matrix
run: |
{
echo 'linux-matrix<<EOF'
echo "$(cat __linux_coverage_matrix.json)"
echo 'swift-matrix<<EOF'
echo "$(cat __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 }})
execute-matrix:
name: ${{ matrix.swift.platform }} (${{ matrix.swift.name }})
needs: generate-matrix
runs-on: ${{ matrix.linux.runner }}
runs-on: ${{ matrix.swift.runner }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.generate-matrix.outputs.linux-matrix) }}
container:
image: ${{ matrix.linux.image }}
matrix: ${{ fromJson(needs.generate-matrix.outputs.swift-matrix) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
submodules: true
- name: Mark the workspace as safe
if: ${{ matrix.swift.platform != 'Windows' }}
# 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 }}
env:
SWIFT_VERSION: ${{ matrix.linux.swift_version }}

windows:
name: Windows (${{ matrix.windows.name }})
needs: generate-matrix
if: ${{ needs.generate-matrix.outputs.windows-matrix != '{"windows":[]}' }}
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
run: docker pull ${{ matrix.swift.image }}
- name: Run matrix job
if: ${{ matrix.swift.platform != 'Windows' }}
run: |
if (-not [string]::IsNullOrEmpty("${{ matrix.windows.setup_command }}")) {
$setup_command_expression = "${{ matrix.windows.setup_command }};"
if [[ -n "${{ matrix.swift.setup_command }}" ]]; then
setup_command_expression="${{ matrix.swift.setup_command }} &&"
else
setup_command_expression=""
fi
workspace="/$(basename ${{ github.workspace }})"
docker run -v ${{ github.workspace }}:"$workspace" -w "$workspace" -e setup_command_expression="$setup_command_expression" ${{ matrix.swift.image }} bash -c "swift --version && $setup_command_expression ${{ matrix.swift.command }} ${{ matrix.swift.command_arguments }}"
- name: Run matrix job (Windows)
if: ${{ matrix.swift.platform == 'Windows' }}
run: |
if (-not [string]::IsNullOrEmpty("${{ matrix.swift.setup_command }}")) {
$setup_command_expression = "${{ matrix.swift.setup_command }} &"
} else {
$setup_command_expression = ""
}
docker run -v ${{ github.workspace }}:C:\source ${{ matrix.windows.image }} cmd /s /c "swift --version & cd C:\source\ & powershell Invoke-Expression ""$($setup_command_expression) ${{ matrix.windows.command }} ${{ matrix.windows.command_arguments }}"""
$workspace = "C:\" + (Split-Path ${{ github.workspace }} -Leaf)
docker run -v ${{ github.workspace }}:$($workspace) -w $($workspace) -e setup_command_expression=%setup_command_expression% ${{ matrix.swift.image }} cmd /s /c "swift --version & powershell Invoke-Expression ""$($setup_command_expression) ${{ matrix.swift.command }} ${{ matrix.swift.command_arguments }}"""
env:
SWIFT_VERSION: ${{ matrix.swift.swift_version }}
18 changes: 9 additions & 9 deletions scripts/generate_matrix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ windows_nightly_main_runner="windows-2019"
windows_nightly_main_container_image="swiftlang/swift:nightly-main-windowsservercore-1809"

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

## Linux
if [[ "$linux_5_9_enabled" == "true" || "$linux_5_10_enabled" == "true" || "$linux_6_0_enabled" == "true" || \
Expand All @@ -70,7 +70,7 @@ 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" \
'.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}')
'.swift[.swift| 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}')
fi

if [[ "$linux_5_10_enabled" == "true" ]]; then
Expand All @@ -80,7 +80,7 @@ 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" \
'.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}')
'.swift[.swift| 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}')
fi

if [[ "$linux_6_0_enabled" == "true" ]]; then
Expand All @@ -90,7 +90,7 @@ 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" \
'.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}')
'.swift[.swift| 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}')
fi

if [[ "$linux_nightly_6_0_enabled" == "true" ]]; then
Expand All @@ -100,7 +100,7 @@ if [[ "$linux_nightly_6_0_enabled" == "true" ]]; then
--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}')
'.swift[.swift| length] |= . + { "name": "nightly-6.0", "image": $container_image, "swift_version": "nightly-6.0", "platform": "Linux", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner}')
fi

if [[ "$linux_nightly_main_enabled" == "true" ]]; then
Expand All @@ -110,7 +110,7 @@ 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" \
'.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}')
'.swift[.swift| 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}')
fi

## Windows
Expand All @@ -127,7 +127,7 @@ 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" \
'.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 }')
'.swift[.swift| 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 }')
fi

if [[ "$windows_nightly_6_0_enabled" == "true" ]]; then
Expand All @@ -137,7 +137,7 @@ if [[ "$windows_nightly_6_0_enabled" == "true" ]]; then
--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 }')
'.swift[.swift| length] |= . + { "name": "nightly-6.0", "image": $container_image, "swift_version": "nightly-6.0", "platform": "Windows", "command": $command, "command_arguments": $command_arguments, "setup_command": $setup_command, "runner": $runner }')
fi

if [[ "$windows_nightly_main_enabled" == "true" ]]; then
Expand All @@ -147,7 +147,7 @@ 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" \
'.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 }')
'.swift[.swift| 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 }')
fi

echo "$matrix" | jq -c

0 comments on commit 66008bb

Please sign in to comment.