Skip to content

Commit 8708bf1

Browse files
authored
Set up Rails matrix testing (#927)
## Summary - allow selecting Rails version via `RAILS_VERSION` in Gemfile - run workflow with Rails 7.1.5.1, 7.2 and 8.0 on Ruby 3.4.4 - fail CI only on Rails 7.1.5.1 failures - update workflow to update Rails during CI ## Testing - `bundle exec rubocop` - `bundle exec brakeman -q -w2` - `bundle exec bundler-audit --update` - `bin/ci` *(fails: ActiveRecord::DatabaseConnectionError)* ------ https://chatgpt.com/codex/tasks/task_e_688baf84cc4c8321ada70c1b85eccd72
2 parents c1b7307 + eee1b6d commit 8708bf1

File tree

5 files changed

+93
-73
lines changed

5 files changed

+93
-73
lines changed

.github/workflows/rubyonrails.yml

Lines changed: 83 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,109 @@
1-
# This workflow uses actions that are not certified by GitHub. They are
2-
# provided by a third-party and are governed by separate terms of service,
3-
# privacy policy, and support documentation.
4-
#
5-
# This workflow will install a prebuilt Ruby version, install dependencies, and
6-
# run tests and linters.
71
name: "Ruby on Rails CI"
8-
on:
9-
push:
10-
branches: [ "main", "dev" ]
11-
pull_request:
12-
branches: [ "main", "dev" ]
2+
3+
on: { push: { branches: [main, dev] }, pull_request: { branches: [main, dev] } }
4+
135
jobs:
146
rspec:
157
runs-on: ubuntu-latest
168
environment: test
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
include:
13+
- ruby: '3.4.4'
14+
rails: '7.1.5.1'
15+
allowed_failure: false # ✅ required
16+
- ruby: '3.4.4'
17+
rails: '7.2'
18+
allowed_failure: true # ⚠️ allowed to fail
19+
- ruby: '3.4.4'
20+
rails: '8.0'
21+
allowed_failure: true # ⚠️ allowed to fail
22+
23+
env:
24+
RAILS_ENV: test
25+
DATABASE_URL: "postgis://rails:password@localhost:5432/rails_test"
26+
ES_HOST: "http://localhost"
27+
RAILS_VERSION: ${{ matrix.rails }}
28+
1729
services:
1830
postgres:
1931
image: postgis/postgis:latest
20-
ports:
21-
- "5432:5432"
22-
env:
23-
POSTGRES_DB: rails_test
24-
POSTGRES_USER: rails
25-
POSTGRES_PASSWORD: password
32+
ports: ["5432:5432"]
33+
env: { POSTGRES_DB: rails_test, POSTGRES_USER: rails, POSTGRES_PASSWORD: password }
2634
elasticsearch:
2735
image: elasticsearch:7.17.23
28-
ports:
29-
- "9200:9200"
36+
ports: ["9200:9200"]
3037
env:
31-
"node.name": elasticsearch
32-
"cluster.name": better-together-es
33-
"discovery.seed_hosts": elasticsearch
34-
"discovery.type": single-node
35-
"bootstrap.memory_lock": true
36-
"ES_JAVA_OPTS": "-Xms512m -Xmx512m"
37-
env:
38-
RAILS_ENV: test
39-
DATABASE_URL: "postgis://rails:password@localhost:5432/rails_test"
40-
ES_HOST: "http://localhost"
38+
node.name: elasticsearch
39+
cluster.name: better-together-es
40+
discovery.seed_hosts: elasticsearch
41+
discovery.type: single-node
42+
bootstrap.memory_lock: "true"
43+
ES_JAVA_OPTS: "-Xms512m -Xmx512m"
44+
4145
steps:
4246
- name: Checkout code
4347
uses: actions/checkout@v3
44-
# Add or replace dependency steps here
45-
- name: Install Ruby and gems
48+
49+
- name: Install Ruby & gems
4650
uses: ruby/setup-ruby@v1
4751
with:
48-
bundler-cache: true
49-
# Add or replace database setup steps here
50-
- name: Set up database schema
51-
run: rm -f spec/dummy/tmp/pids/server.pid && cd ./spec/dummy && bundle exec rails db:schema:load
52-
# Add or replace test runners here
53-
- name: Run tests
52+
ruby-version: ${{ matrix.ruby }}
53+
54+
# Run the automatic bundle-install only on 7.1.
55+
# For 7.2 / 8.0 it just sets up Ruby *and* restores a cache layer
56+
# that we’ll reuse in the later manual install.
57+
bundler-cache: ${{ matrix.rails == '7.1.5.1' }}
58+
59+
# One cache bucket per Rails version so they don’t clobber each other.
60+
cache-version: rails-${{ matrix.rails }}
61+
62+
# Updating Rails can legitimately blow up on the experimental tracks,
63+
# so we allow that *step* to error out without failing the job.
64+
- name: Update Rails & install gems
65+
if: matrix.rails != '7.1.5.1'
66+
id: update
67+
run: |
68+
# turn off deployment mode
69+
bundle config set deployment false
70+
# conservative upgrade to the target rails version
71+
bundle update rails --conservative
72+
# install missing gems (writes bin/rspec, etc)
73+
bundle install --jobs 4 --retry 3
74+
continue-on-error: ${{ matrix.allowed_failure }}
75+
76+
- name: Prepare DB schema
77+
if: (matrix.rails == '7.1.5.1') || steps.update.outcome == 'success'
78+
run: |
79+
rm -f spec/dummy/tmp/pids/server.pid
80+
bundle exec rake -f spec/dummy/Rakefile db:schema:load
81+
continue-on-error: ${{ matrix.allowed_failure }}
82+
83+
- name: Run RSpec
84+
if: (matrix.rails == '7.1.5.1') || steps.update.outcome == 'success'
5485
env:
5586
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
56-
run: rm -f spec/dummy/tmp/pids/server.pid && bundle exec rspec
87+
run: |
88+
rm -f spec/dummy/tmp/pids/server.pid
89+
bundle exec rspec
90+
continue-on-error: ${{ matrix.allowed_failure }}
5791

92+
# ── style & security jobs (unchanged) ───────────────────────────────────────
5893
rubocop:
5994
runs-on: ubuntu-latest
6095
steps:
61-
- name: Checkout code
62-
uses: actions/checkout@v3
63-
- name: Install Ruby and gems
64-
uses: ruby/setup-ruby@v1
65-
with:
66-
bundler-cache: true
67-
- name: Lint Ruby files with Rubocop
68-
run: bundle exec rubocop --parallel
96+
- uses: actions/checkout@v3
97+
- uses: ruby/setup-ruby@v1
98+
with: { bundler-cache: true }
99+
- run: bundle exec rubocop --parallel
69100

70101
security:
71102
runs-on: ubuntu-latest
72103
steps:
73-
- name: Checkout code
74-
uses: actions/checkout@v3
75-
- name: Install Ruby and gems
76-
uses: ruby/setup-ruby@v1
77-
with:
78-
bundler-cache: true
79-
- name: Generate binstubs
80-
run: bundle binstubs bundler-audit --force
81-
- name: Security audit dependencies
82-
run: bundle exec bundler-audit --update
83-
- name: Security audit application code
84-
run: bundle exec brakeman -q -w2
104+
- uses: actions/checkout@v3
105+
- uses: ruby/setup-ruby@v1
106+
with: { bundler-cache: true }
107+
- run: bundle binstubs bundler-audit --force
108+
- run: bundle exec bundler-audit --update
109+
- run: bundle exec brakeman -q -w2

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ gem 'pundit-resources', '~> 1.1.4', github: 'better-together-org/pundit-resource
2727

2828
# Core Rails gem
2929
gem 'rack-protection'
30-
gem 'rails', '~> 7.1.3'
30+
gem 'rails', ENV.fetch('RAILS_VERSION', '7.1.5.1')
3131

3232
# Redis for ActionCable and background jobs
3333
gem 'redis', '~> 5.4'

Gemfile.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
GIT
22
remote: https://github.com/better-together-org/pundit-resources.git
3-
revision: b6218c695c2b6c7413ab416a318cd540835c5394
3+
revision: 4e50d1f97a1e7c864bc45e2613b763ecf8f079ce
44
specs:
5-
pundit-resources (1.1.5)
5+
pundit-resources (1.1.6)
66
activesupport
77
jsonapi-resources
88
pundit
9-
rails (>= 4.2.1, < 7.2)
9+
rails (>= 4.2.1, < 8.1)
1010

1111
GIT
1212
remote: https://github.com/better-together-org/storext.git
13-
revision: 1d7c3707b3e412fece0022c16cc6f51564969d2c
13+
revision: ebc92461e95d07c34f5d8eac4eb7ad13cfd92afa
1414
specs:
15-
storext (3.3.0)
16-
activerecord (>= 4.0, < 8)
15+
storext (3.3.1)
16+
activerecord (>= 4.0, < 8.1)
1717
virtus
1818

1919
PATH
@@ -53,7 +53,7 @@ PATH
5353
rack-attack
5454
rack-cors (>= 1.1.1, < 3.1.0)
5555
rack-mini-profiler
56-
rails (>= 5.2.2, < 7.2.0)
56+
rails (>= 7.1, < 8.1)
5757
reform-rails (~> 0.2.0)
5858
rswag (>= 2.3.1, < 2.17.0)
5959
ruby-openai
@@ -845,7 +845,7 @@ DEPENDENCIES
845845
pundit-resources (~> 1.1.4)!
846846
rack-mini-profiler
847847
rack-protection
848-
rails (~> 7.1.3)
848+
rails (= 7.1.5.1)
849849
rb-readline
850850
rbtrace
851851
redis (~> 5.4)

app/controllers/better_together/messages_controller.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ def notify_participants(message)
3434
# Get all participants except the sender
3535
recipients = message.conversation.participants.where.not(id: message.sender_id)
3636

37-
# Log recipients for debugging
38-
puts "Recipients for message notification: #{recipients.map(&:id)}"
39-
40-
# broadcast_to_recipients(message, recipients)
41-
4237
# Pass the array of recipients to the notification
4338
BetterTogether::NewMessageNotifier.with(record: message).deliver_later(recipients)
4439
end

better_together.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Gem::Specification.new do |spec|
6161
spec.add_dependency 'rack-attack'
6262
spec.add_dependency 'rack-cors', '>= 1.1.1', '< 3.1.0'
6363
spec.add_dependency 'rack-mini-profiler'
64-
spec.add_dependency 'rails', '>= 5.2.2', '< 7.2.0'
64+
spec.add_dependency 'rails', '>= 7.1', '< 8.1'
6565
spec.add_dependency 'reform-rails', '~> 0.2.0'
6666
spec.add_dependency 'rswag', '>= 2.3.1', '< 2.17.0'
6767
spec.add_dependency 'ruby-openai'

0 commit comments

Comments
 (0)