Skip to content

Commit b93d25e

Browse files
committed
Use dedicated GitHub Action jobs for tests and system tests
The most efficient way to speedup a CI is to run the various steps in parallel. The difficulty is of course hpw to split the workload in a balanced way. But regular tests and systems tests are a very natural split strategy, first because system tests require some extra setup, and are generally slower, but also because they tend to be more flaky. So in case of a flake you can retry alone without having to retry all your other tests. this improve the UX a lot.
1 parent 04094ff commit b93d25e

File tree

1 file changed

+75
-6
lines changed
  • railties/lib/rails/generators/rails/app/templates/github

1 file changed

+75
-6
lines changed

railties/lib/rails/generators/rails/app/templates/github/ci.yml.tt

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,81 @@ jobs:
134134
<%- end -%>
135135
# RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
136136
# REDIS_URL: redis://localhost:6379/0
137-
<%- if options[:api] || options[:skip_system_test] -%>
138137
run: bin/rails db:test:prepare test
139-
<%- else -%>
138+
<%- unless options[:api] || options[:skip_system_test] -%>
139+
140+
system-test:
141+
runs-on: ubuntu-latest
142+
143+
<%- if options[:database] == "sqlite3" -%>
144+
# services:
145+
# redis:
146+
# image: valkey/valkey:8
147+
# ports:
148+
# - 6379:6379
149+
# options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5
150+
<%- else -%>
151+
services:
152+
<%- if options[:database] == "mysql" || options[:database] == "trilogy" -%>
153+
mysql:
154+
image: mysql
155+
env:
156+
MYSQL_ALLOW_EMPTY_PASSWORD: true
157+
ports:
158+
- 3306:3306
159+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
160+
<%- elsif options[:database] == "postgresql" -%>
161+
postgres:
162+
image: postgres
163+
env:
164+
POSTGRES_USER: postgres
165+
POSTGRES_PASSWORD: postgres
166+
ports:
167+
- 5432:5432
168+
options: --health-cmd="pg_isready" --health-interval=10s --health-timeout=5s --health-retries=3
169+
<%- end -%>
170+
171+
# redis:
172+
# image: valkey/valkey:8
173+
# ports:
174+
# - 6379:6379
175+
# options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5
176+
177+
<%- end -%>
178+
steps:
179+
<%- unless ci_packages.empty? -%>
180+
- name: Install packages
181+
run: sudo apt-get update && sudo apt-get install --no-install-recommends -y <%= ci_packages.join(" ") %>
182+
183+
<%- end -%>
184+
- name: Checkout code
185+
uses: actions/checkout@v4
186+
187+
- name: Set up Ruby
188+
uses: ruby/setup-ruby@v1
189+
with:
190+
ruby-version: .ruby-version
191+
bundler-cache: true
192+
<%- if using_bun? -%>
193+
194+
- uses: oven-sh/setup-bun@v1
195+
with:
196+
bun-version: <%= dockerfile_bun_version %>
197+
<%- end -%>
198+
199+
- name: Run System Tests
200+
env:
201+
RAILS_ENV: test
202+
<%- if options[:database] == "mysql" -%>
203+
DATABASE_URL: mysql2://127.0.0.1:3306
204+
<%- elsif options[:database] == "trilogy" -%>
205+
DATABASE_URL: trilogy://127.0.0.1:3306
206+
<%- elsif options[:database] == "postgresql" -%>
207+
DATABASE_URL: postgres://postgres:postgres@localhost:5432
208+
<%- end -%>
209+
# RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
210+
# REDIS_URL: redis://localhost:6379/0
140211
run: bin/rails db:test:prepare test test:system
141-
<%- end -%>
142-
<%- unless options[:api] || options[:skip_system_test] -%>
143212

144213
- name: Keep screenshots from failed system tests
145214
uses: actions/upload-artifact@v4
@@ -148,5 +217,5 @@ jobs:
148217
name: screenshots
149218
path: ${{ github.workspace }}/tmp/screenshots
150219
if-no-files-found: ignore
151-
<%- end -%>
152-
<% end -%>
220+
<%- end -%>
221+
<%- end -%>

0 commit comments

Comments
 (0)