Skip to content

Commit

Permalink
Add rake task to bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
otherguy committed Apr 23, 2024
1 parent f45ea8a commit 4246ed2
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 11 deletions.
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 13 additions & 5 deletions remove_bg.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ Gem::Specification.new do |spec|
spec.authors = ["Canva Austria GmbH"]
spec.email = ["[email protected]"]

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.
Expand Down Expand Up @@ -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"
Expand Down
39 changes: 37 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 17 additions & 4 deletions spec/support/simplecov.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
33 changes: 33 additions & 0 deletions tasks/version.rake
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4246ed2

Please sign in to comment.