Skip to content

Commit

Permalink
Nest each matrix dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
lloeki committed Jun 27, 2024
1 parent 8cd3fe2 commit 24acff2
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 63 deletions.
39 changes: 0 additions & 39 deletions .github/workflows/test.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,40 +1,36 @@
name: Unit Test Call
name: Appraisal

on:
workflow_call:
inputs:
spec:
required: true
type: string
engine_name:
required: true
type: string
engine_version:
required: true
type: string
appraisal:
required: true
type: string

jobs:
matrix:
runs-on: ubuntu-latest
container:
image: "ruby:3.3"
name: Prepare matrix
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- name: Compute matrix
id: matrix
run: |
matrix="$(ruby matrix.rb engine.name:${{ inputs.engine_name }} engine.version:${{ inputs.engine_version }})"
echo "${matrix}"
echo "${matrix}" | ruby -rjson -0777 -ne 'pp JSON.parse($_)'
echo "matrix=${matrix}" >> $GITHUB_OUTPUT
test:
runs-on: ubuntu-latest
name: Test ${{ matrix.spec.task }} ${{ matrix.spec.appraisal }} (${{ inputs.engine_name }} ${{ inputs.engine_version }})
name: "Test ${{ matrix.appraisal }} (${{ matrix.engine.name }}:${{ matrix.engine.version }} ${{ matrix.spec }})"
needs: matrix
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.matrix.outputs.matrix) }}
matrix:
spec:
- ${{ inputs.spec }}
engine:
- name: $${ inputs.engine_name }}
version: $${ inputs.engine_version }}
appraisal:
- ${{ inputs.appraisal }}
env:
SKIP_SIMPLECOV: 1
DD_INSTRUMENTATION_TELEMETRY_ENABLED: false
Expand All @@ -60,4 +56,3 @@ jobs:
export BUNDLE_GEMFILE
fi
bundle exec rake spec:${{ matrix.spec.task }}
52 changes: 52 additions & 0 deletions .github/workflows/unit-test/engine.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Engine

on:
workflow_call:
inputs:
engine_name:
required: true
type: string
engine_version:
required: true
type: string
spec:
required: true
type: string

jobs:
matrix:
runs-on: ubuntu-latest
container:
image: "ruby:3.3"
name: Prepare matrix
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- name: Compute matrix
id: matrix
run: |
matrix="$(ruby matrix.rb --json appraisals spec:#{{ inputs.spec }} engine.name:${{ inputs.engine_name }} engine.version:${{ inputs.engine_version }})"
echo "${matrix}" | ruby -rjson -0777 -ne 'puts JSON.pretty_generate JSON.parse($_)'
echo "matrix=${matrix}" >> $GITHUB_OUTPUT
test:
runs-on: ubuntu-latest
name: "${{ matrix.appraisal }} (${{ matrix.engine.name }}:${{ matrix.engine.version }} ${{ matrix.spec }})"
needs: matrix
strategy:
fail-fast: false
matrix:
spec:
- ${{ inputs.spec }}
engine:
- name: $${ inputs.engine_name }}
version: $${ inputs.engine_version }}
appraisal: ${{ fromJSON(needs.matrix.outputs.matrix) }}
uses: ./.github/workflows/unit-test/appraisal.yml
with:
spec: ${{ matrix.spec }}
engine_name: ${{ matrix.engine.name }}
engine_version: ${{ matrix.engine.version }}
appraisal: ${{ matrix.appraisal }}

41 changes: 41 additions & 0 deletions .github/workflows/unit-test/spec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Spec

on:
workflow_call:
inputs:
spec:
required: true
type: string

jobs:
matrix:
runs-on: ubuntu-latest
container:
image: "ruby:3.3"
name: Prepare matrix
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- name: Compute matrix
id: matrix
run: |
matrix="$(ruby matrix.rb --json engines spec:${{ inputs.spec }})"
echo "${matrix}" | ruby -rjson -0777 -ne 'puts JSON.pretty_generate JSON.parse($_)'
echo "matrix=${matrix}" >> $GITHUB_OUTPUT
test:
runs-on: ubuntu-latest
name: "${{ matrix.engine.name }}:${{ matrix.engine.version }} (${{ matrix.spec }})"
needs: matrix
strategy:
fail-fast: false
matrix:
spec:
- ${{ inputs.spec }}
engine: ${{ fromJSON(needs.matrix.outputs.matrix) }}
uses: ./.github/workflows/unit-test/engine.yml
with:
spec: ${{ matrix.spec }}
engine_name: ${{ matrix.engine.name }}
engine_version: ${{ matrix.engine.version }}
32 changes: 32 additions & 0 deletions .github/workflows/unit-test/unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Unit Test

on:
push:

jobs:
matrix:
runs-on: ubuntu-latest
container:
image: "ruby:3.3"
name: Prepare matrix
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- name: Compute matrix
id: matrix
run: |
matrix="$(ruby matrix.rb --json specs)"
echo "${matrix}" | ruby -rjson -0777 -ne 'puts JSON.pretty_generate JSON.parse($_)'
echo "matrix=${matrix}" >> $GITHUB_OUTPUT
test:
name: "${{ matrix.spec }}"
needs: matrix
strategy:
fail-fast: false
matrix:
spec: ${{ needs.matrix.outputs.matrix }}
uses: ./.github/workflows/unit-test/spec.yml
with:
spec: ${{ matrix.spec }}

29 changes: 26 additions & 3 deletions matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'json'

map = eval(File.open('Matrixfile', 'r:UTF-8').read)

ruby_to_jruby = {
'2.5' => ['9.2'],
'2.6' => ['9.3'],
Expand Down Expand Up @@ -50,12 +51,18 @@
selected_engine_version = nil
selected_spec_task = nil
selected_spec_appraisal = nil
output = nil
format = nil
ARGV.each do |arg|
case arg
when /^engine.name:(\S+)/ then selected_engine_name = $1
when /^engine.version:(\S+)/ then selected_engine_version = $1
when /^spec.task:(\S+)/ then selected_spec_task = $1
when /^spec.appraisal:(\S+)/ then selected_spec_appraisal = $1
when /^spec:(\S+)/ then selected_spec_task = $1
when /^appraisal:(\S*)/ then selected_spec_appraisal = $1
when 'engines' then output = 'engines'
when 'specs' then output = 'specs'
when 'appraisals' then output = 'appraisals'
when '--json' then format = 'json'
end
end

Expand All @@ -75,4 +82,20 @@
matrix.select! { |e| e[:spec][:appraisal] == selected_spec_appraisal }
end

puts(JSON.dump({ include: matrix }))
out = case output
when 'engines'
matrix.each_with_object([]) { |e, a| a << e[:engine] }.uniq
when 'specs'
matrix.each_with_object([]) { |e, a| a << e[:spec][:task] }.uniq
when 'appraisals'
matrix.each_with_object([]) { |e, a| a << e[:spec][:appraisal] }.uniq
else
{ include: matrix }
end

case format
when 'json'
puts(JSON.dump(out))
else
out.each { |e| puts e }
end

0 comments on commit 24acff2

Please sign in to comment.