-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
56 lines (46 loc) · 1.3 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true
ENV["RACK_ENV"] ||= "development"
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "rubocop/rake_task"
require "yard"
RSpec::Core::RakeTask.new(:spec)
RuboCop::RakeTask.new(:rubocop)
YARD::Rake::YardocTask.new
desc "allows running a demo controller"
task :demo do
system("rackup --host 0.0.0.0 -P #{File.expand_path(".")}/tmp/daemon.pid")
end
desc "automatically bump the gem's version"
task :bump, [:type] do |_t, args|
type = args[:type] || ENV["TYPE"] || "patch"
current_version = Metatron::VERSION
new_version = calculate_new_version(type)
puts "Bumping gem version from #{current_version} to #{new_version}"
update_version(new_version)
update_gem_lock
end
task default: %i[spec rubocop yard]
def calculate_new_version(type)
version = Metatron::VERSION.split(".").map(&:to_i)
case type
when "patch"
version[2] += 1
when "minor"
version[1] += 1
version[2] = 0
when "major"
version[0] += 1
version[1] = 0
version[2] = 0
end
version.join(".")
end
def update_gem_lock
system("bundle lock --update")
end
def update_version(new_version)
file = File.read("lib/metatron/version.rb")
new_contents = file.gsub(/VERSION = "(.+)"/, %(VERSION = "#{new_version}"))
File.write("lib/metatron/version.rb", new_contents)
end