Skip to content

Commit

Permalink
Dynamically generate matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
genya0407 committed Jan 13, 2024
1 parent 70aa3ae commit 99edf9c
Showing 1 changed file with 41 additions and 30 deletions.
71 changes: 41 additions & 30 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,52 @@ on:
workflow_dispatch:

jobs:
test:
generate-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generate-matrix.outputs.value }}
steps:
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'
- id: generate-matrix
run: |
cat <<EOS | ruby >> $GITHUB_OUTPUT
require 'json'
# In order to effectively specify Rails and Ruby versions simultaneously,
# we test only the oldest and latest Ruby versions for each Rails version.
rubies_by_gemfile = {
'gemfiles/rails_5.gemfile' => ['2.3', '2.6'],
'gemfiles/rails_6.0.gemfile' => ['2.5', '2.7'],
'gemfiles/rails_6.1.gemfile' => ['2.5', '3.2'],
'gemfiles/rails_7.0.gemfile' => ['2.7', '3.2'],
}
adapters = ['trilogy', 'mysql2']
matrix = JSON.generate(
adapters.flat_map do |adapter|
rubies_by_gemfile.flat_map do |gemfile, rubies|
rubies.map do |ruby|
{ ruby: ruby, gemfile: gemfile, adapter: adapter }
end
end
end
)
puts "value=#{matrix}"
EOS
test:
needs: generate-matrix
runs-on: ubuntu-latest

strategy:
max-parallel: 4
fail-fast: true
matrix:
# In order to effectively specify Rails and Ruby versions simultaneously,
# we specify every tuple of versions in `include` section
# except for the tuples with a particular Rails version.
#
# The objective of the exception is to satisfy the
# constraint that a matrix cannot be empty.
#
# We test only the oldest and latest Ruby versions for each Rails version.
gemfile: [gemfiles/rails_5.gemfile]
ruby: ['2.3', '2.6']
adapter: ['trilogy', 'mysql2']
include:
- gemfile: gemfiles/rails_6.0.gemfile
ruby: '2.5'
- gemfile: gemfiles/rails_6.0.gemfile
ruby: '2.7'
- gemfile: gemfiles/rails_6.1.gemfile
ruby: '2.5'
- gemfile: gemfiles/rails_6.1.gemfile
ruby: '3.2'
- gemfile: gemfiles/rails_7.0.gemfile
ruby: '2.7'
- gemfile: gemfiles/rails_7.0.gemfile
ruby: '3.2'

spec: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
env:
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
BUNDLE_GEMFILE: ${{ matrix.spec.gemfile }}
services:
mysql:
image: iwata/centos6-mysql56-q4m-hs
Expand All @@ -66,10 +77,10 @@ jobs:
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
ruby-version: ${{ matrix.ruby }}
ruby-version: ${{ matrix.spec.ruby }}
- name: Install dependencies
run: bundle install
- name: Run tests
env:
SHINQ_TEST_ADAPTER: ${{ matrix.adapter }}
SHINQ_TEST_ADAPTER: ${{ matrix.spec.adapter }}
run: bundle exec rspec

0 comments on commit 99edf9c

Please sign in to comment.