From 8b854c23dd9fbe2550e68fd3dec6466cddd1acb7 Mon Sep 17 00:00:00 2001 From: Mohammed Abdulkareem Date: Fri, 11 Oct 2024 21:57:18 +0300 Subject: [PATCH] Support rails.7.2 & update CI to run on Ruby 3 x Rails 6 & 7 (#2) * Support Rails 7.2 * Bumped ruby version requirement to 3.0.0 * Rubocop Ruby target as well * remove redundant sort * Update Rakefile * Update test/rails_test.rb * chore: update CI to run on Ruby 3 x Rails 6 & 7 (#3) * chore: add appraisal * update CI to run on ruby/rails matrix * continue on error * no need for dark magic rails test? * Fixed rubocop * don't use deprecated OpenStruct * exclude ruby head / rails 6.1 --------- Co-authored-by: Lud --- .github/workflows/test.yml | 35 +++++++--- .gitignore | 2 + .rubocop.yml | 6 +- Appraisals | 13 ++++ Gemfile | 1 + Rakefile | 2 +- diffcrypt.gemspec | 4 +- gemfiles/rails_6.1.gemfile | 16 +++++ gemfiles/rails_7.1.gemfile | 16 +++++ gemfiles/rails_7.2.gemfile | 16 +++++ .../rails/application_helper_test.rb | 6 +- test/rails_test.rb | 68 ------------------- 12 files changed, 98 insertions(+), 87 deletions(-) create mode 100644 Appraisals create mode 100644 gemfiles/rails_6.1.gemfile create mode 100644 gemfiles/rails_7.1.gemfile create mode 100644 gemfiles/rails_7.2.gemfile delete mode 100644 test/rails_test.rb diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 59ead51..4d23625 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,15 +7,29 @@ on: pull_request: jobs: - rspec: + tests: + name: "RSpec @ Ruby ${{ matrix.ruby }}, Rails ${{ matrix.rails }}" runs-on: ubuntu-latest + continue-on-error: true + env: + BUNDLE_GEMFILE: gemfiles/rails_${{ matrix.rails }}.gemfile strategy: matrix: ruby: - - "3.0.7" - - "3.1.5" + - "3.1" + - "3.3" + - "head" + rails: + - "6.1" + - "7.1" + - "7.2" + exclude: + - ruby: "3.3" + rails: "6.1" + - ruby: "head" + rails: "6.1" steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: @@ -24,15 +38,20 @@ jobs: - name: Run rspec run: bundle exec rake test - rubocop: + linters: + name: "Rubocop @ Ruby ${{ matrix.ruby }}, Rails ${{ matrix.rails }}" runs-on: ubuntu-latest + continue-on-error: true + env: + BUNDLE_GEMFILE: gemfiles/rails_${{ matrix.rails }}.gemfile strategy: matrix: ruby: - - "3.0.7" - - "3.1.5" + - "head" + rails: + - "7.2" steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: diff --git a/.gitignore b/.gitignore index 82d8097..01e4723 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ /tmp/ Gemfile.lock *.gem +.ruby-version +gemfiles/*.lock diff --git a/.rubocop.yml b/.rubocop.yml index 1956e70..4e700c1 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,6 @@ AllCops: NewCops: enable - TargetRubyVersion: 2.6 + TargetRubyVersion: 3.0 Style/ClassAndModuleChildren: Exclude: @@ -23,10 +23,6 @@ Style/TrailingCommaInHashLiteral: EnforcedStyleForMultiline: consistent_comma Style/AccessorGrouping: EnforcedStyle: separated -Style/OpenStructUse: - Exclude: - - test/*_test.rb - - test/**/*_test.rb Layout/LineLength: Exclude: diff --git a/Appraisals b/Appraisals new file mode 100644 index 0000000..dbb1264 --- /dev/null +++ b/Appraisals @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +SUPPORTED_RAILS_VERSIONS = %w[ + 6.1 + 7.1 + 7.2 +].freeze + +SUPPORTED_RAILS_VERSIONS.each do |version| + appraise "rails-#{version}" do + gem 'rails', "~> #{version}" + end +end diff --git a/Gemfile b/Gemfile index 5f853a1..588d2ff 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ source 'https://rubygems.org' # Specify your gem's dependencies in diffcrypt.gemspec gemspec +gem 'appraisal' gem 'minitest', '~> 5.0' gem 'minitest-reporters', '~> 1.6.0' gem 'rake', '~> 13.2' diff --git a/Rakefile b/Rakefile index df48b05..a47194d 100644 --- a/Rakefile +++ b/Rakefile @@ -11,4 +11,4 @@ end task default: :test path = File.expand_path(__dir__) -Dir.glob("#{path}/lib/diffcrypt/tasks/**/*.rake").sort.each { |f| load f } +Dir.glob("#{path}/lib/diffcrypt/tasks/**/*.rake").each { load(_1) } diff --git a/diffcrypt.gemspec b/diffcrypt.gemspec index 3ae32cd..ba83b57 100644 --- a/diffcrypt.gemspec +++ b/diffcrypt.gemspec @@ -12,7 +12,7 @@ Gem::Specification.new do |spec| spec.description = 'Diffable encrypted configuration files that can be safely committed into a git repository' spec.homepage = 'https://github.com/diffcrypt/diffcrypt-ruby' spec.license = 'MIT' - spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0') + spec.required_ruby_version = Gem::Requirement.new('>= 3.0.0') # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'" @@ -29,7 +29,7 @@ Gem::Specification.new do |spec| spec.executables = %w[diffcrypt] spec.require_paths = ['lib'] - spec.add_runtime_dependency 'activesupport', '>= 6.0', '< 7.2' + spec.add_runtime_dependency 'activesupport', '>= 6.0', '< 7.3' spec.add_runtime_dependency 'thor', '>= 0.20', '< 2' spec.metadata['rubygems_mfa_required'] = 'true' end diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile new file mode 100644 index 0000000..3b0fe0f --- /dev/null +++ b/gemfiles/rails_6.1.gemfile @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# This file was generated by Appraisal + +source 'https://rubygems.org' + +gem 'appraisal' +gem 'minitest', '~> 5.0' +gem 'minitest-reporters', '~> 1.6.0' +gem 'rails', '~> 6.1' +gem 'rake', '~> 13.2' +gem 'rubocop', '~> 1.25.1' +gem 'simplecov', '~> 0.22.0', require: false +gem 'simplecov-lcov', '< 0.9' + +gemspec path: '../' diff --git a/gemfiles/rails_7.1.gemfile b/gemfiles/rails_7.1.gemfile new file mode 100644 index 0000000..3f4cbf5 --- /dev/null +++ b/gemfiles/rails_7.1.gemfile @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# This file was generated by Appraisal + +source 'https://rubygems.org' + +gem 'appraisal' +gem 'minitest', '~> 5.0' +gem 'minitest-reporters', '~> 1.6.0' +gem 'rails', '~> 7.1' +gem 'rake', '~> 13.2' +gem 'rubocop', '~> 1.25.1' +gem 'simplecov', '~> 0.22.0', require: false +gem 'simplecov-lcov', '< 0.9' + +gemspec path: '../' diff --git a/gemfiles/rails_7.2.gemfile b/gemfiles/rails_7.2.gemfile new file mode 100644 index 0000000..91c2eb6 --- /dev/null +++ b/gemfiles/rails_7.2.gemfile @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# This file was generated by Appraisal + +source 'https://rubygems.org' + +gem 'appraisal' +gem 'minitest', '~> 5.0' +gem 'minitest-reporters', '~> 1.6.0' +gem 'rails', '~> 7.2' +gem 'rake', '~> 13.2' +gem 'rubocop', '~> 1.25.1' +gem 'simplecov', '~> 0.22.0', require: false +gem 'simplecov-lcov', '< 0.9' + +gemspec path: '../' diff --git a/test/diffcrypt/rails/application_helper_test.rb b/test/diffcrypt/rails/application_helper_test.rb index 5fb8930..f07ad05 100644 --- a/test/diffcrypt/rails/application_helper_test.rb +++ b/test/diffcrypt/rails/application_helper_test.rb @@ -7,10 +7,10 @@ class MockApplication include Diffcrypt::Rails::ApplicationHelper + Config = Struct.new(:require_master_key) + def config - OpenStruct.new( - require_master_key: true, - ) + Config.new(true) end end diff --git a/test/rails_test.rb b/test/rails_test.rb deleted file mode 100644 index 360da83..0000000 --- a/test/rails_test.rb +++ /dev/null @@ -1,68 +0,0 @@ -# frozen_string_literal: true - -require 'test_helper' -require 'bundler' - -require 'open3' - -RAILS_VERSIONS = %w[ - 6.1.7.7 - 7.0.8.3 - 7.1.3.3 -].freeze - -RAILS_FLAGS = %w[ - --api - --skip-action-cable - --skip-active-storage - --skip-bundle - --skip-git - --skip-javascript - --skip-keeps - --skip-system-test - --skip-test -].freeze - -TMP_RAILS_ROOT = File.join(__dir__, '../tmp/test') - -# Helper to ensure we raise if command is not successful -def run_command(*command) - stdout, stderr, status = Open3.capture3(*command) - if status.success? == false - errors = [ - " Command Failed: #{command.join(' ')}", - stdout.split("\n").map { |line| " #{line}" }.join("\n"), - stderr.split("\n").map { |line| " #{line}" }.join("\n"), - ] - raise errors.join("\n") - end - - [stdout, stderr, status] -end - -class RailsTest < Minitest::Test - def setup - FileUtils.mkdir_p(TMP_RAILS_ROOT) unless Dir.exist?(TMP_RAILS_ROOT) - end - - RAILS_VERSIONS.each do |rails_version| - define_method "test_that_rails_#{rails_version.gsub('.', '_')}_works" do - Bundler.with_unbundled_env do - Dir.chdir(TMP_RAILS_ROOT) do - tmp_version_root = "rails_#{rails_version.gsub('.', '_')}" - FileUtils.remove_dir(tmp_version_root) if Dir.exist?(tmp_version_root) - run_command('gem', 'install', 'rails', '--version', rails_version, '--force') - run_command('rails', "_#{rails_version}_", 'new', *RAILS_FLAGS, tmp_version_root) - raise "Rails #{rails_version} app creation failed" unless Dir.exist?(tmp_version_root) - - Dir.chdir(tmp_version_root) do - File.write('Gemfile', "gem 'diffcrypt', path: '../../..'", mode: 'a') - run_command('bundle', 'install') - stdout, _stderr, _status = run_command('bundle', 'exec', 'rails', 'r', 'puts Rails.version') - assert_equal rails_version, stdout.strip - end - end - end - end - end -end