Skip to content

Commit

Permalink
DEV: Test different Rails versions (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
CvX committed Apr 6, 2023
1 parent 5910af7 commit 2ece801
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 216 deletions.
64 changes: 44 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,29 @@ on:
- main

jobs:
build:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Setup ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
bundler-cache: true

- name: Rubocop
run: bundle exec rubocop

redis:
name: 'Redis (Ruby ${{ matrix.ruby }})'
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
ruby: ['2.7', '3.0', '3.1', '3.2']
build_type: ['redis', 'active_record']
include:
- ruby: '3.2'
build_type: 'lint'

steps:
- uses: actions/checkout@v3
Expand All @@ -26,39 +38,51 @@ jobs:
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}

- name: Setup gems
run: bundle install

- name: Rubocop
if: matrix.build_type == 'lint'
run: bundle exec rubocop
bundler-cache: true

- name: Setup redis
if: matrix.build_type == 'redis'
run: sudo apt-get install redis-server

- name: Redis specs
if: matrix.build_type == 'redis'
run: bin/rspec redis

- name: Setup test app gems
if: matrix.build_type == 'active_record'
run: cd spec/support/dummy_app && bundle install
active_record:
runs-on: ubuntu-latest
name: 'ActiveRecord ~>${{ matrix.rails }} (Ruby ${{ matrix.ruby }})'

strategy:
fail-fast: false
matrix:
ruby: ['2.7', '3.0', '3.1', '3.2']
rails: ['6.1.0']
include:
- ruby: '3.2'
rails: '6.0.0'

steps:
- uses: actions/checkout@v3

- name: Setup ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}

- name: Setup gems
run: bundle install

- name: Setup postgres
if: matrix.build_type == 'active_record'
run: |
make setup_pg
make start_pg
- name: ActiveRecord specs
if: matrix.build_type == 'active_record'
env:
RAILS_VERSION: ${{ matrix.rails }}
run: bin/rspec active_record

publish:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: build
needs: [lint, redis, active_record]
runs-on: ubuntu-latest

steps:
Expand Down
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
AllCops:
Exclude:
- spec/support/dummy_app/**/*
- vendor/**/*

inherit_gem:
rubocop-discourse: default.yml
Expand Down
6 changes: 3 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ test_active_record:
@ACTIVE_RECORD=1 bundle exec rspec --tag type:active_record ${RSPEC_PATH}

setup_dummy_rails_server:
@cd spec/support/dummy_app && bundle install --quiet && yarn install && RAILS_ENV=production $(BUNDLER_BIN) exec rails db:create db:migrate db:seed
@cd spec/support/dummy_app && BUNDLE_GEMFILE=Gemfile bundle install --quiet && yarn install && BUNDLE_GEMFILE=Gemfile RAILS_ENV=production $(BUNDLER_BIN) exec rails db:create db:migrate db:seed

start_dummy_rails_server:
@cd spec/support/dummy_app && BUNDLE_GEMFILE=Gemfile UNICORN_WORKERS=5 SECRET_KEY_BASE=somekey bundle exec unicorn -c config/unicorn.conf.rb -D -E production
@cd spec/support/dummy_app && BUNDLE_GEMFILE=Gemfile SECRET_KEY_BASE=somekey bundle exec unicorn -c config/unicorn.conf.rb -D -E production

stop_dummy_rails_server:
@kill -TERM $(shell cat spec/support/dummy_app/tmp/pids/unicorn.pid)

teardown_dummy_rails_server:
@cd spec/support/dummy_app && (! (bundle check > /dev/null 2>&1) || DISABLE_DATABASE_ENVIRONMENT_CHECK=1 RAILS_ENV=production $(BUNDLER_BIN) exec rails db:drop)
@cd spec/support/dummy_app && (! (bundle check > /dev/null 2>&1) || BUNDLE_GEMFILE=Gemfile DISABLE_DATABASE_ENVIRONMENT_CHECK=1 RAILS_ENV=production $(BUNDLER_BIN) exec rails db:drop)
1 change: 0 additions & 1 deletion rails_failover.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "byebug"
spec.add_development_dependency "redis", "~> 4.1"
spec.add_development_dependency "pg", "~> 1.2"
spec.add_development_dependency "activerecord", "~> 6.0"
spec.add_development_dependency "rack"
end
4 changes: 3 additions & 1 deletion spec/integration/active_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
EXPECTED_POSTS_COUNT = "100"

def start_dummy_rails_server
system("make start_dummy_rails_server")
if !system("make start_dummy_rails_server")
raise "Could not start dummy server"
end
end

def stop_dummy_rails_server
Expand Down
23 changes: 12 additions & 11 deletions spec/support/dummy_app/Gemfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# frozen_string_literal: true

source "https://rubygems.org"

gem "rails", "~> #{ENV["RAILS_VERSION"] || "6.1.0"}"

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.1.3', '>= 6.1.3.1'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
gem "sass-rails", ">= 6"
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
gem "webpacker", "~> 4.0"

gem 'unicorn'
gem 'pg', '~> 1.2'
gem 'byebug'
gem 'rails_failover', path: '../../../../rails_failover'
gem 'psych', '~> 3.0'
gem "unicorn"
gem 'pg', '~> 1.3.0'
gem "byebug"
gem "rails_failover", path: "../../.."
gem "psych", "~> 3.0"
179 changes: 0 additions & 179 deletions spec/support/dummy_app/Gemfile.lock

This file was deleted.

2 changes: 2 additions & 0 deletions spec/support/dummy_app/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

puts "ActiveRecord #{ActiveRecord::VERSION::STRING}"

module DummyApp
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
Expand Down
2 changes: 1 addition & 1 deletion spec/support/dummy_app/config/unicorn.conf.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
worker_processes ENV["UNICORN_WORKERS"].to_i || 5
worker_processes (ENV["UNICORN_WORKERS"] || 5).to_i

path = File.expand_path(File.expand_path(File.dirname(__FILE__)) + "/../")

Expand Down

0 comments on commit 2ece801

Please sign in to comment.