-
Notifications
You must be signed in to change notification settings - Fork 651
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce and adopt a new method for defining test matrices, `swift_test_matrix.yml`.⚠️ Any external adopters of the unit tests, Cxx interop and benchmarks workflows are automatically opted in to use the new infrastructure. Motivation: * The current matrix workflow has the limitation that it only supports pre-defined sets of variables which are explored in the test matrix. At the moment this is a pre-defined set of Swift versions on Linux and Windows. * Adding more means hard-coding them at multiple levels of the workflow hierarchy. * Currently skipped Windows matrix jobs show up as successes in the GitHub UI leading to a misleading impression of good coverage. Modifications: Introduce and adopt a new method for defining test matrices, `swift_test_matrix.yml`. The new method is based around the approach of defining the test matrix via a JSON object which may be supplied via an input string from another workflow or from a file on-disk in a repository. Taking this approach means that we have the ability to add new targets to the matrix simply by adding new elements to the JSON array, increasing flexibility and the scope for future growth. The unit tests, Cxx interop and benchmarks workflows are all modified to use the new approach, this opts-in all downstream adopters. This should be transparent to all downstream adopters. In order to unify the Linux and Windows jobs I removed the use of the `container:` GitHub Actions affordance in the Linux jobs which transparently means all steps are executed within the nested container. Instead we must manually call in to the docker container which complicates scripting a little. I tested to see if doing this slowed down the jobs (perhaps GitHub was caching the docker images more intelligently) but it does not. Result: * More flexible test matrix definitions * No more false-passes for disabled Windows targets
- Loading branch information
Showing
6 changed files
with
355 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
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 will cancel 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: | ||
swift-matrix: ${{ steps.load-matrix.outputs.swift-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: load-matrix | ||
run: | | ||
if [ -n '${{ inputs.matrix_string }}' ]; then | ||
printf "swift-matrix=%s" "$(echo '${{ inputs.matrix_string }}' | jq -c '.')" >> "$GITHUB_OUTPUT" | ||
else | ||
printf "swift-matrix=%s" "$(jq -c '.' ${{ inputs.matrix_path }})" >> "$GITHUB_OUTPUT" | ||
fi | ||
execute-matrix: | ||
name: ${{ matrix.swift.platform }} (${{ matrix.swift.name }}) | ||
needs: generate-matrix | ||
runs-on: ${{ matrix.swift.runner }} | ||
strategy: | ||
fail-fast: false | ||
matrix: ${{ fromJson(needs.generate-matrix.outputs.swift-matrix) }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
submodules: true | ||
- name: Pull Docker image | ||
run: docker pull ${{ matrix.swift.image }} | ||
- name: Run matrix job | ||
if: ${{ matrix.swift.platform != 'Windows' }} | ||
run: | | ||
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 SWIFT_VERSION="${{ matrix.swift.swift_version }}" \ | ||
-e setup_command_expression="$setup_command_expression" \ | ||
-e workspace="$workspace" \ | ||
${{ matrix.swift.image }} \ | ||
bash -c "swift --version && git config --global --add safe.directory \"$workspace\" && $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 = "" | ||
} | ||
$workspace = "C:\" + (Split-Path ${{ github.workspace }} -Leaf) | ||
docker run -v ${{ github.workspace }}:$($workspace) ` | ||
-w $($workspace) ` | ||
-e SWIFT_VERSION="${{ matrix.swift.swift_version }}" ` | ||
-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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.