release-gem 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4fef3151796135f044ca315573ebaf392f38200882c3ad7abba8d08245821b30
4
- data.tar.gz: '08bf56c3a6f9d9c459bf99234e208d5e0cafe557be73069508a5e4443b80837d'
3
+ metadata.gz: d7e0a394923bafd0342c5e97acb21832ed7ea58d72a2030b403d11dead5d9667
4
+ data.tar.gz: 504bf8e30c3bc4092664f5bab77bcf5fc5cb3b64efd696ce5c4abc77f7699ad3
5
5
  SHA512:
6
- metadata.gz: 57d2feefac0ebbd7c400ef3c4ebcba5a28afad387c9950a5ca5c3135a44b2c7416d24c1c4a47df50bb0ce516fd053c0c56a5d0789e36173da854f0cb4665ba2d
7
- data.tar.gz: 9ce0dfe5a9be331d2a2cebfb7e0048dbb924e88321af3e9064be638c6f470eb31c9565f976a695e0a3e790b7c3dbd7508c7ee32d088b0fc2af634dc9d113f5e4
6
+ metadata.gz: 1547583e15ddc80f3a34aee0e57e7972028980238d005c5535f0b47d835ee187841cc6373e046ec748fadfe334706d80483927c1354b8ea904a6ef417a6bbabd
7
+ data.tar.gz: 96dac3327d061f75db576fcf1ffcd743094f5e524f41afb69ea655c43f46bf8b21122326fc35dc91ebb0d2b78f2cf595de3d82677b6070a8e2330688b4977445
data/Gemfile.lock ADDED
@@ -0,0 +1,78 @@
1
+ GIT
2
+ remote: git_cli
3
+ revision: 05d83d28f37f4023920b6bf91d975b818d0f13fe
4
+ branch: master
5
+ specs:
6
+ git_cli (0.11.2)
7
+ gvcs
8
+ ptools (~> 1.4.0)
9
+ teLogger
10
+ toolrack
11
+
12
+ GIT
13
+ remote: gvcs
14
+ revision: 698970026596bdff48e475c92387287b5966dd1e
15
+ branch: master
16
+ specs:
17
+ gvcs (0.1.1)
18
+
19
+ PATH
20
+ remote: .
21
+ specs:
22
+ release-gem (0.1.1)
23
+ colorize
24
+ teLogger
25
+ toolrack
26
+ tty-command
27
+ tty-prompt
28
+
29
+ GEM
30
+ remote: https://rubygems.org/
31
+ specs:
32
+ colorize (0.8.1)
33
+ diff-lcs (1.5.0)
34
+ pastel (0.8.0)
35
+ tty-color (~> 0.5)
36
+ ptools (1.4.3)
37
+ rake (13.0.6)
38
+ rspec (3.12.0)
39
+ rspec-core (~> 3.12.0)
40
+ rspec-expectations (~> 3.12.0)
41
+ rspec-mocks (~> 3.12.0)
42
+ rspec-core (3.12.1)
43
+ rspec-support (~> 3.12.0)
44
+ rspec-expectations (3.12.2)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.12.0)
47
+ rspec-mocks (3.12.5)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.12.0)
50
+ rspec-support (3.12.0)
51
+ teLogger (0.2.2)
52
+ toolrack (0.21.0)
53
+ tty-color (0.6.0)
54
+ tty-command (0.10.1)
55
+ pastel (~> 0.8)
56
+ tty-cursor (0.7.1)
57
+ tty-prompt (0.23.1)
58
+ pastel (~> 0.8)
59
+ tty-reader (~> 0.8)
60
+ tty-reader (0.9.0)
61
+ tty-cursor (~> 0.7)
62
+ tty-screen (~> 0.8)
63
+ wisper (~> 2.0)
64
+ tty-screen (0.8.1)
65
+ wisper (2.0.1)
66
+
67
+ PLATFORMS
68
+ x86_64-linux
69
+
70
+ DEPENDENCIES
71
+ git_cli!
72
+ gvcs!
73
+ rake (~> 13.0)
74
+ release-gem!
75
+ rspec (~> 3.0)
76
+
77
+ BUNDLED WITH
78
+ 2.4.10
@@ -0,0 +1,5 @@
1
+
2
+ path = File.expand_path(File.dirname(__FILE__))
3
+ Dir.glob("#{path}/../../tasks/**/*.rake").each { |f|
4
+ import f
5
+ }
@@ -0,0 +1,295 @@
1
+
2
+ #require 'rake'
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require 'yaml'
6
+
7
+ module Release
8
+ module Gem
9
+ module Action
10
+
11
+ class GemActionError < StandardError; end
12
+
13
+ class GemAction
14
+ include TR::CondUtils
15
+ include TR::VUtils
16
+
17
+ attr_accessor :ui
18
+
19
+ def initialize(root, opts = { })
20
+ raise GemActionError, "root is not given" if is_empty?(root)
21
+ @root = root
22
+ oopts = opts || {}
23
+ @ui = oopts[:ui]
24
+ @engine = oopts[:engine]
25
+ end
26
+
27
+ def exec(&block)
28
+ instance_eval(&block) if block
29
+ end
30
+
31
+ def release_dependencies
32
+ puts "gem release dependencies"
33
+ end
34
+
35
+ def build(*args, &block)
36
+
37
+ block.call(:action_start, :build) if block
38
+ cp "Action 'build' starting at #{Gem.format_dt(Time.now)}"
39
+
40
+ verfile = find_version_file(&block)
41
+ curVer = find_gem_version(verfile)
42
+ possVer = possible_versions(curVer)
43
+
44
+ cp "Selection of version number. Current version : #{curVer}"
45
+ if block
46
+ @selVersion = block.call(:select_version, { current_version: curVer, proposed_next: possVer })
47
+
48
+ else
49
+ @selVersion = possVer[2] # increase last number
50
+ cp "System selected version '#{@selVersion}' since no block is given"
51
+ end
52
+
53
+ raise GemActionError, "Version number cannot be blank" if is_empty?(@selVersion)
54
+
55
+ cp "Given version number : #{@selVersion}. Updating gem version file"
56
+ update_gem_version(@selVersion) do |ops, *args|
57
+ if block
58
+ block.call(ops,*args)
59
+ else
60
+ # no block
61
+ case ops
62
+ when :multiple_version_files_found
63
+ sel = args.first.first
64
+ cp "System selected version file '#{sel}' since no block is given"
65
+ sel
66
+ end
67
+ end
68
+ end
69
+
70
+ cp "Gem version updated. Start building the gem"
71
+ begin
72
+ Rake::Task["build"].execute
73
+
74
+ if $?
75
+ cp "Gem build successfully at #{Gem.format_dt(Time.now)}"
76
+
77
+ if block
78
+ block.call(:gem_build_successfully, @selVersion)
79
+ else
80
+ [true, @selVersion]
81
+ end
82
+ else
83
+ cp "Gem build failed"
84
+ block.call(:gem_build_failed) if block
85
+ [false, ""]
86
+ end
87
+ rescue Exception => ex
88
+ cp "Gem build failed with message : #{ex.message}"
89
+ block.call(:gem_build_failed, ex) if block
90
+ end
91
+
92
+ end # build()
93
+
94
+ def push(*args, &block)
95
+
96
+ opts = args.first || {}
97
+
98
+ name = opts[:name]
99
+ name = gemspec.name if is_empty?(name)
100
+ version = opts[:version]
101
+ version = @selVersion if is_empty?(version)
102
+
103
+ raise GemActionError, "Version not given and no block" if not block and is_empty?(version)
104
+ if is_empty?(version) and block
105
+ version = block.call(:push_gem_version)
106
+ end
107
+
108
+ raise GemActionError, "No version given to push. Push aborted" if is_empty?(version)
109
+
110
+ cred = find_rubygems_api_key
111
+
112
+ selAcct = cred.keys.first
113
+ if cred.keys.length > 1
114
+ Gem.logger.debug "Multiple rubygems account detected."
115
+ # multiple account configured...
116
+ if block
117
+ selAcct = block.call(:multiple_rubygems_account, cred)
118
+ raise GemActionError, "No rubygems account is selected." if is_empty?(selAcct)
119
+ end
120
+ end
121
+
122
+
123
+ # find the package
124
+ foundGem = Dir.glob(File.join(@root,"**/#{name}-#{version}*.gem"))
125
+ if foundGem.length == 0
126
+ raise GemActionError, "No built gem with version '#{version}' found."
127
+ elsif foundGem.length > 1
128
+ if block
129
+ targetGem = block.call(:multiple_built_gems, foundGem)
130
+ else
131
+ raise GemActionError, "#{foundGem.length} versions of gem found. Please provide a block for selection"
132
+ end
133
+ else
134
+ targetGem = foundGem.first
135
+ end
136
+
137
+ cmd = "cd #{@root} && gem push #{targetGem} -k #{selAcct}"
138
+ Gem.logger.debug "Command to publish gem : #{cmd}"
139
+ res = `#{cmd} 2>&1`
140
+ block.call(:gem_push_output, $?, res) if block
141
+ [$?, res]
142
+
143
+ end
144
+
145
+ def install(*args, &block)
146
+ opts = args.first || {}
147
+ gemVer = ""
148
+ if is_empty?(opts)
149
+ if is_empty?(@selVersion)
150
+ raise GemActionError, "No version info is available and no block given" if not block
151
+ gemVer = block.call(:gem_version_to_install)
152
+ raise GemActionError, "No version info is available" if is_empty?(gemVer)
153
+ else
154
+ gemVer = @selVersion
155
+ end
156
+
157
+ else
158
+ gemVer = opts[:version]
159
+ end
160
+
161
+ cp "Given gem version '#{gemVer}' to install"
162
+ res = TTY::Command.new.run!("gem install pkg/#{gemspec.name}-#{gemVer}.gem") do |out, err|
163
+ cp out if not_empty?(out)
164
+ ce err if not_empty?(err)
165
+ end
166
+
167
+ end # install
168
+
169
+
170
+ def update_gem_version(newVersion, version_file = nil, &block)
171
+
172
+ raise GemActionError, "block is required" if not block
173
+
174
+ if is_empty?(version_file)
175
+ selVerFile = find_version_file(&block)
176
+ raise GemActionError, "Cannot find version file from #{@root}" if is_empty?(selVerFile)
177
+ else
178
+ selVerFile = version_file
179
+ end
180
+
181
+ tmpFile = File.join(File.dirname(selVerFile),"version-da.bak")
182
+ FileUtils.mv(selVerFile,tmpFile)
183
+
184
+ File.open(selVerFile,"w") do |f|
185
+ File.open(tmpFile,"r").each_line do |l|
186
+ if l =~ /VERSION/
187
+ indx = (l =~ /=/)
188
+ ll = "#{l[0..indx]} \"#{newVersion}\""
189
+ f.puts ll
190
+ else
191
+ f.write l
192
+ end
193
+ end
194
+ end
195
+
196
+ FileUtils.rm(tmpFile)
197
+
198
+ selVerFile
199
+
200
+ end # update_gem_version
201
+
202
+ # have to resort to manual way since the version file has
203
+ # frozen_string_literal which makes the Gem::Specification
204
+ # always keep the version that it is first loaded
205
+ def find_gem_version(file = nil, &block)
206
+
207
+ if is_empty?(file)
208
+ raise GemActionError, "Version file not given to extract version" if not block
209
+ file = find_version_file(&block)
210
+ end
211
+
212
+ version = nil
213
+ cont = File.read(file)
214
+ if cont =~ /VERSION/
215
+ val = $'
216
+ if not_empty?(val)
217
+ version = val.gsub("=","").gsub("\"","").gsub("end","").strip
218
+ end
219
+ end
220
+ version
221
+
222
+ end # find_gem_version
223
+
224
+
225
+ ###
226
+ # Private section
227
+ ###
228
+ private
229
+ def cp(msg)
230
+ Gem.cul(@ui, msg)
231
+ end
232
+ def ce(msg)
233
+ Gem.cue(@ui, msg)
234
+ end
235
+
236
+ def gemspec
237
+ if @_gemSpec.nil?
238
+ @_gemSpec = ::Gem::Specification.load(Dir.glob(File.join(@root,"*.gemspec")).first)
239
+ end
240
+ @_gemSpec
241
+ end # gemspec
242
+
243
+ def find_version_file(&block)
244
+
245
+ version_file = Dir.glob(File.join(@root,"**/version.rb"))
246
+
247
+ selVerFile = version_file.first
248
+ if version_file.length > 1
249
+ if block
250
+ selVerFile = block.call(:multiple_version_files_found, version_file)
251
+ block.call(:abort) if is_empty?(selVerFile)
252
+ else
253
+ selVerFile = version_file.first
254
+ cp("Multiple version files detected but no block. Using first version file found : '#{selVerFile}'")
255
+ end
256
+ end
257
+
258
+ selVerFile
259
+
260
+ end # find_version_file
261
+
262
+
263
+ def find_rubygems_api_key
264
+ if TR::RTUtils.on_windows?
265
+ credFile = File.join(ENV['USERPROFILE'],".gem","credentials")
266
+ else
267
+ credFile = File.join(Dir.home,".local","share","gem","credentials")
268
+ end
269
+
270
+ raise GemActionError, "Credential file not found at '#{credFile}'" if not File.exist?(credFile)
271
+
272
+ cred = nil
273
+ File.open(credFile,"r") do |f|
274
+ cred = YAML.load(f.read)
275
+ end
276
+
277
+ raise GemActionError, "Credential file is empty" if is_empty?(cred)
278
+ raise GemActionError, "No credential created yet for rubygems." if is_empty?(cred.keys)
279
+
280
+ cred
281
+ end
282
+
283
+ def method_missing(mtd, *args, &block)
284
+ if not @engine.nil? and @engine.respond_to?(mtd)
285
+ @engine.send(mtd, *args, &block)
286
+ else
287
+ super
288
+ end
289
+ end
290
+
291
+
292
+ end
293
+ end
294
+ end
295
+ end
@@ -0,0 +1,157 @@
1
+
2
+ require 'tty/prompt'
3
+ require_relative 'gem_action'
4
+
5
+ module Release
6
+ module Gem
7
+ module Cli
8
+ class GemAction
9
+
10
+ def initialize(root, opts = {})
11
+ opts = { } if opts.nil?
12
+ opts[:ui] = TTY::Prompt.new
13
+ @inst = Action::GemAction.new(root, opts)
14
+ @pmt = opts[:tty] || opts[:ui]
15
+ end
16
+
17
+ def exec(&block)
18
+ instance_eval(&block) if block
19
+ end
20
+
21
+ def release_dependencies
22
+ puts "CLI release dependencies"
23
+ @inst.release_dependencies
24
+ end
25
+
26
+ def build(*pargs, &block)
27
+
28
+ @inst.build do |ops, *args|
29
+ case ops
30
+ when :action_start
31
+ @pmt.say " Gem building starting...\n".yellow
32
+ when :select_version
33
+ preset = false
34
+ if block
35
+ res = block.call(ops, *args)
36
+ if res.nil?
37
+ preset = true
38
+ else
39
+ res
40
+ end
41
+ else
42
+ preset = true
43
+ end
44
+
45
+ if preset
46
+
47
+ opts = args.first
48
+ res = @pmt.select("\n Please select new gem version : \n".yellow) do |m|
49
+ opts[:proposed_next].reverse.each do |v|
50
+ m.choice v,v
51
+ end
52
+ m.choice "#{opts[:current_version]} -> Current version ", opts[:current_version]
53
+ m.choice "Custom version", :custom
54
+ m.choice "Abort", :abort
55
+ end
56
+
57
+ raise Release::Gem::Abort, "Abort by user" if res == :abort
58
+
59
+ if res == :custom
60
+ loop do
61
+ res = @pmt.ask("\n Please provide custom version number for the release : ".yellow,required: true)
62
+ confirmed = @pmt.yes?("\n Use version '#{res}'? No to try again")
63
+ break if confirmed
64
+ end
65
+ end
66
+
67
+ end # if preset
68
+
69
+ res
70
+
71
+ when :multiple_version_files_found
72
+ preset = false
73
+ if block
74
+ res = block.call(ops, *args)
75
+ if res.nil?
76
+ preset = true
77
+ else
78
+ res
79
+ end
80
+ else
81
+ preset = true
82
+ end
83
+
84
+ if preset
85
+
86
+ res = @pmt.select("\n There are multiple version file found. Please select which one to update : ".yellow) do |m|
87
+ opts = args.first
88
+ opts.each do |f|
89
+ m.choice f,f
90
+ end
91
+ m.choice "Abort", :abort
92
+ end
93
+
94
+ raise Release::Gem::Abort, "Abort by user" if res == :abort
95
+ end
96
+
97
+ res
98
+ when :new_version_number
99
+ @selVersion = args.first
100
+
101
+ when :gem_build_successfully
102
+ @pmt.puts "\n Gem version '#{args.first}' built successfully".green
103
+ @inst.register(:selected_version, args.first)
104
+ [true, args.first]
105
+ end
106
+ end
107
+
108
+
109
+ end # build
110
+
111
+ def push(*pargs, &block)
112
+ @inst.push(*pargs) do |ops, *args|
113
+ case ops
114
+ when :multiple_rubygems_account
115
+ creds = args.first
116
+ res = @pmt.select("\n Multiple rubygems account detected. Please select one : ".yellow) do |m|
117
+ creds.each do |k,v|
118
+ m.choice k,k
119
+ end
120
+ m.choice "Skip gem push", :skip
121
+ m.choice "Abort", :abort
122
+ end
123
+
124
+ raise Release::Gem::Abort, "Abort by user" if res == :abort
125
+ res
126
+
127
+ when :gem_push_output
128
+ st = pargs.first
129
+ res = pargs[1]
130
+ if st
131
+ @pmt.puts "\n Gem push successful.".green
132
+ else
133
+ @pmt.puts "\n Gem push failed. Error was :\n #{res}".red
134
+ end
135
+ end
136
+ end
137
+
138
+ end # push
139
+
140
+ def install(*args, &block)
141
+
142
+ sysInst = @pmt.yes?("\n Install release into system? ".yellow)
143
+ if sysInst
144
+ @inst.install(*args)
145
+ end
146
+
147
+ end # install
148
+
149
+ def method_missing(mtd, *args, &block)
150
+ @inst.send(mtd,*args, &block)
151
+ end
152
+
153
+ end
154
+ end
155
+ end
156
+ end
157
+
@@ -0,0 +1,113 @@
1
+
2
+ require_relative 'vcs_action'
3
+ require_relative 'gem_action'
4
+
5
+ require_relative 'vcs_cli_action'
6
+ require_relative 'gem_cli_action'
7
+
8
+ module Release
9
+ module Gem
10
+ module Engine
11
+ class GemEngine
12
+ include TR::CondUtils
13
+
14
+ def initialize(*args, &block)
15
+ opts = args.first
16
+ @root = opts[:root]
17
+ @ui = opts[:ui]
18
+ @var = {}
19
+
20
+ exec(&block)
21
+ end
22
+
23
+ def exec(&block)
24
+ instance_eval(&block) if block
25
+ end
26
+
27
+ def run_test(eng)
28
+ puts "run test : #{eng}"
29
+ end
30
+
31
+ def register(key,value)
32
+ @var[key] = value if not_empty?(key)
33
+ end
34
+
35
+ def value(key)
36
+ @var[key]
37
+ end
38
+
39
+ def gem_action(&block)
40
+ gem_action_inst.exec(&block)
41
+ end
42
+
43
+ def gem_cli_action(&block)
44
+ gem_cli_action_inst.exec(&block)
45
+ end
46
+
47
+ def vcs_action(&block)
48
+ vcs_action_inst.exec(&block)
49
+ end
50
+
51
+ def vcs_cli_action(&block)
52
+ vcs_cli_action_inst.exec(&block)
53
+ end
54
+
55
+ def method_missing(mtd, *args, &block)
56
+ if mtd.to_s.start_with?("gem_cli")
57
+ Gem.logger.debug "Passing method '#{mtd}' to gem_cli action"
58
+ pmtd = mtd.to_s[7..-1].to_sym
59
+ gem_cli_action_inst.send(pmtd, *args, &block)
60
+
61
+ elsif mtd.to_s.start_with?("vcs_cli")
62
+ Gem.logger.debug "Passing method '#{mtd}' to vcs_cli action"
63
+ pmtd = mtd.to_s[7..-1].to_sym
64
+ vcs_cli_action_inst.send(pmtd, *args, &block)
65
+
66
+ elsif mtd.to_s.start_with?("gem_")
67
+ Gem.logger.debug "Passing method '#{mtd}' to gem action"
68
+ pmtd = mtd.to_s[4..-1].to_sym
69
+ gem_action_inst.send(pmtd, *args, &block)
70
+
71
+ elsif mtd.to_s.start_with?("vcs_")
72
+ pmtd = mtd.to_s[4..-1].to_sym
73
+ vcs_action_inst.send(pmtd, *args, &block)
74
+
75
+ else
76
+ super
77
+ end
78
+ end
79
+
80
+ def vcs_action_inst
81
+ if @vcsAct.nil?
82
+ @vcsAct = Action::VcsAction.new(@root,{ ui: @ui, engine: self })
83
+ end
84
+ @vcsAct
85
+ end
86
+
87
+ def gem_action_inst
88
+ if @gemAct.nil?
89
+ @gemAct = Action::GemAction.new(@root, { ui: @ui, engine: self})
90
+ end
91
+ @gemAct
92
+ end
93
+
94
+ def vcs_cli_action_inst
95
+ if @vcsCliAct.nil?
96
+ @vcsCliAct = Cli::VcsAction.new(@root,{ engine: self })
97
+ end
98
+ @vcsCliAct
99
+ end
100
+
101
+ def gem_cli_action_inst
102
+ if @gemCliAct.nil?
103
+ @gemCliAct = Cli::GemAction.new(@root, { engine: self})
104
+ end
105
+ @gemCliAct
106
+ end
107
+
108
+
109
+ end
110
+ end
111
+ end
112
+ end
113
+