Skip to content

Commit

Permalink
refactor(ci): generate unit test workflow matrix dynamically
Browse files Browse the repository at this point in the history
this will allow us to have different matrix expansions for different
use cases, will be used to add iterative expansion on infrequent schedule
or on workflow dispatch with parameters to add statistical power to
flake-hunting attempts
  • Loading branch information
mikehardy committed Apr 26, 2024
1 parent 0edeb9d commit 912a24e
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions .github/workflows/tests_unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,43 @@ concurrency:
cancel-in-progress: true

jobs:
# We want to generate our matrix dynamically
# Initial job generates the matrix as a JSON, and following job will use deserialize and use the result
matrix_prep:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.build-matrix.outputs.result }}
steps:
- id: build-matrix
uses: actions/github-script@v7
with:
# Notes:
# 1) 'os'
# - https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
# - macOS 14 is in beta and runs on Apple Silicon [M1]
# 2) 'include'
# - define 'name' so we don't need to update branch protection rules if the os changes
script: |
return {
"os": ["ubuntu-latest", "macos-14", "windows-latest"],
"include": [
{"os": "ubuntu-latest", "name": "ubuntu"},
{"os": "macos-14", "name": "macos"},
{"os": "windows-latest", "name": "windows"}
]
}
- name: Debug Output
run: echo "${{ steps.build-matrix.outputs.result }}"

# This uses the matrix generated from the matrix-prep stage
# it will run unit tests on whatever OS combinations are desired
unit:
name: JUnit Tests (${{ matrix.name }})
needs: matrix_prep
timeout-minutes: 40
strategy:
fail-fast: false
matrix:
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
# macOS 14 is in beta and runs on Apple Silicon [M1]
os: [ubuntu-latest, macos-14, windows-latest]
# define 'name' so we don't need to update branch protection rules if the os changes
include:
- os: ubuntu-latest
name: ubuntu
- os: macos-14
name: macos
- os: windows-latest
name: windows
matrix: ${{fromJson(needs.matrix_prep.outputs.matrix)}}
runs-on: ${{ matrix.os }}
#env:
# CODACY_TOKEN: ${{ secrets.CODACY_TOKEN }}
Expand Down

0 comments on commit 912a24e

Please sign in to comment.