pod-bump 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4d73b515b211edb4de45ab6de4149e6979df7e7c
4
+ data.tar.gz: 15eb710f425f97f8c9315a232f51a0140cdc476a
5
+ SHA512:
6
+ metadata.gz: '09e92652d041c7cf521811fa5f4fce821a0defecc90835ebb0091aea6dbff5b6dcb02c7367443f694d32aff38c851713cdbf6ccedb47362b01a2e1004cfbe4db'
7
+ data.tar.gz: c6cf4035dfda965715098274c3115c1c61205e75ac2824fab14b5fc92131bc16b3d93789f2535d66752e564109acc85a9e6dcfa7955f65969d62f73d9d4f48ab
data/bin/pod-bump ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pod-bump'
4
+ require 'optparse'
5
+
6
+ options = {}
7
+ OptionParser.new do |opt|
8
+ opt.banner = <<-BANNER.gsub(/^ /, "")
9
+ Bump your podspec version and push it to specs repo.
10
+ Usage:
11
+ pod-bump patch [options] # increase patch version (1.0.X)
12
+ pod-bump minor [options] # increase minor version (1.X.0)
13
+ pod-bump major [options] # increase major version (X.0.0)
14
+ pod-bump current [options] # push without increasing version
15
+ pod-bump set (1.2.3) [options] # set the version number to the given value
16
+ Options:
17
+ BANNER
18
+ opt.on("-s", "--specs_repository [REPO]", "Specs repository to push. Default 'trunk'.") { |o| options[:spec_repository] = o }
19
+ opt.on("-m", "--message [MSG]", "Commit message. Default 'Bumped Version [Vesion]' ") { |o| options[:commit_message] = o }
20
+ opt.on("--no-commit", "Do not commit after version bump.") { options[:no_commit] = true }
21
+ end.parse!
22
+
23
+ options[:version] = ARGV[1] if ARGV[0] == "set"
24
+
25
+ status = PodBump.run(ARGV, options)
26
+ # puts "Exit status " + status
27
+ # exit status
@@ -0,0 +1,40 @@
1
+ module PodBump
2
+
3
+ class Version
4
+
5
+ def initialize(version_string)
6
+ versions = version_string.split(".")
7
+ @major = versions[0].to_i
8
+ @minor = versions[1].to_i
9
+ @patch = versions[2].to_i
10
+ end
11
+
12
+ def major
13
+ return @major
14
+ end
15
+
16
+ def minor
17
+ return @minor
18
+ end
19
+
20
+ def patch
21
+ return @patch
22
+ end
23
+
24
+ def increase_major
25
+ @major += 1
26
+ end
27
+
28
+ def increase_minor
29
+ @minor += 1
30
+ end
31
+
32
+ def increase_patch
33
+ @patch += 1
34
+ end
35
+
36
+ def to_string_version
37
+ @major.to_s + "." + @minor.to_s + "." + @patch.to_s
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,9 @@
1
+ module PodBump
2
+
3
+ module VersionUpdateType
4
+ MAJOR = "major"
5
+ MINOR = "minor"
6
+ PATCH = "patch"
7
+ CURRENT = "current"
8
+ end
9
+ end
data/lib/pod-bump.rb ADDED
@@ -0,0 +1,225 @@
1
+ require 'pod-bump/version'
2
+ require 'pod-bump/version_update_type'
3
+ require 'git'
4
+ require 'digest/sha1'
5
+
6
+ module PodBump
7
+
8
+ VERSION_REGEX = %r{
9
+ (0|[1-9]\d*)
10
+ \.(0|[1-9]\d*)
11
+ \.(0|[1-9]\d*)
12
+ (?:\.(0|[1-9]\d*))? # is not valid sem versioning pattern to support 1.2.3.4
13
+ (?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?
14
+ (?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?
15
+ }x
16
+
17
+ def PodBump.pull_git_repo()
18
+ work_dir = "./"
19
+ git_current = Git.open(work_dir)
20
+ git_current.pull()
21
+ return true
22
+ end
23
+
24
+ def PodBump.commit_git_repo(path_to_podspec, commit_message, version_to_commit)
25
+ result = false
26
+ work_dir = "./"
27
+
28
+ git_current = Git.open(work_dir)
29
+ git_current.add(path_to_podspec)
30
+ result_commit_message = commit_message == nil ? "Bumped Version " + version_to_commit : commit_message
31
+ git_current.commit(result_commit_message)
32
+ puts "Commit: " + result_commit_message
33
+ git_current.add_tag(version_to_commit)
34
+ puts "Tag: " + version_to_commit
35
+ git_current.push("origin", git_current.current_branch, :tags=>true)
36
+ puts "Pushed to remote " + "origin " + git_current.current_branch
37
+
38
+ result = true
39
+ return result
40
+ end
41
+
42
+ def PodBump.push_to_podspec(podspec_name, specs_repository)
43
+ result = false
44
+
45
+ if specs_repository != nil
46
+ specs_repository_name = Digest::SHA1.hexdigest(specs_repository)
47
+ puts "Specs repository name based on hash " + specs_repository_name
48
+
49
+ repository_exits = system("pod repo list | grep " + specs_repository_name)
50
+
51
+ puts "Repository already exists " + (repository_exits ? "YES" : "NO")
52
+
53
+ if repository_exits == false
54
+ command = "pod repo add " + specs_repository_name + " " + specs_repository
55
+ puts "Running " + command
56
+ result_of_repo_add = system(command)
57
+
58
+ if result_of_repo_add == false
59
+ puts "Could not add specs repository " + specs_repository
60
+ return result
61
+ end
62
+ end
63
+
64
+ command = "pod repo push " + specs_repository_name + " " + podspec_name
65
+ puts "Running " + command
66
+ result = system(command)
67
+ else
68
+ command = "pod trunk push " + podspec_name
69
+ puts "Running " + command
70
+ result = system("pod trunk push " + podspec_name)
71
+ end
72
+
73
+ if result == false
74
+ puts "Could not update podspec please do it manually after fixing errors"
75
+ end
76
+
77
+ return result
78
+ end
79
+
80
+ def PodBump.string_with_count(count, character)
81
+ result = ""
82
+ count.times do |count|
83
+ result += character
84
+ end
85
+ return result
86
+ end
87
+
88
+ def PodBump.get_version_from_podpsec(podspec_path)
89
+ content = File.read(podspec_path)
90
+ version_line_part = content.match(/\.version\s*=\s*["']#{VERSION_REGEX}["']/).to_s
91
+ version = version_line_part.split(' ').last.tr('\'', '')
92
+
93
+ return version
94
+ end
95
+
96
+ def PodBump.update_version_in_podspec(podpsec_path, version_string_to_update)
97
+ lines = File.readlines(podpsec_path)
98
+ output_lines = []
99
+ version_pattern = ".version ="
100
+ updated = false
101
+
102
+ for line in lines
103
+ prefix_count_of_spaces = line.size - line.lstrip.size
104
+ version_line_part = line.match(/\.version\s*=\s*["']#{VERSION_REGEX}["']/).to_s
105
+
106
+ if version_line_part.empty? == false
107
+ items = line.split(' ')
108
+ previous_version_string = items[2]
109
+ version_to_update = "'" + version_string_to_update + "'"
110
+ updated_line = line.gsub(previous_version_string, version_to_update)
111
+ output_lines.push(updated_line)
112
+ updated = true
113
+ else
114
+ output_lines.push(line)
115
+ end
116
+ end
117
+
118
+ if updated == true
119
+ output_file = File.open(podpsec_path, "w")
120
+ for line in output_lines
121
+ output_file.puts line
122
+ end
123
+ output_file.close()
124
+ end
125
+
126
+ return updated
127
+ end
128
+
129
+ def PodBump.find_podspec_in_current_folder
130
+ return Dir["./*.podspec"].first
131
+ end
132
+
133
+ def PodBump.find_podspec_name_in_current_folder
134
+ file = Dir["*.podspec"].first
135
+ return file
136
+ end
137
+
138
+ def PodBump.get_version_string_to_update(bump_type, options, version_string)
139
+ version = Version.new(version_string)
140
+ version_to_update = nil
141
+
142
+ if bump_type == VersionUpdateType::MAJOR
143
+ version.increase_major()
144
+ version_to_update = version.to_string_version
145
+ elsif bump_type == VersionUpdateType::MINOR
146
+ version.increase_minor()
147
+ version_to_update = version.to_string_version
148
+ elsif bump_type == VersionUpdateType::PATCH
149
+ version.increase_patch()
150
+ version_to_update = version.to_string_version
151
+ elsif bump_type == VersionUpdateType::CURRENT
152
+ version_to_update = version_string
153
+ elsif options[:version] != nil
154
+ version_to_update = options[:version]
155
+ end
156
+
157
+ return version_to_update
158
+ end
159
+
160
+ def PodBump.run(arguments, options)
161
+ if arguments.size > 2 || (arguments.size == 2 && options[:version] == nil)
162
+ puts "Invalid parameters. Please check documentation"
163
+ return
164
+ end
165
+
166
+ bump_type = arguments.first
167
+
168
+ if options[:version] != nil && options[:version].match(VERSION_REGEX).to_s.empty?
169
+ puts "Version to set should use valid semantic versioning"
170
+ return
171
+ end
172
+
173
+ podspec_file_path = find_podspec_in_current_folder
174
+ if podspec_file_path == nil
175
+ puts "No podspec file found in current directory"
176
+ return
177
+ end
178
+
179
+ if options[:no_commit] == nil
180
+ pull_git_repo()
181
+ puts "Pulled git repository"
182
+ end
183
+
184
+ version = get_version_from_podpsec(podspec_file_path)
185
+ if version == nil
186
+ puts "Could not find version line in podspec " + podspec_file_path
187
+ return
188
+ end
189
+
190
+ version_to_update = get_version_string_to_update(bump_type, options, version)
191
+ if version_to_update == nil
192
+ puts "Invalid version to update passed to parameters. Please check documentation."
193
+ return
194
+ end
195
+
196
+ updated_podspec = update_version_in_podspec(podspec_file_path, version_to_update)
197
+ if updated_podspec == false
198
+ puts "Could not update version in podspec " + podspec_file_path
199
+ return
200
+ end
201
+
202
+ puts "Updated version in podspec " + podspec_file_path
203
+
204
+ if options[:no_commit] == true
205
+ return
206
+ end
207
+
208
+ commit_git_repo = commit_git_repo(podspec_file_path, options[:commit_message], version_to_update)
209
+ if commit_git_repo == false
210
+ puts "Could not commit to git repo"
211
+ return
212
+ end
213
+
214
+ podspec_name = find_podspec_name_in_current_folder()
215
+ puts "PODSPEC NAME " + podspec_name
216
+ pushed_to_podspec = push_to_podspec(podspec_name, options[:spec_repository])
217
+
218
+ if pushed_to_podspec == false
219
+ puts "Could not push to podspec repository"
220
+ return
221
+ end
222
+
223
+ puts "Successfully bumped version to " + version_to_update
224
+ end
225
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pod-bump
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Maksim Kita
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-02-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: git
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.0
27
+ description: Pod Bump is command line tool that should be used to bump your podspec
28
+ version
29
+ email: kitaetoya@gmail.com
30
+ executables:
31
+ - pod-bump
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - bin/pod-bump
36
+ - lib/pod-bump.rb
37
+ - lib/pod-bump/version.rb
38
+ - lib/pod-bump/version_update_type.rb
39
+ homepage: https://github.com/kitaisreal/pod-bump
40
+ licenses:
41
+ - MIT
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.5.2.3
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Pod Bump
63
+ test_files: []