From 6891bba3091dcfa9e9c38b184d4575659b6147dc Mon Sep 17 00:00:00 2001 From: Hans Lemuet Date: Thu, 6 Jan 2022 11:03:37 +0100 Subject: [PATCH] Use Appraisal in CI Appraisal allows us to test with different versions of gems. In addition to GitHub Actions' matrix functionality, we can use this to test against different combinations of Ruby and Rails versions. As part of this, we've also made the following changes to our CI pipeline: Rename Appraisal rails-head to rails-main Loosen version constraints to minor versions Use setup-ruby's caching mechanism Means we don't need to configure vendor/bundle as the path here. We should probably do this for other workflows too. Don't trigger CI twice on PRs Co-authored-by: Simon Fish --- .github/workflows/ci.yml | 85 ++++++++----------- Appraisals | 8 +- Gemfile | 4 + Gemfile.lock | 2 +- docs/CHANGELOG.md | 4 + gemfiles/rails_5.2.gemfile | 19 +++++ gemfiles/rails_6.0.gemfile | 20 +++++ gemfiles/rails_6.1.gemfile | 15 ++-- gemfiles/rails_7.0.gemfile | 12 ++- gemfiles/rails_7.1.gemfile | 12 ++- ...{rails_head.gemfile => rails_main.gemfile} | 10 ++- lib/view_component/test_helpers.rb | 3 + 12 files changed, 131 insertions(+), 63 deletions(-) create mode 100644 gemfiles/rails_5.2.gemfile create mode 100644 gemfiles/rails_6.0.gemfile rename gemfiles/{rails_head.gemfile => rails_main.gemfile} (58%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bdb7dbbb63..00c7fdb2ac 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,10 @@ name: CI -on: [push, pull_request] +on: + pull_request: + push: + branches: + - main jobs: benchmark: @@ -22,65 +26,50 @@ jobs: bundle exec rake partial_benchmark bundle exec rake translatable_benchmark test: + name: test (${{ matrix.rails_version }}, ${{ matrix.ruby_version }}, ${{ matrix.mode }}) runs-on: ubuntu-latest strategy: fail-fast: false matrix: + rails_version: ["6.1", "7.0", "7.1", "main"] + ruby_version: ["3.1", "3.2", "3.3"] + mode: ["capture_patch_enabled", "capture_patch_disabled"] include: - - rails_version: "6.1.4.4" - ruby_version: "3.0" - mode: "capture_patch_enabled" - - rails_version: "7.0.2.3" - ruby_version: "3.0" - mode: "capture_patch_enabled" - - rails_version: "main" - ruby_version: "3.1" - mode: "capture_patch_enabled" - - rails_version: "7.1.1" - ruby_version: "3.2" - mode: "capture_patch_enabled" - - rails_version: "main" - ruby_version: "3.2" - mode: "capture_patch_enabled" - - rails_version: "6.1.4.4" - ruby_version: "3.0" - mode: "capture_patch_disabled" - - rails_version: "7.0.2.3" - ruby_version: "3.0" - mode: "capture_patch_disabled" - - rails_version: "main" - ruby_version: "3.1" - mode: "capture_patch_disabled" - - rails_version: "7.1.1" - ruby_version: "3.2" - mode: "capture_patch_disabled" - - rails_version: "main" - ruby_version: "3.2" - mode: "capture_patch_disabled" - - rails_version: "7.1.1" - ruby_version: "3.3" - mode: "capture_patch_disabled" - - rails_version: "main" - ruby_version: "3.3" - mode: "capture_patch_disabled" + # Run against all previously supported Rails versions for Ruby 3.0 + - ruby_version: "3.0" + rails_version: "6.1" + capture_patch_enabled: true + - ruby_version: "3.0" + rails_version: "6.1" + capture_patch_enabled: false + - ruby_version: "3.0" + rails_version: "7.0" + capture_patch_enabled: true + - ruby_version: "3.0" + rails_version: "7.0" + capture_patch_enabled: false + - ruby_version: "3.0" + rails_version: "7.1" + capture_patch_enabled: true + - ruby_version: "3.0" + rails_version: "7.1" + capture_patch_enabled: false + env: + BUNDLE_GEMFILE: gemfiles/rails_${{ matrix.rails_version }}.gemfile steps: - uses: actions/checkout@v4.1.1 - name: Setup Ruby uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby_version }} - - uses: actions/cache@v3 - with: - path: vendor/bundle - key: gems-build-rails-${{ matrix.rails_version }}-ruby-${{ matrix.ruby_version }}-${{ hashFiles('**/Gemfile.lock') }} + bundler-cache: true - name: Build and test with Rake + # Code-reloading isn't compatible with simplecov, so we need to run once + # to collect coverage, and again to test reloads. run: | - bundle config path vendor/bundle - bundle update - # Code-reloading isn't compatible with simplecov, so we need to run once - # to collect coverage, and again to test reloads. - MEASURE_COVERAGE=true bundle exec rake test spec - ENABLE_RELOADING=true bundle exec rake test spec + bundle exec appraisal rails-${{ matrix.rails_version }} bundle + MEASURE_COVERAGE=true bundle exec appraisal rails-${{ matrix.rails_version }} rake + ENABLE_RELOADING=true bundle exec appraisal rails-${{ matrix.rails_version }} rake env: RAISE_ON_WARNING: 1 RAILS_VERSION: ${{ matrix.rails_version }} @@ -89,7 +78,7 @@ jobs: uses: actions/upload-artifact@v3.1.3 if: always() with: - name: simplecov-resultset-rails${{matrix.rails_version}}-ruby${{matrix.ruby_version}} + name: simplecov-resultset-rails${{ matrix.rails_version }}-ruby${{ matrix.ruby_version }} path: coverage primer_view_components_compatibility: name: Test compatibility with Primer ViewComponents (main) diff --git a/Appraisals b/Appraisals index 02dfc4ebc8..31446f8f73 100644 --- a/Appraisals +++ b/Appraisals @@ -1,7 +1,7 @@ # frozen_string_literal: true appraise "rails-6.1" do - gem "rails", "~> 6.1.0" + gem "rails", "~> 6.1" gem "tailwindcss-rails", "~> 2.0" # Required for Ruby 3.1.0 @@ -11,16 +11,16 @@ appraise "rails-6.1" do end appraise "rails-7.0" do - gem "rails", "~> 7.0.0" + gem "rails", "~> 7.0" gem "tailwindcss-rails", "~> 2.0" end appraise "rails-7.1" do - gem "rails", "~> 7.1.0" + gem "rails", "~> 7.1" gem "tailwindcss-rails", "~> 2.0" end -appraise "rails-head" do +appraise "rails-main" do gem "rails", github: "rails/rails", branch: "main" gem "tailwindcss-rails", "~> 2.0" end diff --git a/Gemfile b/Gemfile index 32791882ee..fdced803cc 100644 --- a/Gemfile +++ b/Gemfile @@ -18,6 +18,10 @@ group :test do gem "selenium-webdriver", "4.9.0" # 4.9.1 requires Ruby 3+ end +group :development, :test do + gem "appraisal", "~> 2.5" +end + if RUBY_VERSION >= "3.1" gem "net-imap", require: false gem "net-pop", require: false diff --git a/Gemfile.lock b/Gemfile.lock index 9be3a638b1..bf846a20a3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -326,7 +326,7 @@ PLATFORMS ruby DEPENDENCIES - appraisal (~> 2.4) + appraisal (~> 2.5) benchmark-ips (~> 2.13.0) better_html bundler (~> 2) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index ac7dded7fc..d31d013d5e 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,6 +10,10 @@ nav_order: 5 ## main +* Update CI configuration to use `Appraisal`. + + *Hans Lemuet, Simon Fish* + * Add support for Ruby 3.3. *Reegan Viljoen* diff --git a/gemfiles/rails_5.2.gemfile b/gemfiles/rails_5.2.gemfile new file mode 100644 index 0000000000..383c308485 --- /dev/null +++ b/gemfiles/rails_5.2.gemfile @@ -0,0 +1,19 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "capybara", "~> 3" +gem "rails", "~> 5.2.0" +gem "rspec-rails", "~> 5" + +group :test do + gem "cuprite", "~> 0.8" + gem "puma", "~> 5" + gem "selenium-webdriver", "~> 4" +end + +group :development, :test do + gem "appraisal", github: "thoughtbot/appraisal" +end + +gemspec path: "../" diff --git a/gemfiles/rails_6.0.gemfile b/gemfiles/rails_6.0.gemfile new file mode 100644 index 0000000000..77de2ea0c5 --- /dev/null +++ b/gemfiles/rails_6.0.gemfile @@ -0,0 +1,20 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "capybara", "~> 3" +gem "rails", "~> 6.0.0" +gem "rspec-rails", "~> 5" +gem "tailwindcss-rails", "~> 2.0" + +group :test do + gem "cuprite", "~> 0.8" + gem "puma", "~> 5" + gem "selenium-webdriver", "~> 4" +end + +group :development, :test do + gem "appraisal", github: "thoughtbot/appraisal" +end + +gemspec path: "../" diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile index 8c7e7c7684..a865770983 100644 --- a/gemfiles/rails_6.1.gemfile +++ b/gemfiles/rails_6.1.gemfile @@ -3,18 +3,23 @@ source "https://rubygems.org" gem "capybara", "~> 3" -gem "rails", "~> 6.1.0" +gem "rails", "~> 6.1" gem "rspec-rails", "~> 5" -gem "debug" -gem "tailwindcss-rails", "~> 2.0" -gem "net-smtp", require: false gem "net-imap", require: false gem "net-pop", require: false +gem "net-smtp", require: false +gem "debug" +gem "tailwindcss-rails", "~> 2.0" group :test do - gem "cuprite", "~> 0.8" + gem "cuprite", "~> 0.15" gem "puma", "~> 6" + gem "warning" gem "selenium-webdriver", "4.9.0" end +group :development, :test do + gem "appraisal", github: "thoughtbot/appraisal" +end + gemspec path: "../" diff --git a/gemfiles/rails_7.0.gemfile b/gemfiles/rails_7.0.gemfile index d08c4f8e20..7898d8fea1 100644 --- a/gemfiles/rails_7.0.gemfile +++ b/gemfiles/rails_7.0.gemfile @@ -3,15 +3,23 @@ source "https://rubygems.org" gem "capybara", "~> 3" -gem "rails", "~> 7.0.0" +gem "rails", "~> 7.0" gem "rspec-rails", "~> 5" +gem "net-imap", require: false +gem "net-pop", require: false +gem "net-smtp", require: false gem "debug" gem "tailwindcss-rails", "~> 2.0" group :test do - gem "cuprite", "~> 0.8" + gem "cuprite", "~> 0.15" gem "puma", "~> 6" + gem "warning" gem "selenium-webdriver", "4.9.0" end +group :development, :test do + gem "appraisal", github: "thoughtbot/appraisal" +end + gemspec path: "../" diff --git a/gemfiles/rails_7.1.gemfile b/gemfiles/rails_7.1.gemfile index 28e79bf1e6..be88aee364 100644 --- a/gemfiles/rails_7.1.gemfile +++ b/gemfiles/rails_7.1.gemfile @@ -3,15 +3,23 @@ source "https://rubygems.org" gem "capybara", "~> 3" -gem "rails", "~> 7.1.0" +gem "rails", "~> 7.1" gem "rspec-rails", "~> 5" +gem "net-imap", require: false +gem "net-pop", require: false +gem "net-smtp", require: false gem "debug" gem "tailwindcss-rails", "~> 2.0" group :test do - gem "cuprite", "~> 0.8" + gem "cuprite", "~> 0.15" gem "puma", "~> 6" + gem "warning" gem "selenium-webdriver", "4.9.0" end +group :development, :test do + gem "appraisal", github: "thoughtbot/appraisal" +end + gemspec path: "../" diff --git a/gemfiles/rails_head.gemfile b/gemfiles/rails_main.gemfile similarity index 58% rename from gemfiles/rails_head.gemfile rename to gemfiles/rails_main.gemfile index 904c552a7d..428f763546 100644 --- a/gemfiles/rails_head.gemfile +++ b/gemfiles/rails_main.gemfile @@ -5,13 +5,21 @@ source "https://rubygems.org" gem "capybara", "~> 3" gem "rails", github: "rails/rails", branch: "main" gem "rspec-rails", "~> 5" +gem "net-imap", require: false +gem "net-pop", require: false +gem "net-smtp", require: false gem "debug" gem "tailwindcss-rails", "~> 2.0" group :test do - gem "cuprite", "~> 0.8" + gem "cuprite", "~> 0.15" gem "puma", "~> 6" + gem "warning" gem "selenium-webdriver", "4.9.0" end +group :development, :test do + gem "appraisal", github: "thoughtbot/appraisal" +end + gemspec path: "../" diff --git a/lib/view_component/test_helpers.rb b/lib/view_component/test_helpers.rb index 69d4b8114d..60ab49779b 100644 --- a/lib/view_component/test_helpers.rb +++ b/lib/view_component/test_helpers.rb @@ -252,9 +252,11 @@ def __vc_test_helpers_build_controller(klass) def __vc_test_helpers_preview_class result = if respond_to?(:described_class) + # :nocov: raise "`render_preview` expected a described_class, but it is nil." if described_class.nil? "#{described_class}Preview" + # :nocov: else self.class.name.gsub("Test", "Preview") end @@ -262,5 +264,6 @@ def __vc_test_helpers_preview_class rescue NameError raise NameError, "`render_preview` expected to find #{result}, but it does not exist." end + # :nocov: end end