Skip to content

Commit

Permalink
GHA: Separate matrix input handling (#3018)
Browse files Browse the repository at this point in the history
### Motivation:

The new test matrix workflow is quite verbose in the most common case,
unit tests, outputting two workflow entries for handling and preparing
the matrix inputs.

In addition to this, it appeared that when running in `act` the matrix
preparation step would run multiple times.

### Modifications:

* Prioritize the current most common case, string inputs, and skip the
matrix preparation step in this case reducing the number of workflows
run.
* Separate the path for loading the JSON matrix from a file into its own
workflow.

### Result:

* Less noise in the output
* More reliable and efficient local matrix runs
  • Loading branch information
rnro authored Dec 5, 2024
1 parent 234ea10 commit 74f7674
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/swift_load_test_matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Matrix Load

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: ""

jobs:
load-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: |
printf "swift-matrix=%s" "$(jq -c '.' ${{ inputs.matrix_path }})" >> "$GITHUB_OUTPUT"
execute-matrix:
name: Execute matrix
needs: load-matrix
# Workaround https://github.com/nektos/act/issues/1875
uses: apple/swift-nio/.github/workflows/swift_test_matrix.yml@main
with:
name: ${{ inputs.name }}
matrix_string: '${{ needs.load-matrix.outputs.swift-matrix }}'
30 changes: 2 additions & 28 deletions .github/workflows/swift_test_matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,23 @@ on:
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: ""
required: true

# 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) }}
matrix: ${{ fromJson(inputs.matrix_string) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down

0 comments on commit 74f7674

Please sign in to comment.