forked from cookpad/aws-xray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bump
executable file
·36 lines (32 loc) · 922 Bytes
/
bump
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
#!/usr/bin/env ruby
level = ARGV.first
if level.nil?
warn "Example: #{__FILE__} (tiny|minor|major)"
exit 1
end
path = 'lib/aws/xray/version.rb'
regexp = /VERSION = '(.+)'.freeze$/
version = File.read(path).scan(regexp)[0][0]
version_strs = version.split('.')
if version_strs.size > 3
warn "Current version includes a prelease suffix, drop it: #{version}"
version_strs = version_strs[0..2]
end
case level
when 'tiny'
version_strs[2] = version_strs[2].to_i + 1
when 'minor'
version_strs[1] = version_strs[1].to_i + 1
version_strs[2] = 0
when 'major'
version_strs[0] = version_strs[0].to_i + 1
version_strs[1] = 0
version_strs[2] = 0
else
warn "Example: #{__FILE__} (tiny|minor|major)"
exit 1
end
next_version = version_strs.join('.')
File.write(path, File.read(path).gsub(regexp, "VERSION = '#{next_version}'.freeze"))
system('git', 'add', path)
system('git', 'commit', '-m', "v#{next_version}")