forked from TimCinel/ActionSheetPicker
-
-
Notifications
You must be signed in to change notification settings - Fork 741
/
Copy pathbump.rb
executable file
·116 lines (95 loc) · 2.56 KB
/
bump.rb
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env ruby
require 'optparse'
@options = {:dry_run => false, :major => false, :minor => false, :revision => true}
OptionParser.new { |opts|
opts.banner = 'Usage: bump.rb [options]'
opts.on('-d', '--dry-run', 'Dry run') do |v|
@options[:dry_run] = v
end
opts.on('-a', '--major', 'Bump major version') do |v|
@options[:major] = v
end
opts.on('-m', '--minor', 'Bump minor version') do |v|
@options[:minor] = v
end
opts.on('-r', '--revision', 'Bump minor version') do |v|
@options[:revision] = v
end
}.parse!
p @options
def check_repo_is_clean_or_dry_run
value =%x[#{'git status --porcelain'}]
if value.empty?
puts 'Repo is clean -> continue'
else
if @options[:dry_run]
puts 'Repo not clean, "Dry run" enabled -> continue'
else
puts 'Repository not clean -> exit'
exit
end
end
end
def find_version_in_podspec
readme = File.read('ActionSheetPicker-3.0.podspec')
re = /(\d+)\.(\d+)\.(\d+)/m
match_result = re.match(readme)
unless match_result
puts 'Not found any versions'
exit
end
puts "Found version #{match_result[0]}"
return match_result[0], match_result.captures
end
def bump_version(result_array)
bumped_result = result_array.dup
bumped_result.map! { |x| x.to_i }
if @options[:major]
bumped_result[0] += 1
bumped_result[1] = 0
bumped_result[2] = 0
else
if @options[:minor]
bumped_result[1] += 1
bumped_result[2] = 0
else
if @options[:revision]
bumped_result[2] += 1
end
end
end
bumped_version = bumped_result.join('.')
puts "Bump version: #{result_array.join('.')} -> #{bumped_version}"
bumped_version
end
def execute_line(line)
if @options[:dry_run]
puts 'Dry run: ' + line
else
puts line
value = %x[#{line}]
puts value
if $?.exitstatus != 0
puts "Error (exit status = #{$?} -> exit"
exit
end
end
end
check_repo_is_clean_or_dry_run
result, result_array = find_version_in_podspec
bumped_version = bump_version(result_array)
unless @options[:dry_run]
puts 'Are you sure? Click Y to continue:'
str = gets.chomp
if str != 'Y'
puts '-> exit'
exit
end
end
execute_line("sed -i \"\" \"s/#{result}/#{bumped_version}/\" README.md")
execute_line("sed -i \"\" \"s/#{result}/#{bumped_version}/\" ActionSheetPicker-3.0.podspec")
execute_line("git commit --all -m \"Update podspec to version #{bumped_version}\"")
execute_line("git tag #{bumped_version}")
execute_line('git push')
execute_line('git push --tags')
execute_line('pod trunk push ./ActionSheetPicker-3.0.podspec')