Skip to content

Commit a38bd38

Browse files
authored
ci: Refactor CI workflow with build matrix (#173)
* feat: Accept argument for `build_multi` task Sample command: ``` rake 'build_multi[7.0,7.1]' ``` * refactor: Fetch rails tags inside the loop * cI: Build build_multi matrix - refactor: Loop versions in bash script * ci: Build YJIT enabled matrix - Remove `doc-build-latest-with-yjit` since it's covered by matrix - switch YJIT using `RUBY_YJIT_ENABLE`
1 parent 9227538 commit a38bd38

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

Diff for: .github/workflows/ci.yml

+25-22
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ on:
99
jobs:
1010
jekyll-build:
1111
runs-on: ubuntu-latest
12-
name: Jekyll Build
12+
name: Jekyll Build (YJIT_ENABLED ${{ matrix.yjit-enabled }})
13+
strategy:
14+
matrix:
15+
yjit-enabled: [0, 1]
16+
env:
17+
RUBY_YJIT_ENABLE: ${{ matrix.yjit-enabled }}
1318
steps:
1419
- uses: actions/checkout@v4
1520
- uses: ruby/setup-ruby@v1
@@ -21,25 +26,12 @@ jobs:
2126

2227
doc-build-latest:
2328
runs-on: ubuntu-latest
24-
name: Rails Doc Build (latest)
25-
steps:
26-
- uses: actions/checkout@v4
27-
with:
28-
submodules: true
29-
- name: fetch Rails tags
30-
run: cd rails && git fetch --depth=1 origin refs/tags/v7*:refs/tags/v7*
31-
- uses: ruby/setup-ruby@v1
32-
with:
33-
ruby-version: 3.3
34-
bundler-cache: true
35-
- name: Doc Build
36-
run: rake build
37-
38-
doc-build-latest-with-yjit:
39-
runs-on: ubuntu-latest
40-
name: Rails Doc Build (latest, with YJIT enabled)
29+
name: Rails Doc Build (latest, YJIT_ENABLED ${{ matrix.yjit-enabled }})
30+
strategy:
31+
matrix:
32+
yjit-enabled: [0, 1]
4133
env:
42-
RUBY_YJIT_ENABLE: true
34+
RUBY_YJIT_ENABLE: ${{ matrix.yjit-enabled }}
4335
steps:
4436
- uses: actions/checkout@v4
4537
with:
@@ -56,15 +48,26 @@ jobs:
5648
doc-build-others:
5749
runs-on: ubuntu-latest
5850
name: Rails Doc Build (older versions)
51+
strategy:
52+
matrix:
53+
include:
54+
- ruby-version: 2.7
55+
build-rails-versions: "5.2,6.0,6.1"
56+
- ruby-version: 3.3
57+
build-rails-versions: "7.0,7.1,7.2"
5958
steps:
6059
- uses: actions/checkout@v4
6160
with:
6261
submodules: true
6362
- name: fetch Rails tags
64-
run: cd rails && git fetch --depth=1 origin refs/tags/v7*:refs/tags/v7* refs/tags/v6*:refs/tags/v6* refs/tags/v5*:refs/tags/v5*
63+
working-directory: rails
64+
run: |
65+
for version in $(echo "${{ matrix.build-rails-versions }}" | tr ',' ' '); do
66+
git fetch --depth=1 origin refs/tags/v${version}*:refs/tags/v${version}*
67+
done
6568
- uses: ruby/setup-ruby@v1
6669
with:
67-
ruby-version: 2.7
70+
ruby-version: ${{ matrix.ruby-version }}
6871
bundler-cache: true
6972
- name: Doc Build
70-
run: rake build_multi
73+
run: rake 'build_multi[${{ matrix.build-rails-versions }}]'

Diff for: Rakefile

+8-4
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ task :switch_default_rails do
2121
end
2222

2323
desc 'Generate and build documentation for older versions of Rails'
24-
task :build_multi do
25-
# WORKAROUND: use `reverse_each` instead of `each` to avoid nokogiri installation error
26-
config['rails_versions'].reverse_each do |version, detail|
24+
task :build_multi, [:versions] do |_t, args|
25+
rails_versions = config['rails_versions'].reverse_each.to_h # Versions from oldest to newest
26+
unless args[:versions].nil?
27+
versions = args[:versions].split(',')
28+
rails_versions.select! { |version, _| versions.include?(version) }
29+
end
30+
rails_versions.each do |version, detail|
2731
if detail['latest']
2832
puts "=== Skip Rails v#{version} because it's latest version ==="
2933
next
@@ -39,7 +43,7 @@ task :build_multi do
3943
generate_rails_rdoc
4044
generate_src(target_version: version)
4145
end
42-
puts
46+
puts "=== Build Jekyll site ==="
4347
sh 'bundle exec jekyll build'
4448
end
4549

0 commit comments

Comments
 (0)