From 4246ed200dc93955208cd86ce18c302f0a52f1a0 Mon Sep 17 00:00:00 2001 From: Alexander Graf Date: Tue, 23 Apr 2024 13:26:40 +0200 Subject: [PATCH] Add rake task to bump version --- Gemfile.lock | 1 + Rakefile | 2 ++ remove_bg.gemspec | 18 +++++++++++++----- spec/spec_helper.rb | 39 +++++++++++++++++++++++++++++++++++++-- spec/support/simplecov.rb | 21 +++++++++++++++++---- tasks/version.rake | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 103 insertions(+), 11 deletions(-) create mode 100644 tasks/version.rake diff --git a/Gemfile.lock b/Gemfile.lock index 53afb07..8294d1e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -145,6 +145,7 @@ DEPENDENCIES rubocop-rspec (~> 2.29) simplecov (~> 0.22) simplecov-cobertura (~> 2.1) + simplecov_json_formatter (~> 0.1) vcr (~> 6.2) vcr_better_binary (~> 0.2) webmock (~> 3.23) diff --git a/Rakefile b/Rakefile index b6ae734..557724f 100644 --- a/Rakefile +++ b/Rakefile @@ -5,4 +5,6 @@ require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) +Dir.glob('tasks/*.rake').each {|r| import r} + task default: :spec diff --git a/remove_bg.gemspec b/remove_bg.gemspec index c3fc135..7dcb88f 100644 --- a/remove_bg.gemspec +++ b/remove_bg.gemspec @@ -10,14 +10,21 @@ Gem::Specification.new do |spec| spec.authors = ["Canva Austria GmbH"] spec.email = ["ops@kaleido.ai"] + spec.platform = Gem::Platform::RUBY + spec.summary = "Remove image background - 100% automatically" + spec.description = "Use remove.bg with our official Ruby library to quickly, easily and 100% automatically remove the background from images." spec.homepage = "https://www.remove.bg/" spec.license = "MIT" - spec.metadata["source_code_uri"] = "https://github.com/remove-bg/ruby" - spec.metadata["changelog_uri"] = "https://github.com/remove-bg/ruby/blob/main/CHANGELOG.md" - spec.metadata["rubygems_mfa_required"] = "true" - - # Require at least Ruby 2. + spec.metadata = { + "bug_tracker_uri" => "https://github.com/remove-bg/ruby/issues", + "source_code_uri" => "https://github.com/remove-bg/ruby", + "changelog_uri" => "https://github.com/remove-bg/ruby/blob/main/CHANGELOG.md", + "allowed_push_host" => "https://rubygems.org", + "rubygems_mfa_required" => "true", + } + + # Require at least Ruby 2.7 spec.required_ruby_version = ">= 2.7" # Specify which files should be added to the gem when it is released. @@ -48,6 +55,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency "rubocop-rspec", "~> 2.29" spec.add_development_dependency "simplecov", "~> 0.22" spec.add_development_dependency "simplecov-cobertura", "~> 2.1" + spec.add_development_dependency "simplecov_json_formatter", "~> 0.1" spec.add_development_dependency "vcr", "~> 6.2" spec.add_development_dependency "vcr_better_binary", "~> 0.2" spec.add_development_dependency "webmock", "~> 3.23" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7f6a9e4..06cbd87 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,18 +5,53 @@ require_relative "support/vcr" RSpec.configure do |config| + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. mocks.verify_partial_doubles = true end + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode config.disable_monkey_patching! + + # Turn Ruby warnings on config.warnings = true + + # Turns deprecation warnings into errors, in order to surface the full + # backtrace of the call site. This can be useful when you need more + # context to address a deprecation than the single-line call site + # normally provided. config.raise_errors_for_deprecations! - config.filter_run focus: true - config.run_all_when_everything_filtered = true + # This allows you to limit a spec run to individual examples or groups + # you care about by tagging them with `:focus` metadata. When nothing + # is tagged with `:focus`, all examples get run. RSpec also provides + # aliases for `it`, `describe`, and `context` that include `:focus` + # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + config.filter_run_when_matching :focus + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. Kernel.srand config.seed end diff --git a/spec/support/simplecov.rb b/spec/support/simplecov.rb index 01cc7c4..9de4c6c 100644 --- a/spec/support/simplecov.rb +++ b/spec/support/simplecov.rb @@ -2,9 +2,22 @@ require "simplecov" require "simplecov-cobertura" +require "simplecov_json_formatter" -SimpleCov.start do - add_filter "/spec/" -end +SimpleCov.formatters = [ + SimpleCov::Formatter::SimpleFormatter, + SimpleCov::Formatter::CoberturaFormatter, + SimpleCov::Formatter::HTMLFormatter, + SimpleCov::Formatter::JSONFormatter, +] + +SimpleCov.start "rails" do + # ignore common ruby and ruby on rails files in test coverage + add_filter "Gemfile" -SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([SimpleCov::Formatter::SimpleFormatter, SimpleCov::Formatter::CoberturaFormatter]) + # Ignore Rails binaries + add_filter "bin" + + # Ignore Specs/tests themselves + add_filter "spec" +end diff --git a/tasks/version.rake b/tasks/version.rake new file mode 100644 index 0000000..8aa48a8 --- /dev/null +++ b/tasks/version.rake @@ -0,0 +1,33 @@ +desc "Bump version of this gem" +task :version, [:version] do |_task, args| + args.with_defaults(version: nil) + + if args[:version].nil? + puts "Version: #{RemoveBg::VERSION}" + exit 0 + end + + unless args[:version].match(/(\d+)\.(\d+)\.(\d+)/) + puts "#{args[:version]} needs to be a major/minor/patch SemVer version number!" + exit 1 + end + + version_file_path = 'lib/remove_bg/version.rb' + version_pattern = /VERSION = "(.+)"/ + + # Read the current version from file + content = File.read(version_file_path) + current_version = content.match(version_pattern) + + unless current_version = content.match(version_pattern) + puts "Error in #{version_file_path} file! Cannot determine current version!" + exit 1 + end + + puts "Setting gem version to #{args[:version]}..." + new_content = content.sub(version_pattern, %Q{VERSION = "#{args[:version]}"}) + + File.open(version_file_path, 'w') { |file| file.puts new_content } + + puts "Version set to #{args[:version]}" +end