From 2ece801f2e0a9fca998265043a53340c5d11b5eb Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Thu, 6 Apr 2023 21:26:16 +0200 Subject: [PATCH] DEV: Test different Rails versions (#58) --- .github/workflows/ci.yml | 64 +++++-- .rubocop.yml | 1 + makefile | 6 +- rails_failover.gemspec | 1 - spec/integration/active_record_spec.rb | 4 +- spec/support/dummy_app/Gemfile | 23 +-- spec/support/dummy_app/Gemfile.lock | 179 ------------------ spec/support/dummy_app/config/application.rb | 2 + spec/support/dummy_app/config/unicorn.conf.rb | 2 +- 9 files changed, 66 insertions(+), 216 deletions(-) delete mode 100644 spec/support/dummy_app/Gemfile.lock diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8052a76..b5b8320 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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: diff --git a/.rubocop.yml b/.rubocop.yml index 50c116e..fcfbc23 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,7 @@ AllCops: Exclude: - spec/support/dummy_app/**/* + - vendor/**/* inherit_gem: rubocop-discourse: default.yml diff --git a/makefile b/makefile index 5bb87c6..61fab96 100644 --- a/makefile +++ b/makefile @@ -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) diff --git a/rails_failover.gemspec b/rails_failover.gemspec index f42e96a..db0758b 100644 --- a/rails_failover.gemspec +++ b/rails_failover.gemspec @@ -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 diff --git a/spec/integration/active_record_spec.rb b/spec/integration/active_record_spec.rb index dbd3621..972f0b6 100644 --- a/spec/integration/active_record_spec.rb +++ b/spec/integration/active_record_spec.rb @@ -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 diff --git a/spec/support/dummy_app/Gemfile b/spec/support/dummy_app/Gemfile index 0a17ae9..f58dd98 100644 --- a/spec/support/dummy_app/Gemfile +++ b/spec/support/dummy_app/Gemfile @@ -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" diff --git a/spec/support/dummy_app/Gemfile.lock b/spec/support/dummy_app/Gemfile.lock deleted file mode 100644 index 25595a6..0000000 --- a/spec/support/dummy_app/Gemfile.lock +++ /dev/null @@ -1,179 +0,0 @@ -PATH - remote: ../../.. - specs: - rails_failover (0.8.1) - activerecord (> 6.0, < 7.1) - concurrent-ruby - railties (> 6.0, < 7.1) - -GEM - remote: https://rubygems.org/ - specs: - actioncable (6.1.5) - actionpack (= 6.1.5) - activesupport (= 6.1.5) - nio4r (~> 2.0) - websocket-driver (>= 0.6.1) - actionmailbox (6.1.5) - actionpack (= 6.1.5) - activejob (= 6.1.5) - activerecord (= 6.1.5) - activestorage (= 6.1.5) - activesupport (= 6.1.5) - mail (>= 2.7.1) - actionmailer (6.1.5) - actionpack (= 6.1.5) - actionview (= 6.1.5) - activejob (= 6.1.5) - activesupport (= 6.1.5) - mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (6.1.5) - actionview (= 6.1.5) - activesupport (= 6.1.5) - rack (~> 2.0, >= 2.0.9) - rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.1.5) - actionpack (= 6.1.5) - activerecord (= 6.1.5) - activestorage (= 6.1.5) - activesupport (= 6.1.5) - nokogiri (>= 1.8.5) - actionview (6.1.5) - activesupport (= 6.1.5) - builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.1.5) - activesupport (= 6.1.5) - globalid (>= 0.3.6) - activemodel (6.1.5) - activesupport (= 6.1.5) - activerecord (6.1.5) - activemodel (= 6.1.5) - activesupport (= 6.1.5) - activestorage (6.1.5) - actionpack (= 6.1.5) - activejob (= 6.1.5) - activerecord (= 6.1.5) - activesupport (= 6.1.5) - marcel (~> 1.0) - mini_mime (>= 1.1.0) - activesupport (6.1.5) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 1.6, < 2) - minitest (>= 5.1) - tzinfo (~> 2.0) - zeitwerk (~> 2.3) - builder (3.2.4) - byebug (11.1.3) - concurrent-ruby (1.1.9) - crass (1.0.6) - erubi (1.10.0) - ffi (1.15.5) - globalid (1.0.0) - activesupport (>= 5.0) - i18n (1.10.0) - concurrent-ruby (~> 1.0) - kgio (2.11.4) - loofah (2.14.0) - crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.7.1) - mini_mime (>= 0.1.1) - marcel (1.0.2) - method_source (1.0.0) - mini_mime (1.1.2) - mini_portile2 (2.8.0) - minitest (5.15.0) - nio4r (2.5.8) - nokogiri (1.13.3) - mini_portile2 (~> 2.8.0) - racc (~> 1.4) - pg (1.3.4) - psych (3.3.2) - racc (1.6.0) - rack (2.2.3) - rack-proxy (0.7.2) - rack - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails (6.1.5) - actioncable (= 6.1.5) - actionmailbox (= 6.1.5) - actionmailer (= 6.1.5) - actionpack (= 6.1.5) - actiontext (= 6.1.5) - actionview (= 6.1.5) - activejob (= 6.1.5) - activemodel (= 6.1.5) - activerecord (= 6.1.5) - activestorage (= 6.1.5) - activesupport (= 6.1.5) - bundler (>= 1.15.0) - railties (= 6.1.5) - sprockets-rails (>= 2.0.0) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) - nokogiri (>= 1.6) - rails-html-sanitizer (1.4.2) - loofah (~> 2.3) - railties (6.1.5) - actionpack (= 6.1.5) - activesupport (= 6.1.5) - method_source - rake (>= 12.2) - thor (~> 1.0) - raindrops (0.20.0) - rake (13.0.6) - sass-rails (6.0.0) - sassc-rails (~> 2.1, >= 2.1.1) - sassc (2.4.0) - ffi (~> 1.9) - sassc-rails (2.1.2) - railties (>= 4.0.0) - sassc (>= 2.0) - sprockets (> 3.0) - sprockets-rails - tilt - sprockets (4.0.3) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.4.2) - actionpack (>= 5.2) - activesupport (>= 5.2) - sprockets (>= 3.0.0) - thor (1.2.1) - tilt (2.0.10) - tzinfo (2.0.4) - concurrent-ruby (~> 1.0) - unicorn (6.1.0) - kgio (~> 2.6) - raindrops (~> 0.7) - webpacker (4.3.0) - activesupport (>= 4.2) - rack-proxy (>= 0.6.1) - railties (>= 4.2) - websocket-driver (0.7.5) - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.5) - zeitwerk (2.5.4) - -PLATFORMS - ruby - -DEPENDENCIES - byebug - pg (~> 1.2) - psych (~> 3.0) - rails (~> 6.1.3, >= 6.1.3.1) - rails_failover! - sass-rails (>= 6) - unicorn - webpacker (~> 4.0) - -BUNDLED WITH - 2.3.9 diff --git a/spec/support/dummy_app/config/application.rb b/spec/support/dummy_app/config/application.rb index 91e709e..4dc14d9 100644 --- a/spec/support/dummy_app/config/application.rb +++ b/spec/support/dummy_app/config/application.rb @@ -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. diff --git a/spec/support/dummy_app/config/unicorn.conf.rb b/spec/support/dummy_app/config/unicorn.conf.rb index dbb7a1d..541818a 100644 --- a/spec/support/dummy_app/config/unicorn.conf.rb +++ b/spec/support/dummy_app/config/unicorn.conf.rb @@ -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__)) + "/../")