Skip to content

Commit

Permalink
Makes git-version-bump a development-only dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
mscottford committed Sep 5, 2023
1 parent 006c08f commit 22d341d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
.rspec_status

lib/corgibytes/freshli/commons/step_definitions/grpc/*.rb

lib/corgibytes/freshli/commons/version.rb
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ gem 'rspec', '~> 3.0'

gem 'rubocop', '~> 1.21'
gem 'rubocop-performance'
gem 'git-version-bump'

49 changes: 47 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'git-version-bump/rake-tasks'

require 'git-version-bump'

require 'fileutils'

Expand Down Expand Up @@ -71,7 +72,51 @@ require 'rubocop/rake_task'

RuboCop::RakeTask.new

namespace :version do
desc "Persist the the current version number as #{GVB.version}"
task :persist do
# open version file and replace contents of VERSION constant with the result of calling `GVB.version`
version_file = File.expand_path(File.join(File.dirname(__FILE__), 'lib', 'corgibytes', 'freshli', 'commons', 'version.rb'))
version_file_contents = File.read(version_file)
new_version_file_contents = version_file_contents.gsub(/VERSION = ".*"/, "VERSION = \"#{GVB.version}\"")
File.write(version_file, new_version_file_contents)
end
end

# Ensure that the grpc files are generated before the build runs
Rake::Task['build'].enhance(['grpc'])
Rake::Task['build'].enhance(['grpc', 'version:persist'])

task default: %i[grpc spec rubocop]

# Copied from https://github.com/mpalmer/git-version-bump/blob/c1af65cd82c131cb541fa717b3d24a9247973049/lib/git-version-bump/rake-tasks.rb
# to avoid an issue that was causing the version number of the `git-version-bump` gem to be used instead
# of this gem's version. That's because of how the `GVB.version` method determines the calling file.
namespace :version do
namespace :bump do
desc "bump major version (x.y.z -> x+1.0.0)"
task :major do
GVB.tag_version "#{GVB.major_version + 1}.0.0"

puts "Version is now #{GVB.version}"
end

desc "bump minor version (x.y.z -> x.y+1.0)"
task :minor do
GVB.tag_version "#{GVB.major_version}.#{GVB.minor_version+1}.0"

puts "Version is now #{GVB.version}"
end

desc "bump patch version (x.y.z -> x.y.z+1)"
task :patch do
GVB.tag_version "#{GVB.major_version}.#{GVB.minor_version}.#{GVB.patch_version+1}"

puts "Version is now #{GVB.version}"
end

desc "Print current version"
task :show do
puts GVB.version
end
end
end
7 changes: 3 additions & 4 deletions freshli-commons.gemspec
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# frozen_string_literal: true

require 'git-version-bump'
require_relative 'lib/corgibytes/freshli/commons/version'

Gem::Specification.new do |spec|
spec.name = 'freshli-commons'

spec.version = GVB.version
spec.date = GVB.date
spec.version = Corgibytes::Freshli::Commons::VERSION

spec.authors = ['M. Scott Ford']
spec.email = ['[email protected]']
Expand All @@ -27,6 +26,7 @@ Gem::Specification.new do |spec|
end
# include gRPC generated files in the gem
generated_files = Dir.glob('lib/corgibytes/freshli/commons/step_definitions/grpc/*.rb')
generated_files += ['lib/corgibytes/freshli/commons/version.rb']
git_files + generated_files
end
spec.bindir = 'exe'
Expand All @@ -40,7 +40,6 @@ Gem::Specification.new do |spec|
spec.add_dependency 'grpc-tools'
spec.add_dependency 'rspec-expectations'
spec.add_dependency 'sqlite3'
spec.add_dependency 'git-version-bump'

# For more information and examples about making a new gem, check out our
# guide at: https://bundler.io/guides/creating_gem.html
Expand Down
9 changes: 9 additions & 0 deletions lib/corgibytes/freshli/commons/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Corgibytes
module Freshli
module Commons
# The actual version number is generated by the git-version-bump gem
# before the gem is built.
VERSION = "0.0.0"
end
end
end

0 comments on commit 22d341d

Please sign in to comment.