48 lines
1.1 KiB
Ruby
Executable File
48 lines
1.1 KiB
Ruby
Executable File
#!/usr/bin/env ruby
|
|
require_relative '../lib/version.rb'
|
|
|
|
class BumpVersion
|
|
def initialize(*args)
|
|
@type = args[0]
|
|
if !valid_type?(@type)
|
|
puts "Invalid bump type: #{@type}"
|
|
exit 1
|
|
end
|
|
end
|
|
|
|
def valid_type?(type)
|
|
%w(major minor patch).include?(type)
|
|
end
|
|
|
|
def bump(current_version, type)
|
|
major, minor, patch = current_version.split('.').map(&:to_i)
|
|
if type == 'major'
|
|
major += 1
|
|
minor = 0
|
|
patch = 0
|
|
end
|
|
if type == 'minor'
|
|
minor += 1
|
|
patch = 0
|
|
end
|
|
patch += 1 if type == 'patch'
|
|
"#{major}.#{minor}.#{patch}"
|
|
end
|
|
|
|
def run
|
|
old_version = AlgoliaSearchJekyllVersion.to_s
|
|
new_version = bump(old_version, @type)
|
|
|
|
script_dir = File.expand_path(File.dirname(__FILE__))
|
|
file = File.join(script_dir, '../lib/version.rb')
|
|
old_content = File.read(file)
|
|
new_content = old_content.gsub(old_version, new_version)
|
|
File.write(file, new_content)
|
|
|
|
`git add #{file}`
|
|
`git commit -m "chore(bump): Version bump to #{new_version}"`
|
|
end
|
|
|
|
end
|
|
BumpVersion.new(*ARGV).run
|