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 1e22aae
Show file tree
Hide file tree
Showing 4 changed files with 390 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/unit_tests.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
119 changes: 119 additions & 0 deletions .github/workflows/swift_test_matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
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: |
if [[ ! -z "${{ matrix.windows.pre_run_command }}" ]]; then
pre_run_command_expression="powershell Invoke-Expression ${{ matrix.windows.pre_run_command }} &"
else
pre_run_command_expression=""
fi
docker run -v ${{ github.workspace }}:C:\source ${{ matrix.windows.image }} cmd /s /c "swift --version & cd C:\source\ & $pre_run_command_expression powershell Invoke-Expression ${{ matrix.windows.command }} ${{ matrix.windows.command_arguments }}"
117 changes: 117 additions & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Unit tests

on:
workflow_call:
inputs:
linux_5_9_enabled:
type: boolean
description: "Boolean to enable the Linux 5.9 Swift version matrix job. Defaults to true."
default: true
linux_5_9_arguments_override:
type: string
description: "The arguments passed to swift test in the Linux 5.9 Swift version matrix job."
default: ""
linux_5_10_enabled:
type: boolean
description: "Boolean to enable the Linux 5.10 Swift version matrix job. Defaults to true."
default: true
linux_5_10_arguments_override:
type: string
description: "The arguments passed to swift test in the Linux 5.10 Swift version matrix job."
default: ""
linux_6_0_enabled:
type: boolean
description: "Boolean to enable the Linux 6.0 Swift version matrix job. Defaults to true."
default: true
linux_6_0_arguments_override:
type: string
description: "The arguments passed to swift test in the Linux 6.0 Swift version matrix job."
default: ""
linux_nightly_6_0_enabled:
type: boolean
description: "Boolean to enable the Linux nightly 6.0 Swift version matrix job. Defaults to true."
default: true
linux_nightly_6_0_arguments_override:
type: string
description: "The arguments passed to swift test in the Linux nightly 6.0 Swift version matrix job."
default: ""
linux_nightly_main_enabled:
type: boolean
description: "Boolean to enable the Linux nightly main Swift version matrix job. Defaults to true."
default: true
linux_nightly_main_arguments_override:
type: string
description: "The arguments passed to swift test in the Linux nightly main Swift version matrix job."
default: ""

windows_6_0_enabled:
type: boolean
description: "Boolean to enable the Windows 6.0 Swift version matrix job. Defaults to true."
default: false
windows_6_0_arguments_override:
type: string
description: "The arguments passed to swift test in the Windows 6.0 Swift version matrix job."
default: ""
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
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."
default: ""
windows_nightly_main_enabled:
type: boolean
description: "Boolean to enable the Windows nightly main Swift version matrix job. Defaults to true."
default: false
windows_nightly_main_arguments_override:
type: string
description: "The arguments passed to swift test in the Windows nightly main Swift version matrix job."
default: ""

jobs:
construct-matrix:
name: Construct unit test matrix
runs-on: ubuntu-latest
outputs:
unit-test-matrix: '${{ steps.generate-matrix.outputs.unit-test-matrix }}'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
- id: generate-matrix
run: |
{
echo 'unit-test-matrix<<EOF'
./scripts/generate_matrix.sh
echo EOF
} >> "$GITHUB_OUTPUT"
env:
MATRIX_LINUX_COMMAND: "swift test"
MATRIX_LINUX_5_9_ENABLED: ${{ inputs.linux_5_9_enabled }}
MATRIX_LINUX_5_9_COMMAND_ARGUMENTS: ${{ inputs.linux_5_9_arguments_override }}
MATRIX_LINUX_5_10_ENABLED: ${{ inputs.linux_5_10_enabled }}
MATRIX_LINUX_5_10_COMMAND_ARGUMENTS: ${{ inputs.linux_5_10_arguments_override }}
MATRIX_LINUX_6_0_ENABLED: ${{ inputs.linux_6_0_enabled }}
MATRIX_LINUX_6_0_COMMAND_ARGUMENTS: ${{ inputs.linux_6_0_arguments_override }}
MATRIX_LINUX_NIGHTLY_6_0_ENABLED: ${{ inputs.linux_nightly_6_0_enabled }}
MATRIX_LINUX_NIGHTLY_6_0_COMMAND_ARGUMENTS: ${{ inputs.linux_nightly_6_0_arguments_override }}
MATRIX_LINUX_NIGHTLY_MAIN_ENABLED: ${{ inputs.linux_nightly_main_enabled }}
MATRIX_LINUX_NIGHTLY_MAIN_COMMAND_ARGUMENTS: ${{ inputs.linux_nightly_main_arguments_override }}
MATRIX_WINDOWS_COMMAND: "swift test"
MATRIX_WINDOWS_6_0_ENABLED: ${{ inputs.windows_6_0_enabled }}
MATRIX_WINDOWS_6_0_COMMAND_ARGUMENTS: ${{ inputs.windows_6_0_arguments_override }}
MATRIX_WINDOWS_NIGHTLY_6_0_ENABLED: ${{ inputs.windows_nightly_6_0_enabled }}
MATRIX_WINDOWS_NIGHTLY_6_0_COMMAND_ARGUMENTS: ${{ inputs.windows_nightly_6_0_arguments_override }}
MATRIX_WINDOWS_NIGHTLY_MAIN_ENABLED: ${{ inputs.windows_nightly_main_enabled }}
MATRIX_WINDOWS_NIGHTLY_MAIN_COMMAND_ARGUMENTS: ${{ inputs.windows_nightly_main_arguments_override }}

unit-tests:
name: Unit tests
needs: construct-matrix
# TODO: use global reference
uses: ./.github/workflows/swift_test_matrix.yml
with:
name: "Unit tests"
matrix_string: '${{ needs.construct-matrix.outputs.unit-test-matrix }}'
Loading

0 comments on commit 1e22aae

Please sign in to comment.