From 893ad840a80d90969a16eb1b04c9212f4f75e468 Mon Sep 17 00:00:00 2001 From: Jason Frey Date: Tue, 15 Feb 2022 17:43:39 -0500 Subject: [PATCH 1/2] Switch to GitHub Actions --- .github/workflows/ci.yaml | 40 +++++++++++++++++++++++++++++++++++++++ .rspec | 3 +-- .travis.yml | 23 ---------------------- Gemfile | 2 -- README.md | 7 ++++--- bundler-inject.gemspec | 2 +- 6 files changed, 46 insertions(+), 31 deletions(-) create mode 100644 .github/workflows/ci.yaml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..b1235d6 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,40 @@ +name: CI + +on: + push: + pull_request: + schedule: + - cron: '0 0 * * 0' + +jobs: + ci: + runs-on: ubuntu-latest + strategy: + matrix: + ruby-version: + - '2.7' + - '3.0' + bundler-version: + - '2.1.4' + - '2.2.33' + - '2.3.10' + include: + - ruby-version: '2.6' + bundler-version: '2.0.2' + env: + TEST_BUNDLER_VERSION: ${{ matrix.bundler-version }} + CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler: ${{ matrix.bundler-version }} + bundler-cache: true + - name: Run tests + run: bundle exec rake + - name: Report code coverage + if: ${{ github.ref == 'refs/heads/master' && matrix.ruby-version == '3.0' && matrix.bundler-version == '2.3.10' }} + continue-on-error: true + uses: paambaati/codeclimate-action@v3.0.0 diff --git a/.rspec b/.rspec index 6c6110e..b4065e3 100644 --- a/.rspec +++ b/.rspec @@ -1,4 +1,3 @@ ---format documentation ---color --require spec_helper +--color --order random diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 07902a4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,23 +0,0 @@ ---- -language: ruby -cache: bundler -rvm: -- 2.7.3 -- 3.0.1 -env: -- TEST_BUNDLER_VERSION=2.1 -- TEST_BUNDLER_VERSION=2.2 -jobs: - include: - - rvm: 2.6.7 - env: TEST_BUNDLER_VERSION=2.0 -before_install: -- 'echo ''gem: --no-ri --no-rdoc --no-document'' > ~/.gemrc' -- gem install bundler -v "~> $TEST_BUNDLER_VERSION.0" -before_script: -- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 - > ./cc-test-reporter -- chmod +x ./cc-test-reporter -- "./cc-test-reporter before-build" -after_script: -- "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT" diff --git a/Gemfile b/Gemfile index f30720d..3e11431 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,4 @@ source "https://rubygems.org" -git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } - # Specify your gem's dependencies in bundler-inject.gemspec gemspec diff --git a/README.md b/README.md index 8511dd5..1fe94a4 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ # bundler-inject -[![Build Status](https://travis-ci.org/ManageIQ/bundler-inject.svg?branch=master)](https://travis-ci.org/ManageIQ/bundler-inject) -[![Maintainability](https://api.codeclimate.com/v1/badges/e4650d6dd7cbcd981057/maintainability)](https://codeclimate.com/github/ManageIQ/bundler-inject/maintainability) -[![Test Coverage](https://api.codeclimate.com/v1/badges/e4650d6dd7cbcd981057/test_coverage)](https://codeclimate.com/github/ManageIQ/bundler-inject/test_coverage) +[![Gem Version](https://badge.fury.io/rb/bundler-inject.svg)](http://badge.fury.io/rb/bundler-inject) +[![CI](https://github.com/ManageIQ/bundler-inject/actions/workflows/ci.yaml/badge.svg)](https://github.com/ManageIQ/bundler-inject/actions/workflows/ci.yaml) +[![Code Climate](https://codeclimate.com/github/ManageIQ/bundler-inject.svg)](https://codeclimate.com/github/ManageIQ/bundler-inject) +[![Test Coverage](https://codeclimate.com/github/ManageIQ/bundler-inject/badges/coverage.svg)](https://codeclimate.com/github/ManageIQ/bundler-inject/coverage) **bundler-inject** is a [bundler plugin](https://bundler.io/guides/bundler_plugins.html) that allows a developer to extend a project with their own personal gems and/or diff --git a/bundler-inject.gemspec b/bundler-inject.gemspec index 3eaf148..8149111 100644 --- a/bundler-inject.gemspec +++ b/bundler-inject.gemspec @@ -34,5 +34,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "manageiq-style" spec.add_development_dependency "rake", "~> 10.0" spec.add_development_dependency "rspec", "~> 3.0" - spec.add_development_dependency "simplecov" + spec.add_development_dependency "simplecov", ">= 0.21.2" end From 4eb551a4f77e3b2cd4be9090b8e8dc769d2b12c0 Mon Sep 17 00:00:00 2001 From: Jason Frey Date: Mon, 4 Apr 2022 17:36:56 -0400 Subject: [PATCH 2/2] Choose new (hopefully more stable) gems for the tests The latest rack, which was used as the "gem with no dependencies", introduced a new dependency, complicating the specs, so this commit replaces them with gems that following the same pattern, but haven't been updated in a long time. - rack-obama is replaced with rubytest - rack is replaced with ansi The gem versions used in these specs follow a specific pattern in order to test various versions and overrides. rubytest 0.7.0 depends on ansi >= 0 which has no dependencies. This allows us to manipulate the various versions of ansi without introducing additional dependencies complicating the test. ansi 1.4.2, 1.4.3, 1.5.0 are the three latest versions, and most tests "start" with ansi 1.4.3 in the base Gemfile. omg 0.0.6 is an additional gem that also has no dependencies. --- spec/bundler_inject_spec.rb | 123 +++++++++++++++++++----------------- spec/support/helpers.rb | 8 --- 2 files changed, 65 insertions(+), 66 deletions(-) diff --git a/spec/bundler_inject_spec.rb b/spec/bundler_inject_spec.rb index 00c5ffc..2a3adea 100644 --- a/spec/bundler_inject_spec.rb +++ b/spec/bundler_inject_spec.rb @@ -1,3 +1,10 @@ +# The gem versions used in these specs follow a specific pattern in order to +# test various versions and overrides. rubytest 0.7.0 depends on ansi >= 0 which +# has no dependencies. This allows us to manipulate the various versions of +# ansi without introducing additional dependencies complicating the test. +# ansi 1.4.2, 1.4.3, 1.5.0 are the three latest versions, and most tests "start" +# with ansi 1.4.3 in the base Gemfile. omg 0.0.6 is an additional gem that also +# has no dependencies. RSpec.describe Bundler::Inject do let(:base_gemfile) do bundler_inject_root = Pathname.new(__dir__).join("..").expand_path @@ -54,86 +61,86 @@ bundle(:update, verbose: true) expect(out).to_not match /^Injecting / - expect(lockfile_specs).to eq [["rack", "2.0.6"]] + expect(lockfile_specs).to eq [["ansi", "1.4.3"]] end end describe "#gem" do it "with local file" do write_bundler_d_file <<~F - gem "rack-obama" + gem "rubytest", "=0.7.0" F bundle(:update) - expect(lockfile_specs).to match_array [["rack", "2.0.6"], ["rack-obama", "0.1.1"]] + expect(lockfile_specs).to match_array [["ansi", "1.4.3"], ["rubytest", "0.7.0"]] end it "with global file" do write_global_bundler_d_file <<~F - gem "rack-obama" + gem "rubytest", "=0.7.0" F bundle(:update) - expect(lockfile_specs).to match_array [["rack", "2.0.6"], ["rack-obama", "0.1.1"]] + expect(lockfile_specs).to match_array [["ansi", "1.4.3"], ["rubytest", "0.7.0"]] end it "with local and global files" do write_bundler_d_file <<~F - gem "rack-obama" + gem "rubytest", "=0.7.0" F write_global_bundler_d_file <<~F gem "omg" F bundle(:update) - expect(lockfile_specs).to match_array [["rack", "2.0.6"], ["rack-obama", "0.1.1"], ["omg", "0.0.6"]] + expect(lockfile_specs).to match_array [["ansi", "1.4.3"], ["rubytest", "0.7.0"], ["omg", "0.0.6"]] end end describe "#override_gem" do it "with a different version" do write_bundler_d_file <<~F - override_gem "rack", "=2.0.5" + override_gem "ansi", "=1.4.2" F bundle(:update) - expect(lockfile_specs).to eq [["rack", "2.0.5"]] - expect(err).to match %r{^\*\* override_gem\("rack", "=2.0.5"\) at .+/bundler\.d/local_overrides\.rb:1$} + expect(lockfile_specs).to eq [["ansi", "1.4.2"]] + expect(err).to match %r{^\*\* override_gem\("ansi", "=1.4.2"\) at .+/bundler\.d/local_overrides\.rb:1$} end it "with a git repo" do write_bundler_d_file <<~F - override_gem "rack", :git => "https://github.com/rack/rack" + override_gem "ansi", :git => "https://github.com/rubyworks/ansi" F bundle(:update) - expect(lockfile_specs).to eq [["rack", extract_rack_version]] - expect(err).to match %r{^\*\* override_gem\("rack", :git=>"https://github.com/rack/rack"\) at .+/bundler\.d/local_overrides\.rb:1$} + expect(lockfile_specs).to eq [["ansi", "1.5.0"]] + expect(err).to match %r{^\*\* override_gem\("ansi", :git=>"https://github.com/rubyworks/ansi"\) at .+/bundler\.d/local_overrides\.rb:1$} end it "with a path" do - with_path_based_gem("https://github.com/rack/rack") do |path| + with_path_based_gem("https://github.com/rubyworks/ansi") do |path| write_bundler_d_file <<~F - override_gem "rack", :path => #{path.to_s.inspect} + override_gem "ansi", :path => #{path.to_s.inspect} F bundle(:update) - expect(lockfile_specs).to eq [["rack", extract_rack_version(path)]] - expect(err).to match %r{^\*\* override_gem\("rack", :path=>#{path.to_s.inspect}\) at .+/bundler\.d/local_overrides\.rb:1$} + expect(lockfile_specs).to eq [["ansi", "1.5.0"]] + expect(err).to match %r{^\*\* override_gem\("ansi", :path=>#{path.to_s.inspect}\) at .+/bundler\.d/local_overrides\.rb:1$} end end it "with a path that includes ~" do - with_path_based_gem("https://github.com/rack/rack") do |path| + with_path_based_gem("https://github.com/rubyworks/ansi") do |path| path = Pathname.new("~/#{path.relative_path_from(Pathname.new("~").expand_path)}") write_bundler_d_file <<~F - override_gem "rack", :path => #{path.to_s.inspect} + override_gem "ansi", :path => #{path.to_s.inspect} F bundle(:update) - expect(lockfile_specs).to eq [["rack", extract_rack_version(path)]] - expect(err).to match %r{^\*\* override_gem\("rack", :path=>#{path.expand_path.to_s.inspect}\) at .+/bundler\.d/local_overrides\.rb:1$} + expect(lockfile_specs).to eq [["ansi", "1.5.0"]] + expect(err).to match %r{^\*\* override_gem\("ansi", :path=>#{path.expand_path.to_s.inspect}\) at .+/bundler\.d/local_overrides\.rb:1$} end end @@ -148,34 +155,34 @@ it "with ENV['BUNDLE_BUNDLER_INJECT__DISABLE_WARN_OVERRIDE_GEM'] = 'true'" do write_bundler_d_file <<~F - override_gem "rack", "=2.0.5" + override_gem "ansi", "=1.4.2" F env_var = "BUNDLE_BUNDLER_INJECT__DISABLE_WARN_OVERRIDE_GEM" bundle(:update, env: { env_var => "true" }) - expect(lockfile_specs).to eq [["rack", "2.0.5"]] + expect(lockfile_specs).to eq [["ansi", "1.4.2"]] expect(err).to_not match %r{^\*\* override_gem} end it "with ENV['RAILS_ENV'] = 'production'" do write_bundler_d_file <<~F - override_gem "rack", "=2.0.5" + override_gem "ansi", "=1.4.2" F bundle(:update, env: { "RAILS_ENV" => "production" }) - expect(lockfile_specs).to eq [["rack", "2.0.5"]] + expect(lockfile_specs).to eq [["ansi", "1.4.2"]] expect(err).to_not match %r{^\*\* override_gem} end it "with ENV['RAILS_ENV'] = 'production' and the Bundler::Setting false" do write_bundler_d_file <<~F - override_gem "rack", "=2.0.5" + override_gem "ansi", "=1.4.2" F env_var = "BUNDLE_BUNDLER_INJECT__DISABLE_WARN_OVERRIDE_GEM" bundle(:update, env: { "RAILS_ENV" => "production", env_var => 'false' }) - expect(lockfile_specs).to eq [["rack", "2.0.5"]] - expect(err).to match %r{^\*\* override_gem\("rack", "=2.0.5"\) at .+/bundler\.d/local_overrides\.rb:1$} + expect(lockfile_specs).to eq [["ansi", "1.4.2"]] + expect(err).to match %r{^\*\* override_gem\("ansi", "=1.4.2"\) at .+/bundler\.d/local_overrides\.rb:1$} end end @@ -186,48 +193,48 @@ F bundle(:update) - expect(lockfile_specs).to match_array [["rack", "2.0.6"], ["omg", "0.0.6"]] + expect(lockfile_specs).to match_array [["ansi", "1.4.3"], ["omg", "0.0.6"]] expect(err).to_not match %r{^\*\* override_gem} end it "when overriding without a version" do write_global_bundler_d_file <<~F - ensure_gem "rack" + ensure_gem "ansi" F bundle(:update) - expect(lockfile_specs).to eq [["rack", "2.0.6"]] + expect(lockfile_specs).to eq [["ansi", "1.4.3"]] expect(err).to_not match %r{^\*\* override_gem} end it "when overriding with the same version" do write_global_bundler_d_file <<~F - ensure_gem "rack", "=2.0.6" + ensure_gem "ansi", "=1.4.3" F bundle(:update) - expect(lockfile_specs).to eq [["rack", "2.0.6"]] + expect(lockfile_specs).to eq [["ansi", "1.4.3"]] expect(err).to_not match %r{^\*\* override_gem} end it "when overriding with a different version" do write_global_bundler_d_file <<~F - ensure_gem "rack", "=2.0.5" + ensure_gem "ansi", "=1.4.2" F bundle(:update) - expect(lockfile_specs).to eq [["rack", "2.0.5"]] - expect(err).to match %r{^\*\* override_gem\("rack", "=2.0.5"\) at .+/\.bundler\.d/global_overrides\.rb:1$} + expect(lockfile_specs).to eq [["ansi", "1.4.2"]] + expect(err).to match %r{^\*\* override_gem\("ansi", "=1.4.2"\) at .+/\.bundler\.d/global_overrides\.rb:1$} end it "when overriding with other options" do write_global_bundler_d_file <<~F - override_gem "rack", :git => "https://github.com/rack/rack" + override_gem "ansi", :git => "https://github.com/rubyworks/ansi" F bundle(:update) - expect(lockfile_specs).to eq [["rack", extract_rack_version]] - expect(err).to match %r{^\*\* override_gem\("rack", :git=>"https://github.com/rack/rack"\) at .+/\.bundler\.d/global_overrides\.rb:1$} + expect(lockfile_specs).to eq [["ansi", "1.5.0"]] + expect(err).to match %r{^\*\* override_gem\("ansi", :git=>"https://github.com/rubyworks/ansi"\) at .+/\.bundler\.d/global_overrides\.rb:1$} end end end @@ -236,13 +243,13 @@ shared_examples_for "bundle check/exec" do context "bundle check/exec" do let(:exec_command) do - %q{ruby -e "puts Bundler.load.gems.select { |g| %w[rack rack-obama omg].include?(g.name) }.map { |g| [g.name, g.version.version] }.sort.inspect"} + %q{ruby -e "puts Bundler.load.gems.select { |g| %w[ansi rubytest omg].include?(g.name) }.map { |g| [g.name, g.version.version] }.sort.inspect"} end describe "#gem" do before do write_bundler_d_file <<~F - gem "rack-obama" + gem "rubytest", "=0.7.0" F write_global_bundler_d_file <<~F gem "omg" @@ -260,7 +267,7 @@ it "bundle exec" do bundle("exec #{exec_command}") - expect(out).to eq %Q{[["omg", "0.0.6"], ["rack", "2.0.6"], ["rack-obama", "0.1.1"]]\n} + expect(out).to eq %Q{[["ansi", "1.4.3"], ["omg", "0.0.6"], ["rubytest", "0.7.0"]]\n} expect(err).to be_empty end end @@ -268,8 +275,8 @@ describe "#override_gem" do before do write_bundler_d_file <<~F - override_gem "rack", "=2.0.5" - gem "rack-obama" + override_gem "ansi", "=1.4.2" + gem "rubytest", "=0.7.0" F write_global_bundler_d_file <<~F gem "omg" @@ -281,14 +288,14 @@ bundle(:check) expect(out).to eq "The Gemfile's dependencies are satisfied\n" - expect(err).to match %r{\A\*\* override_gem\("rack", "=2.0.5"\) at .+/bundler\.d/local_overrides\.rb:1\n\z} + expect(err).to match %r{\A\*\* override_gem\("ansi", "=1.4.2"\) at .+/bundler\.d/local_overrides\.rb:1\n\z} end it "bundle exec" do bundle("exec #{exec_command}") - expect(out).to eq %Q{[["omg", "0.0.6"], ["rack", "2.0.5"], ["rack-obama", "0.1.1"]]\n} - expect(err).to match %r{\A\*\* override_gem\("rack", "=2.0.5"\) at .+/bundler\.d/local_overrides\.rb:1\n\z} + expect(out).to eq %Q{[["ansi", "1.4.2"], ["omg", "0.0.6"], ["rubytest", "0.7.0"]]\n} + expect(err).to match %r{\A\*\* override_gem\("ansi", "=1.4.2"\) at .+/bundler\.d/local_overrides\.rb:1\n\z} end end @@ -296,10 +303,10 @@ before do write_bundler_d_file <<~F gem "omg" - gem "rack-obama" + gem "rubytest", "=0.7.0" F write_global_bundler_d_file <<~F - ensure_gem "rack", "=2.0.5" + ensure_gem "ansi", "=1.4.2" F bundle(:update) end @@ -308,14 +315,14 @@ bundle(:check) expect(out).to eq "The Gemfile's dependencies are satisfied\n" - expect(err).to match %r{\A\*\* override_gem\("rack", "=2.0.5"\) at .+/\.bundler\.d/global_overrides\.rb:1\n\z} + expect(err).to match %r{\A\*\* override_gem\("ansi", "=1.4.2"\) at .+/\.bundler\.d/global_overrides\.rb:1\n\z} end it "bundle exec" do bundle("exec #{exec_command}") - expect(out).to eq %Q{[["omg", "0.0.6"], ["rack", "2.0.5"], ["rack-obama", "0.1.1"]]\n} - expect(err).to match %r{\A\*\* override_gem\("rack", "=2.0.5"\) at .+/\.bundler\.d/global_overrides\.rb:1\n\z} + expect(out).to eq %Q{[["ansi", "1.4.2"], ["omg", "0.0.6"], ["rubytest", "0.7.0"]]\n} + expect(err).to match %r{\A\*\* override_gem\("ansi", "=1.4.2"\) at .+/\.bundler\.d/global_overrides\.rb:1\n\z} end end end @@ -326,7 +333,7 @@ write_gemfile <<~G #{base_gemfile} - gem "rack", "=2.0.6" + gem "ansi", "=1.4.3" G end @@ -346,7 +353,7 @@ write_gemfile <<~G #{base_gemfile} - gem "rack", "=2.0.6" + gem "ansi", "=1.4.3" G bundle(:update) end @@ -367,19 +374,19 @@ write_gemfile <<~G #{base_gemfile} - gem "rack", :git => "https://github.com/rack/rack" + gem "ansi", :git => "https://github.com/rubyworks/ansi" G end describe "#override_gem" do it "will remove the original git source" do write_bundler_d_file <<~F - override_gem "rack", "=2.0.6" + override_gem "ansi", "=1.4.3" F bundle(:update) - expect(lockfile_specs).to eq [["rack", "2.0.6"]] - expect(err).to match %r{^\*\* override_gem\("rack", "=2.0.6"\) at .+/bundler\.d/local_overrides\.rb:1$} + expect(lockfile_specs).to eq [["ansi", "1.4.3"]] + expect(err).to match %r{^\*\* override_gem\("ansi", "=1.4.3"\) at .+/bundler\.d/local_overrides\.rb:1$} expect(lockfile.sources.map(&:class)).to_not include(Bundler::Source::Git) end diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index c9ace81..4d7b4db 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -162,13 +162,5 @@ def write_global_bundler_d_file(content, filename = "global_overrides.rb") File.write(".bundler.d/#{filename}", content) end end - - def extract_rack_version(path = nil) - unless path - _, path, _, _ = raw_bundle("show rack") - path = Pathname.new(path.chomp) - end - path.expand_path.join("lib/rack/version.rb").read[/RELEASE += +([\"\'])([\d][\w\.]+)\1/, 2] - end end end