Skip to content

Commit c2f29a7

Browse files
ntkmeeregon
authored andcommitted
Generate test matrix dynamically
1 parent d5f787c commit c2f29a7

File tree

2 files changed

+107
-82
lines changed

2 files changed

+107
-82
lines changed

.github/workflows/test.yml

Lines changed: 30 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -13,85 +13,33 @@ permissions:
1313
contents: read
1414

1515
jobs:
16+
test-matrix:
17+
runs-on: ubuntu-latest
18+
19+
outputs:
20+
matrix: ${{ steps.matrix.outputs.matrix }}
21+
22+
steps:
23+
- uses: actions/checkout@v6
24+
25+
- uses: ./
26+
with:
27+
ruby-version: ruby
28+
29+
- id: matrix
30+
run: echo "matrix=$(ruby generate-test-matrix.rb)" | tee -a "$GITHUB_OUTPUT"
31+
32+
- run: echo "$MATRIX" | yq -P
33+
env:
34+
MATRIX: ${{ steps.matrix.outputs.matrix }}
35+
1636
test:
37+
needs: [test-matrix]
38+
1739
strategy:
1840
fail-fast: false
1941
matrix:
20-
os: [ ubuntu-22.04, ubuntu-24.04, ubuntu-22.04-arm, ubuntu-24.04-arm, macos-14, macos-15, macos-15-intel, windows-2022, windows-2025, windows-11-arm ]
21-
ruby: [
22-
'1.9', '2.0', '2.1', '2.2', '2.3', '2.4', '2.5', '2.6', '2.7', '3.0', '3.1', '3.2', '3.3', '3.4', '4.0', ruby-head,
23-
jruby-9.4, jruby, jruby-head,
24-
truffleruby, truffleruby-head,
25-
truffleruby+graalvm, truffleruby+graalvm-head
26-
]
27-
include:
28-
- { os: windows-2022, ruby: mingw }
29-
- { os: windows-2022, ruby: mswin }
30-
- { os: windows-2022, ruby: ucrt }
31-
- { os: windows-2025, ruby: mingw }
32-
- { os: windows-2025, ruby: mswin }
33-
- { os: windows-2025, ruby: ucrt }
34-
- { os: ubuntu-24.04, ruby: asan }
35-
- { os: ubuntu-24.04, ruby: asan-release }
36-
exclude:
37-
# https://github.com/ruby/setup-ruby/issues/496
38-
- { os: ubuntu-22.04, ruby: '2.2' }
39-
- { os: ubuntu-24.04, ruby: '1.9' }
40-
- { os: ubuntu-24.04, ruby: '2.2' }
41-
# These old Rubies fail to compile on macOS arm64
42-
- { os: macos-14, ruby: '1.9' }
43-
- { os: macos-14, ruby: '2.0' }
44-
- { os: macos-14, ruby: '2.1' }
45-
- { os: macos-14, ruby: '2.2' }
46-
- { os: macos-14, ruby: '2.3' }
47-
- { os: macos-14, ruby: '2.4' }
48-
- { os: macos-14, ruby: '2.5' }
49-
- { os: macos-15, ruby: '1.9' }
50-
- { os: macos-15, ruby: '2.0' }
51-
- { os: macos-15, ruby: '2.1' }
52-
- { os: macos-15, ruby: '2.2' }
53-
- { os: macos-15, ruby: '2.3' }
54-
- { os: macos-15, ruby: '2.4' }
55-
- { os: macos-15, ruby: '2.5' }
56-
# These old Rubies fail to compile or segfault on Linux arm64
57-
- { os: ubuntu-22.04-arm, ruby: '1.9' }
58-
- { os: ubuntu-22.04-arm, ruby: '2.0' }
59-
- { os: ubuntu-22.04-arm, ruby: '2.1' }
60-
- { os: ubuntu-22.04-arm, ruby: '2.2' }
61-
- { os: ubuntu-24.04-arm, ruby: '1.9' }
62-
- { os: ubuntu-24.04-arm, ruby: '2.0' }
63-
- { os: ubuntu-24.04-arm, ruby: '2.1' }
64-
- { os: ubuntu-24.04-arm, ruby: '2.2' }
65-
# RubyInstaller windows-arm64 builds only exist for Ruby 3.4+
66-
- { os: windows-11-arm, ruby: '2.0' }
67-
- { os: windows-11-arm, ruby: '2.1' }
68-
- { os: windows-11-arm, ruby: '2.2' }
69-
- { os: windows-11-arm, ruby: '2.3' }
70-
- { os: windows-11-arm, ruby: '2.4' }
71-
- { os: windows-11-arm, ruby: '2.5' }
72-
- { os: windows-11-arm, ruby: '2.6' }
73-
- { os: windows-11-arm, ruby: '2.7' }
74-
- { os: windows-11-arm, ruby: '3.0' }
75-
- { os: windows-11-arm, ruby: '3.1' }
76-
- { os: windows-11-arm, ruby: '3.2' }
77-
- { os: windows-11-arm, ruby: '3.3' }
78-
# RubyInstaller has no 64-bit builds of 1.9 on Windows
79-
- { os: windows-2022, ruby: '1.9' }
80-
- { os: windows-2025, ruby: '1.9' }
81-
- { os: windows-11-arm, ruby: '1.9' }
82-
# TruffleRuby does not support Windows
83-
- { os: windows-2022, ruby: truffleruby }
84-
- { os: windows-2025, ruby: truffleruby }
85-
- { os: windows-11-arm, ruby: truffleruby }
86-
- { os: windows-2022, ruby: truffleruby-head }
87-
- { os: windows-2025, ruby: truffleruby-head }
88-
- { os: windows-11-arm, ruby: truffleruby-head }
89-
- { os: windows-2022, ruby: truffleruby+graalvm }
90-
- { os: windows-2025, ruby: truffleruby+graalvm }
91-
- { os: windows-11-arm, ruby: truffleruby+graalvm }
92-
- { os: windows-2022, ruby: truffleruby+graalvm-head }
93-
- { os: windows-2025, ruby: truffleruby+graalvm-head }
94-
- { os: windows-11-arm, ruby: truffleruby+graalvm-head }
42+
include: ${{ fromJSON(needs.test-matrix.outputs.matrix) }}
9543

