Skip to content

Commit c36a258

Browse files
authored
Merge pull request rails#54703 from byroot/github-actions-improvements
GitHub Actions improvements
2 parents bdaab70 + b93d25e commit c36a258

File tree

4 files changed

+97
-16
lines changed

4 files changed

+97
-16
lines changed

railties/lib/rails/generators/app_base.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -618,11 +618,16 @@ def dockerfile_build_packages
618618
end
619619

620620
def ci_packages
621-
if depends_on_system_test?
622-
dockerfile_build_packages << "google-chrome-stable"
623-
else
624-
dockerfile_build_packages
625-
end
621+
dockerfile_build_packages - [
622+
# GitHub Actions doesn't have build-essential,
623+
# but it's a meta-packages and all its dependencies are already installed.
624+
"build-essential",
625+
"git",
626+
"pkg-config",
627+
"libyaml-dev",
628+
"unzip",
629+
"python-is-python3",
630+
]
626631
end
627632

628633
def css_gemfile_entry

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

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,11 @@ jobs:
102102

103103
<%- end -%>
104104
steps:
105+
<%- unless ci_packages.empty? -%>
105106
- name: Install packages
106107
run: sudo apt-get update && sudo apt-get install --no-install-recommends -y <%= ci_packages.join(" ") %>
107108

109+
<%- end -%>
108110
- name: Checkout code
109111
uses: actions/checkout@v4
110112

@@ -132,12 +134,81 @@ jobs:
132134
<%- end -%>
133135
# RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
134136
# REDIS_URL: redis://localhost:6379/0
135-
<%- if options[:api] || options[:skip_system_test] -%>
136137
run: bin/rails db:test:prepare test
137-
<%- 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
138211
run: bin/rails db:test:prepare test test:system
139-
<%- end -%>
140-
<%- unless options[:api] || options[:skip_system_test] -%>
141212

142213
- name: Keep screenshots from failed system tests
143214
uses: actions/upload-artifact@v4
@@ -146,5 +217,5 @@ jobs:
146217
name: screenshots
147218
path: ${{ github.workspace }}/tmp/screenshots
148219
if-no-files-found: ignore
149-
<%- end -%>
150-
<% end -%>
220+
<%- end -%>
221+
<%- end -%>

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ jobs:
6363

6464
<%- end -%>
6565
steps:
66-
- name: Install packages
67-
run: sudo apt-get update && sudo apt-get install --no-install-recommends -y <%= ci_packages.join(" ") %>
68-
6966
- name: Checkout code
7067
uses: actions/checkout@v4
7168

railties/test/generators/app_generator_test.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,16 @@ def test_both_brakeman_and_rubocop_binstubs_are_skipped_if_required
655655

656656
def test_inclusion_of_ci_files
657657
run_generator
658-
assert_file ".github/workflows/ci.yml"
659-
assert_file ".github/dependabot.yml"
658+
assert_file ".github/workflows/ci.yml" do |yaml|
659+
assert_nothing_raised do
660+
YAML.load(yaml)
661+
end
662+
end
663+
assert_file ".github/dependabot.yml" do |yaml|
664+
assert_nothing_raised do
665+
YAML.load(yaml)
666+
end
667+
end
660668
end
661669

662670
def test_ci_files_are_skipped_if_required

0 commit comments

Comments
 (0)