bumper_pusher 0.0.2

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: 19f26e4c08b54f7d96ef3e353f30c9df23cc4510
4
+ data.tar.gz: da73e8626640fae0fb38d221a1bbcaaefee72738
5
+ SHA512:
6
+ metadata.gz: adbc5354ee9482abadb418fd6907f37902132ab59f7ce21f87da2bf302c23320adb7444088bc6d23af183580c38fc40a0a3a7e1d71262403dfb747149eb844f1
7
+ data.tar.gz: c9ce5b25308a9ed173907e246a99cfeb48e08ed4da16fb03c2e067a31dac7b1a9226755e9b560a8e69dcfeff8af3d7e21593f0d233d5b0e86fdb0f77f3bf5763
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ a.podspec
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ # Specify your gem's dependencies in bumper_pusher.gemspec
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Petr Korolev
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # BumperPusher
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'bumper_pusher'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install bumper_pusher
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/skywinder/bumper_pusher/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/bumper_pusher ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bumper_pusher'
4
+
5
+ BumperPusher::Pusher.new
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'bumper_pusher/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "bumper_pusher"
9
+ spec.version = BumperPusher::VERSION
10
+ spec.authors = ["Petr Korolev"]
11
+ spec.email = ["sky4winder@gmail.com"]
12
+ spec.summary = %q{Easiest way to bump your specs}
13
+ spec.description = %q{Easiest way to bump your specs}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_runtime_dependency(%q<colorize>, ["~> 0.7"])
25
+ end
@@ -0,0 +1,273 @@
1
+ require 'colorize'
2
+
3
+ module BumperPusher
4
+
5
+ POD_SPEC_TYPE = 'podspec'
6
+ GEM_SPEC_TYPE = 'gemspec'
7
+
8
+ class Bumper
9
+
10
+ @spec_mode
11
+
12
+ def initialize(options)
13
+ @options = options
14
+ @spec_file = find_spec_file
15
+ end
16
+
17
+ def check_repo_is_clean_or_dry_run
18
+ value =%x[#{'git status --porcelain'}]
19
+
20
+ if value.empty?
21
+ puts 'Repo is clean -> continue'
22
+ else
23
+ if @options[:dry_run]
24
+ puts 'Repo not clean, "Dry run" enabled -> continue'
25
+ else
26
+ puts 'Repository not clean -> exit'
27
+ exit
28
+ end
29
+ end
30
+ end
31
+
32
+
33
+ def find_spec_file
34
+
35
+ pod_arr = execute_line("find . -name '*.#{POD_SPEC_TYPE}'").split("\n")
36
+ gem_arr = execute_line("find . -name '*.#{GEM_SPEC_TYPE}'").split("\n")
37
+ if gem_arr.any? && pod_arr.any?
38
+ puts 'Warning: both podspec and gemspec found!'.yellow
39
+ end
40
+ all_specs = gem_arr | pod_arr
41
+
42
+ spec_file = ''
43
+
44
+ case all_specs.count
45
+ when 0
46
+ puts 'No spec files found. -> Exit.'
47
+ exit
48
+ when 1
49
+ spec_file = all_specs[0]
50
+ else
51
+ puts 'Which spec should be used?'
52
+ all_specs.each_with_index { |file, index| puts "#{index+1}. #{file}" }
53
+ input_index = Integer(gets.chomp)
54
+ spec_file = all_specs[input_index-1]
55
+ end
56
+
57
+ if spec_file == nil
58
+ puts "Can't find specified spec file -> exit"
59
+ exit
60
+ end
61
+
62
+ if gem_arr.include?(spec_file)
63
+ @spec_mode = GEM_SPEC_TYPE
64
+ else
65
+ if pod_arr.include?(spec_file)
66
+ @spec_mode = POD_SPEC_TYPE
67
+ else
68
+
69
+ end
70
+
71
+ end
72
+
73
+ spec_file.sub('./', '')
74
+
75
+ end
76
+
77
+ def find_current_gem_file
78
+ list_of_specs = execute_line("find . -name '*.gem'")
79
+ arr = list_of_specs.split("\n")
80
+
81
+ spec_file = ''
82
+
83
+ case arr.count
84
+ when 0
85
+ puts "No #{POD_SPEC_TYPE} files found. -> Exit."
86
+ exit
87
+ when 1
88
+ spec_file = arr[0]
89
+ else
90
+ puts 'Which spec should be used?'
91
+ arr.each_with_index { |file, index| puts "#{index+1}. #{file}" }
92
+ input_index = Integer(gets.chomp)
93
+ spec_file = arr[input_index-1]
94
+ end
95
+
96
+ if spec_file == nil
97
+ puts "Can't find specified spec file -> exit"
98
+ exit
99
+ end
100
+
101
+ spec_file.sub('./', '')
102
+
103
+ end
104
+
105
+ def find_version_in_file(podspec)
106
+ readme = File.read(podspec)
107
+
108
+ #try to find version in format 1.22.333
109
+ re = /(\d+)\.(\d+)\.(\d+)/m
110
+
111
+ match_result = re.match(readme)
112
+
113
+ unless match_result
114
+ puts 'Not found any versions'
115
+ exit
116
+ end
117
+
118
+ puts "Found version #{match_result[0]}"
119
+ return match_result[0], match_result.captures
120
+ end
121
+
122
+ def bump_version(versions_array)
123
+ bumped_result = versions_array.dup
124
+ bumped_result.map! { |x| x.to_i }
125
+
126
+ case @options[:bump_number]
127
+ when :major
128
+ bumped_result[0] += 1
129
+ bumped_result[1] = 0
130
+ bumped_result[2] = 0
131
+ when :minor
132
+ bumped_result[1] += 1
133
+ bumped_result[2] = 0
134
+ when :patch
135
+ bumped_result[2] += 1
136
+ else
137
+ raise('unknown bump_number')
138
+ end
139
+
140
+
141
+ bumped_version = bumped_result.join('.')
142
+ if @options[:beta]
143
+ bumped_version += 'b'
144
+ end
145
+ puts "Bump version: #{versions_array.join('.')} -> #{bumped_version}"
146
+ bumped_version
147
+ end
148
+
149
+ def execute_line(line)
150
+ output = `#{line}`
151
+ check_exit_status(output)
152
+
153
+ output
154
+ end
155
+
156
+ def execute_line_if_not_dry_run(line)
157
+ if @options[:dry_run]
158
+ puts "Dry run: #{line}"
159
+ nil
160
+ else
161
+ puts line
162
+ value = %x[#{line}]
163
+ puts value
164
+ check_exit_status(value)
165
+ value
166
+ end
167
+ end
168
+
169
+ def check_exit_status(output)
170
+ if $?.exitstatus != 0
171
+ puts "Output:\n#{output}\nExit status = #{$?.exitstatus} ->Terminate script."
172
+ exit
173
+ end
174
+ end
175
+
176
+ def run_bumping_script
177
+
178
+ check_repo_is_clean_or_dry_run
179
+
180
+ version_file = find_version_file
181
+ result, versions_array = find_version_in_file(version_file)
182
+ bumped_version = bump_version(versions_array)
183
+
184
+ unless @options[:dry_run]
185
+ puts 'Are you sure? Press Y to continue:'
186
+ str = gets.chomp
187
+ if str != 'Y'
188
+ puts '-> exit'
189
+ exit
190
+ end
191
+ end
192
+
193
+ if @options[:bump]
194
+ execute_line_if_not_dry_run("sed -i \"\" \"s/#{result}/#{bumped_version}/\" README.md")
195
+ execute_line_if_not_dry_run("sed -i \"\" \"s/#{result}/#{bumped_version}/\" #{version_file}")
196
+ end
197
+
198
+ if @options[:commit]
199
+ execute_line_if_not_dry_run("git commit --all -m \"Update #{@spec_mode} to version #{bumped_version}\"")
200
+ execute_line_if_not_dry_run("git tag #{bumped_version}")
201
+ end
202
+
203
+ if @options[:push]
204
+ execute_line_if_not_dry_run('git push')
205
+ execute_line_if_not_dry_run('git push --tags')
206
+ end
207
+
208
+ if @options[:push]
209
+ if @spec_mode == POD_SPEC_TYPE
210
+ execute_line_if_not_dry_run("pod trunk push #{@spec_file}")
211
+ else
212
+ if @spec_mode == GEM_SPEC_TYPE
213
+ execute_line_if_not_dry_run("gem build #{@spec_file}")
214
+ gem = find_current_gem_file
215
+ execute_line_if_not_dry_run("gem push #{gem}")
216
+ else
217
+ raise 'Unknown spec type'
218
+ end
219
+ end
220
+ end
221
+
222
+ if @options[:beta]
223
+ if @spec_mode == GEM_SPEC_TYPE
224
+ execute_line_if_not_dry_run("gem build #{@spec_file}")
225
+ gem = find_current_gem_file
226
+ execute_line_if_not_dry_run("gem install #{gem}")
227
+ execute_line_if_not_dry_run("git checkout #{version_file}")
228
+ execute_line_if_not_dry_run('git checkout README.md')
229
+ else
230
+ raise 'Unknown spec type'
231
+ end
232
+ end
233
+
234
+
235
+ if @options[:changelog]
236
+ execute_line_if_not_dry_run("github_changelog_generator")
237
+ execute_line_if_not_dry_run("git commit CHANGELOG.md -m \"Update changelog for version #{bumped_version}\"")
238
+ execute_line_if_not_dry_run('git push')
239
+ end
240
+
241
+ end
242
+
243
+ def find_version_file
244
+ version_file = nil
245
+ arr = `find . -name 'version.rb'`.split("\n")
246
+ case arr.count
247
+ when 0
248
+ puts "version.rb file found (#{arr[0]}) -> bump this file"
249
+ when 1
250
+ version_file = arr[0]
251
+ else
252
+ puts 'More than 1 version.rb file found. -> skip'
253
+ end
254
+
255
+ version_file ? version_file.sub('./', '') : @spec_file
256
+ end
257
+
258
+ def revert_last_bump
259
+ spec_file = @spec_file
260
+ result, _ = find_version_in_file(spec_file)
261
+
262
+ puts "DELETE tag #{result} and HARD reset HEAD~1?\nPress Y to continue:"
263
+ str = gets.chomp
264
+ if str != 'Y'
265
+ puts '-> exit'
266
+ exit
267
+ end
268
+ execute_line_if_not_dry_run("git tag -d #{result}")
269
+ execute_line_if_not_dry_run('git reset --hard HEAD~1')
270
+ execute_line_if_not_dry_run("git push --delete origin #{result}")
271
+ end
272
+ end
273
+ end
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+
4
+ module BumperPusher
5
+
6
+ class Parser
7
+
8
+ def initialize
9
+
10
+ end
11
+
12
+ def parse_options
13
+ options = {:dry_run => false, :bump_number => :patch, :changelog => true, :bump => true, :commit => true, :build => true, :push => true}
14
+
15
+ OptionParser.new { |opts|
16
+ opts.banner = 'Usage: bump.rb [options]'
17
+
18
+ opts.on('-d', '--dry-run', 'Dry run') do |v|
19
+ options[:dry_run] = v
20
+ end
21
+ opts.on('-r', '--release', 'Bump release version') do |v|
22
+ options[:bump_number] = :major
23
+ end
24
+ opts.on('-m', '--minor', 'Bump minor version') do |v|
25
+ options[:bump_number] = :minor
26
+ end
27
+ opts.on('-p', '--patch', 'Bump patch version') do |v|
28
+ options[:bump_number] = :patch
29
+ end
30
+ opts.on('-r', '--revert', 'Revert last bump') do |v|
31
+ options[:revert] = v
32
+ end
33
+ opts.on('-b', '--beta', 'Build beta gem without commit and push') do |v|
34
+ options[:beta] = v
35
+ options[:bump] = v
36
+ options[:build] = v
37
+ options[:commit] = !v
38
+ options[:push] = !v
39
+
40
+ end
41
+ opts.on('-v', '--version', 'Print version number') do |v|
42
+ puts "Version: #{BumperPusher::VERSION}"
43
+ exit
44
+ end
45
+ opts.on('-c', '--[no]-changelog', 'Auto generation of changelog and pushing it origin. Default is true') do |v|
46
+ options[:changelog] = v
47
+ end
48
+ }.parse!
49
+ options
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module BumperPusher
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative 'bumper_pusher/version'
4
+ require_relative 'bumper_pusher/parser'
5
+ require_relative 'bumper_pusher/bumper'
6
+
7
+ module BumperPusher
8
+
9
+ class Pusher
10
+ attr_reader :options
11
+ def initialize
12
+ @options = BumperPusher::Parser.new.parse_options
13
+ @options.freeze
14
+
15
+ @parser = BumperPusher::Bumper.new(@options)
16
+
17
+ if @options[:revert]
18
+ @parser.revert_last_bump
19
+ else
20
+ @parser.run_bumping_script
21
+ end
22
+
23
+ end
24
+ end
25
+
26
+
27
+ end
28
+
29
+ if $0 == __FILE__
30
+ bumper = BumperPusher::Pusher.new
31
+
32
+
33
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bumper_pusher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Petr Korolev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.7'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.7'
55
+ description: Easiest way to bump your specs
56
+ email:
57
+ - sky4winder@gmail.com
58
+ executables:
59
+ - bumper_pusher
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/bumper_pusher
69
+ - bumper_pusher.gemspec
70
+ - lib/bumper_pusher.rb
71
+ - lib/bumper_pusher/bumper.rb
72
+ - lib/bumper_pusher/parser.rb
73
+ - lib/bumper_pusher/version.rb
74
+ homepage: ''
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.4.3
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Easiest way to bump your specs
98
+ test_files: []