9644
name: ${{ matrix.os }} ${{ matrix.ruby }}
9745
runs-on: ${{ matrix.os }}
@@ -113,7 +61,7 @@ jobs:
11361
run: |
11462
ruby -e "puts 'build compiler: ' + RbConfig::CONFIG.fetch('CC_VERSION_MESSAGE', 'unknown').lines.first"
11563
- name: gcc and ridk version (mingw)
116-
if: startsWith(matrix.os, 'windows')
64+
if: runner.os == 'Windows'
11765
run: |
11866
$abi, $plat = $(ruby -e "STDOUT.write RbConfig::CONFIG['ruby_version'] + ' ' + RUBY_PLATFORM").split(' ')
11967
if ($plat.Contains('mingw')) {
@@ -154,15 +102,15 @@ jobs:
154102
- name: bundle install (bash)
155103
run: bundle install
156104
shell: bash
157-
if: startsWith(matrix.os, 'windows')
105+
if: runner.os == 'Windows'
158106
- name: bundle exec rake --version (bash)
159107
run: bundle exec rake --version
160108
shell: bash
161-
if: startsWith(matrix.os, 'windows')
109+
if: runner.os == 'Windows'
162110
- name: bundle exec rake (bash)
163111
run: bundle exec rake
164112
shell: bash
165-
if: startsWith(matrix.os, 'windows')
113+
if: runner.os == 'Windows'
166114

167115
- name: Test `gem github:` in a Gemfile
168116
run: bundle install
@@ -179,9 +127,9 @@ jobs:
179127
if: "matrix.ruby != 'mingw' && matrix.ruby != 'mswin' && matrix.ruby != 'ucrt'"
180128
- name: which rake
181129
run: which -a rake
182-
if: "!startsWith(matrix.os, 'windows')"
130+
if: runner.os != 'Windows'
183131
- name: where ruby, rake, bundle
184-
if: startsWith(matrix.os, 'windows')
132+
if: runner.os == 'Windows'
185133
run: |
186134
$ErrorActionPreference = 'Continue'
187135
$where = 'ruby', 'rake', 'bundle'
@@ -195,7 +143,7 @@ jobs:
195143
shell: bash
196144
run: echo ~ && bundle install
197145
- name: Windows JRuby
198-
if: startsWith(matrix.os, 'windows') && startsWith(matrix.ruby, 'jruby')
146+
if: runner.os == 'Windows' && startsWith(matrix.ruby, 'jruby')
199147
run: gem install sassc
200148

201149
testDotRubyVersion:

generate-test-matrix.rb

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
require 'json'
2+
3+
# Returns unique semantic versions and symbolic versions
4+
#
5+
# segment_count = 1 returns unique major versions
6+
# segment_count = 2 returns unique minor versions
7+
# segment_count = 3 returns unique patch versions
8+
def unique_versions(versions, segment_count, *symbolic)
9+
versions.filter_map do |version|
10+
next unless Gem::Version.correct?(version)
11+
12+
ruby_version = Gem::Version.new(version)
13+
next if ruby_version.prerelease? && ruby_version.segments[-2] != 'p'
14+
15+
ruby_version.segments[0, segment_count].join('.')
16+
end.uniq + versions.intersection(symbolic)
17+
end
18+
19+
# Runners
20+
runners = %w[
21+
macos-14
22+
macos-15
23+
macos-15-intel
24+
ubuntu-22.04
25+
ubuntu-24.04
26+
ubuntu-22.04-arm
27+
ubuntu-24.04-arm
28+
windows-2022
29+
windows-2025
30+
windows-11-arm
31+
].freeze
32+
33+
macos_runners = runners.select { |runner| runner.start_with?('macos-') }
34+
ubuntu_runners = runners.select { |runner| runner.start_with?('ubuntu-') }
35+
windows_runners, non_windows_runners = runners.partition { |runner| runner.start_with?('windows-') }
36+
37+
macos_arm64_runners, _macos_x64_runners = macos_runners.partition { |runner| !runner.end_with?('-intel')}
38+
ubuntu_arm64_runners, ubuntu_x64_runners = ubuntu_runners.partition { |runner| runner.end_with?('-arm')}
39+
windows_arm64_runners, windows_x64_runners = windows_runners.partition { |runner| runner.end_with?('-arm') }
40+
41+
# Versions
42+
ruby_builder_versions = JSON.load(File.read('ruby-builder-versions.json'))
43+
windows_versions = JSON.load(File.read('windows-versions.json'))
44+
45+
# ruby: each minor release + head
46+
ruby_versions = unique_versions(ruby_builder_versions['ruby'], 2, 'head')
47+
windows_ruby_versions = unique_versions(windows_versions.keys, 2, 'head')
48+
matrix = non_windows_runners.product(ruby_versions) + windows_runners.product(windows_ruby_versions)
49+
50+
# jruby: each major release + head
51+
jruby_versions = unique_versions(ruby_builder_versions['jruby'], 1, 'head').map { |version| "jruby-#{version}" }
52+
matrix += runners.product(jruby_versions)
53+
54+
# truffleruby: latest release + head
55+
truffleruby_versions = %w[truffleruby truffleruby-head truffleruby+graalvm truffleruby+graalvm-head]
56+
matrix += non_windows_runners.product(truffleruby_versions)
57+
58+
# ruby-loco: head
59+
ruby_loco_versions = %w[mingw mswin ucrt]
60+
matrix += windows_x64_runners.product(ruby_loco_versions)
61+
62+
# asan: latest release + head
63+
asan_versions = %w[asan-release asan]
64+
matrix += ubuntu_x64_runners.sort.last(1).product(asan_versions)
65+
66+
# https://github.com/ruby/setup-ruby/pull/596#discussion_r1606047680
67+
matrix -= (ubuntu_runners - %w[ubuntu-22.04]).product(%w[1.9])
68+
# https://github.com/ruby/setup-ruby/issues/496
69+
matrix -= ubuntu_runners.product(%w[2.2])
70+
# These old Rubies fail to compile on macOS arm64
71+
matrix -= macos_arm64_runners.product(%w[1.9 2.0 2.1 2.2 2.3 2.4 2.5])
72+
# These old Rubies fail to compile or segfault on Linux arm64
73+
matrix -= ubuntu_arm64_runners.product(%w[1.9 2.0 2.1 2.2])
74+
# RubyInstaller windows-arm64 builds only exist for Ruby 3.4+
75+
matrix -= windows_arm64_runners.product(%w[2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 3.0 3.1 3.2 3.3])
76+
77+
puts(JSON.generate(matrix.sort.collect { |os, ruby| { os: os, ruby: ruby } }))

0 commit comments

Comments
 (0)