|
| 1 | +name: Matrix |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + name: |
| 7 | + type: string |
| 8 | + description: "The name of the workflow used for the concurrency group." |
| 9 | + required: true |
| 10 | + matrix_path: |
| 11 | + type: string |
| 12 | + description: "The path of the test matrix definition." |
| 13 | + default: "" |
| 14 | + matrix_string: |
| 15 | + type: string |
| 16 | + description: "The test matrix definition." |
| 17 | + default: "" |
| 18 | + |
| 19 | +# We will cancel previously triggered workflow runs |
| 20 | +concurrency: |
| 21 | + group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.name }} |
| 22 | + cancel-in-progress: true |
| 23 | + |
| 24 | +jobs: |
| 25 | + generate-matrix: |
| 26 | + name: Prepare matrices |
| 27 | + runs-on: ubuntu-latest |
| 28 | + outputs: |
| 29 | + linux-matrix: ${{ steps.load-matrix.outputs.linux-matrix }} |
| 30 | + windows-matrix: ${{ steps.load-matrix.outputs.windows-matrix }} |
| 31 | + steps: |
| 32 | + - name: Checkout repository |
| 33 | + uses: actions/checkout@v4 |
| 34 | + with: |
| 35 | + persist-credentials: false |
| 36 | + - name: Mark the workspace as safe |
| 37 | + # https://github.com/actions/checkout/issues/766 |
| 38 | + run: git config --global --add safe.directory ${GITHUB_WORKSPACE} |
| 39 | + - id: file_check |
| 40 | + run: | |
| 41 | + if [ ! -z '${{ inputs.matrix_string }}' ]; then |
| 42 | + echo "matrix_string_populated=true" >> $GITHUB_ENV |
| 43 | + else |
| 44 | + echo "matrix_string_populated=false" >> $GITHUB_ENV |
| 45 | + fi |
| 46 | + - id: cat-matrix |
| 47 | + if: ${{ env.matrix_string_populated == 'false' }} |
| 48 | + run: | |
| 49 | + jq -c '{linux: .linux}' ${{ inputs.matrix_path }} >| __linux_coverage_matrix.json |
| 50 | + jq -c '{windows: .windows}' ${{ inputs.matrix_path }} >| __windows_coverage_matrix.json |
| 51 | + - id: write-matrix |
| 52 | + if: ${{ env.matrix_string_populated == 'true' }} |
| 53 | + run: | |
| 54 | + echo '${{ inputs.matrix_string }}' | jq -c '{linux: .linux}' >| __linux_coverage_matrix.json |
| 55 | + echo '${{ inputs.matrix_string }}' | jq -c '{windows: .windows}' >| __windows_coverage_matrix.json |
| 56 | + - id: load-matrix |
| 57 | + run: | |
| 58 | + { |
| 59 | + echo 'linux-matrix<<EOF' |
| 60 | + echo "$(cat __linux_coverage_matrix.json)" |
| 61 | + echo EOF |
| 62 | + } >> "$GITHUB_OUTPUT" |
| 63 | +
|
| 64 | + { |
| 65 | + echo 'windows-matrix<<EOF' |
| 66 | + echo "$(cat __windows_coverage_matrix.json)" |
| 67 | + echo EOF |
| 68 | + } >> "$GITHUB_OUTPUT" |
| 69 | +
|
| 70 | + linux: |
| 71 | + name: Linux (${{ matrix.linux.name }}) |
| 72 | + needs: generate-matrix |
| 73 | + runs-on: ${{ matrix.linux.runner }} |
| 74 | + strategy: |
| 75 | + fail-fast: false |
| 76 | + matrix: ${{ fromJson(needs.generate-matrix.outputs.linux-matrix) }} |
| 77 | + container: |
| 78 | + image: ${{ matrix.linux.image }} |
| 79 | + steps: |
| 80 | + - name: Checkout repository |
| 81 | + uses: actions/checkout@v4 |
| 82 | + with: |
| 83 | + persist-credentials: false |
| 84 | + - name: Mark the workspace as safe |
| 85 | + # https://github.com/actions/checkout/issues/766 |
| 86 | + run: git config --global --add safe.directory ${GITHUB_WORKSPACE} |
| 87 | + - name: Pre-build |
| 88 | + if: ${{ matrix.linux.setup_command }} |
| 89 | + run: | |
| 90 | + ${{ matrix.linux.setup_command }} |
| 91 | + - name: Run matrix job |
| 92 | + run: | |
| 93 | + ${{ matrix.linux.command }} ${{ matrix.linux.command_arguments }} |
| 94 | +
|
| 95 | + windows: |
| 96 | + name: Windows (${{ matrix.windows.name }}) |
| 97 | + needs: generate-matrix |
| 98 | + runs-on: ${{ matrix.windows.runner }} |
| 99 | + strategy: |
| 100 | + fail-fast: false |
| 101 | + matrix: ${{ fromJson(needs.generate-matrix.outputs.windows-matrix) }} |
| 102 | + steps: |
| 103 | + - name: Pull Docker image |
| 104 | + run: docker pull ${{ matrix.windows.image }} |
| 105 | + - name: Checkout repository |
| 106 | + uses: actions/checkout@v4 |
| 107 | + with: |
| 108 | + persist-credentials: false |
| 109 | + submodules: true |
| 110 | + - name: Run matrix job |
| 111 | + run: | |
| 112 | + if (-not [string]::IsNullOrEmpty("${{ matrix.windows.setup_command }}")) { |
| 113 | + $setup_command_expression = "${{ matrix.windows.setup_command }};" |
| 114 | + } else { |
| 115 | + $setup_command_expression = "" |
| 116 | + } |
| 117 | + 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 }}""" |
0 commit comments