Module: PodBump
- Defined in:
- lib/pod-bump.rb,
lib/pod-bump/version.rb,
lib/pod-bump/version_model.rb,
lib/pod-bump/version_update_type.rb
Defined Under Namespace
Modules: VersionUpdateType
Classes: VersionModel
Constant Summary
collapse
- VERSION_REGEX =
%r{
(0|[1-9]\d*)
\.(0|[1-9]\d*)
\.(0|[1-9]\d*)
(?:\.(0|[1-9]\d*))? # is not valid sem versioning pattern to support 1.2.3.4
(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?
(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?
}x
- VERSION =
"0.0.2"
Class Method Summary
collapse
Class Method Details
.commit_git_repo(path_to_podspec, commit_message, version_to_commit) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/pod-bump.rb', line 25
def PodBump.commit_git_repo(path_to_podspec, commit_message, version_to_commit)
result = false
work_dir = "./"
git_current = Git.open(work_dir)
git_current.add(path_to_podspec)
result_commit_message = commit_message == nil ? "Bumped Version " + version_to_commit : commit_message
git_current.commit(result_commit_message)
puts "Commit: " + result_commit_message
git_current.add_tag(version_to_commit)
puts "Tag: " + version_to_commit
git_current.push("origin", git_current.current_branch, :tags=>true)
puts "Pushed to remote " + "origin " + git_current.current_branch
result = true
return result
end
|
.find_podspec_in_current_folder ⇒ Object
130
131
132
|
# File 'lib/pod-bump.rb', line 130
def PodBump.find_podspec_in_current_folder
return Dir["./*.podspec"].first
end
|
.find_podspec_name_in_current_folder ⇒ Object
134
135
136
137
|
# File 'lib/pod-bump.rb', line 134
def PodBump.find_podspec_name_in_current_folder
file = Dir["*.podspec"].first
return file
end
|
.get_version_from_podpsec(podspec_path) ⇒ Object
89
90
91
92
93
94
95
|
# File 'lib/pod-bump.rb', line 89
def PodBump.get_version_from_podpsec(podspec_path)
content = File.read(podspec_path)
version_line_part = content.match(/\.version\s*=\s*["']#{VERSION_REGEX}["']/).to_s
version = version_line_part.split(' ').last.tr('\'', '')
return version
end
|
.get_version_string_to_update(bump_type, options, version_string) ⇒ Object
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/pod-bump.rb', line 139
def PodBump.get_version_string_to_update(bump_type, options, version_string)
version = VersionModel.new(version_string)
version_to_update = nil
if bump_type == VersionUpdateType::MAJOR
version.increase_major()
version_to_update = version.to_string_version
elsif bump_type == VersionUpdateType::MINOR
version.increase_minor()
version_to_update = version.to_string_version
elsif bump_type == VersionUpdateType::PATCH
version.increase_patch()
version_to_update = version.to_string_version
elsif bump_type == VersionUpdateType::CURRENT
version_to_update = version_string
elsif options[:version] != nil
version_to_update = options[:version]
end
return version_to_update
end
|
.pull_git_repo ⇒ Object
18
19
20
21
22
23
|
# File 'lib/pod-bump.rb', line 18
def PodBump.pull_git_repo()
work_dir = "./"
git_current = Git.open(work_dir)
git_current.pull()
return true
end
|
.push_to_podspec(podspec_name, specs_repository) ⇒ Object
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
|
# File 'lib/pod-bump.rb', line 43
def PodBump.push_to_podspec(podspec_name, specs_repository)
result = false
if specs_repository != nil
specs_repository_name = Digest::SHA1.hexdigest(specs_repository)
puts "Specs repository name based on hash " + specs_repository_name
repository_exits = system("pod repo list | grep " + specs_repository_name)
puts "Repository already exists " + (repository_exits ? "YES" : "NO")
if repository_exits == false
command = "pod repo add " + specs_repository_name + " " + specs_repository
puts "Running " + command
result_of_repo_add = system(command)
if result_of_repo_add == false
puts "Could not add specs repository " + specs_repository
return result
end
end
command = "pod repo push " + specs_repository_name + " " + podspec_name
puts "Running " + command
result = system(command)
else
command = "pod trunk push " + podspec_name
puts "Running " + command
result = system("pod trunk push " + podspec_name)
end
if result == false
puts "Could not update podspec please do it manually after fixing errors"
end
return result
end
|
.run(arguments, options) ⇒ Object
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
# File 'lib/pod-bump.rb', line 161
def PodBump.run(arguments, options)
if options[:print_version] == true
puts "pod-bump version " + PodBump::VERSION
return
end
if arguments.size > 2 || (arguments.size == 2 && options[:version] == nil)
puts "Invalid parameters. Please check documentation"
return
end
bump_type = arguments.first
if options[:version] != nil && options[:version].match(VERSION_REGEX).to_s.empty?
puts "Version to set should use valid semantic versioning"
return
end
podspec_file_path = find_podspec_in_current_folder
if podspec_file_path == nil
puts "No podspec file found in current directory"
return
end
if options[:no_commit] == nil
pull_git_repo()
puts "Pulled git repository"
end
version = get_version_from_podpsec(podspec_file_path)
if version == nil
puts "Could not find version line in podspec " + podspec_file_path
return
end
version_to_update = get_version_string_to_update(bump_type, options, version)
if version_to_update == nil
puts "Invalid version to update passed to parameters. Please check documentation."
return
end
updated_podspec = update_version_in_podspec(podspec_file_path, version_to_update)
if updated_podspec == false
puts "Could not update version in podspec " + podspec_file_path
return
end
puts "Updated version in podspec " + podspec_file_path
if options[:no_commit] == true
return
end
commit_git_repo = commit_git_repo(podspec_file_path, options[:commit_message], version_to_update)
if commit_git_repo == false
puts "Could not commit to git repo"
return
end
podspec_name = find_podspec_name_in_current_folder()
puts "PODSPEC NAME " + podspec_name
pushed_to_podspec = push_to_podspec(podspec_name, options[:spec_repository])
if pushed_to_podspec == false
puts "Could not push to podspec repository"
return
end
puts "Successfully bumped version to " + version_to_update
end
|
.string_with_count(count, character) ⇒ Object
81
82
83
84
85
86
87
|
# File 'lib/pod-bump.rb', line 81
def PodBump.string_with_count(count, character)
result = ""
count.times do |count|
result += character
end
return result
end
|
.update_version_in_podspec(podpsec_path, version_string_to_update) ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/pod-bump.rb', line 97
def PodBump.update_version_in_podspec(podpsec_path, version_string_to_update)
lines = File.readlines(podpsec_path)
output_lines = []
version_pattern = ".version ="
updated = false
for line in lines
prefix_count_of_spaces = line.size - line.lstrip.size
version_line_part = line.match(/\.version\s*=\s*["']#{VERSION_REGEX}["']/).to_s
if version_line_part.empty? == false
items = line.split(' ')
previous_version_string = items[2]
version_to_update = "'" + version_string_to_update + "'"
updated_line = line.gsub(previous_version_string, version_to_update)
output_lines.push(updated_line)
updated = true
else
output_lines.push(line)
end
end
if updated == true
output_file = File.open(podpsec_path, "w")
for line in output_lines
output_file.puts line
end
output_file.close()
end
return updated
end
|