release-gem 0.1.2 → 0.1.4

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: b9ddcff2d96fbd26c5b35922f9b5b7e3f80b3f85ef7fd384218454f021ba0634
4
- data.tar.gz: cd3a8dc5754bbc3e31e6aba9e9cb78137e7e59d330aac18d773bb540f3874545
3
+ metadata.gz: 25dd9ae22ee2f6e81080fb7dfad95726cf299aa4c8e437ea49ccf015ba383566
4
+ data.tar.gz: f3f0f229c66f3eb7e3c9aa2cbf275a0cbaed4f55da0987c17bddcde48bfb8890
5
5
  SHA512:
6
- metadata.gz: d62bb46846ae308e74740a8f5197454ae77cdf46882afa053f7ca3dd8b750024b5373fd1f544dd716d34f20ad89caa4ec43cd948369185f64f8b6f77af9bc196
7
- data.tar.gz: c850c5f366feca6ab4f15e0f472498019005d826cb97b8ebba2d47605752c2c0c335eafc9f7f7f2b2c9716ee9e981670f4998caa181e674ee9c1e48e6218c420
6
+ metadata.gz: e892d6126c332f5266abaf1c3bb992c4cd4f9157eac46da023f4eff89b9a1217e69fed6656c24447fe903d707d2803c86241290b65f0aada86e06985faa8ee33
7
+ data.tar.gz: 2142260e3f9bc6af01c6bc6e3812b9258e8ec077dbb44d77f77243989b722ed9306fe8f6d2a467043d5681acf37fb193004b504815cef932552307e82cee3831
data/Gemfile CHANGED
@@ -9,6 +9,4 @@ gem "rake", "~> 13.0"
9
9
 
10
10
  gem "rspec", "~> 3.0"
11
11
 
12
- gem "gvcs", git: "gvcs", branch: "master"
13
- gem "git_cli", git: "git_cli", branch: "master"
14
12
 
data/Gemfile.lock CHANGED
@@ -1,26 +1,10 @@
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
1
  PATH
20
2
  remote: .
21
3
  specs:
22
- release-gem (0.1.2)
4
+ release-gem (0.1.4)
23
5
  colorize
6
+ git_cli
7
+ gvcs
24
8
  teLogger
25
9
  toolrack
26
10
  tty-command
@@ -31,6 +15,12 @@ GEM
31
15
  specs:
32
16
  colorize (0.8.1)
33
17
  diff-lcs (1.5.0)
18
+ git_cli (0.11.2)
19
+ gvcs
20
+ ptools (~> 1.4.0)
21
+ teLogger
22
+ toolrack
23
+ gvcs (0.1.1)
34
24
  pastel (0.8.0)
35
25
  tty-color (~> 0.5)
36
26
  ptools (1.4.3)
@@ -68,8 +58,6 @@ PLATFORMS
68
58
  x86_64-linux
69
59
 
70
60
  DEPENDENCIES
71
- git_cli!
72
- gvcs!
73
61
  rake (~> 13.0)
74
62
  release-gem!
75
63
  rspec (~> 3.0)
@@ -3,6 +3,7 @@
3
3
  require "bundler/gem_tasks"
4
4
  require "rspec/core/rake_task"
5
5
  require 'yaml'
6
+ require_relative 'gemdep'
6
7
 
7
8
  module Release
8
9
  module Gem
@@ -28,8 +29,48 @@ module Release
28
29
  instance_eval(&block) if block
29
30
  end
30
31
 
31
- def release_dependencies
32
- puts "gem release dependencies"
32
+ def release_dependencies(*args, &block)
33
+
34
+ if gemdepInst.has_development_gem?
35
+
36
+ if block
37
+
38
+ block.call(:action_start, :relase_dependencies)
39
+ keys = gemdepInst.development_gem.keys
40
+ loop do
41
+ begin
42
+ conf = block.call(:define_gem_prod_config, { gems: keys })
43
+ if conf.is_a?(Hash)
44
+ conf.each do |k,v|
45
+ gemdepInst.configure_gem(k,v)
46
+ end
47
+ break if gemdepInst.all_dev_gems_has_config?
48
+ keys = gemdepInst.not_configured_gem
49
+ else
50
+ block.call(:invalid_gem_prod_config, "Expected return from :define_gem_prod_config is a hash of \"gem name\" => { type: [:runtime | :dev], version: \">= 1.2.0\" }. Note version can be empty")
51
+ end
52
+ rescue GemDepError => ex
53
+ block.call(:invlid_gem_prod_config, ex.message)
54
+ end
55
+ end
56
+
57
+ gemdepInst.transfer_gem
58
+
59
+ block.call(:development_gem_temporary_promoted)
60
+ end
61
+
62
+ else
63
+ if block
64
+ block.call(:no_development_gems_found)
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+
71
+ def dependency_restore
72
+ puts "restoring dependency"
73
+ gemdepInst.restore_dev_gem
33
74
  end
34
75
 
35
76
  def build(*args, &block)
@@ -288,6 +329,13 @@ module Release
288
329
  end
289
330
  end
290
331
 
332
+ def gemdepInst
333
+ if @gemdepInst.nil?
334
+ @gemdepInst = GemDep.new(@root)
335
+ end
336
+ @gemdepInst
337
+ end
338
+
291
339
 
292
340
  end
293
341
  end
@@ -19,8 +19,53 @@ module Release
19
19
  end
20
20
 
21
21
  def release_dependencies
22
- puts "CLI release dependencies"
23
- @inst.release_dependencies
22
+ @inst.release_dependencies do |ops, *args|
23
+ case ops
24
+ when :action_start
25
+ @pmt.say "\n Release dependencies starting...\n".yellow
26
+
27
+ when :define_gem_prod_config
28
+
29
+ config = {}
30
+ selections = args.first[:gems]
31
+
32
+ loop do
33
+
34
+ sel = @pmt.select("\n The following development gems requires configuration. Please select one to configure ".yellow) do |m|
35
+ selections.each do |g|
36
+ m.choice g, g
37
+ end
38
+ end
39
+
40
+ config[sel] = {} if config[sel].nil?
41
+
42
+ type = @pmt.select("\n The gem in production will be runtime or development ? ".yellow) do |m|
43
+ m.choice "Runtime", :runtime
44
+ m.choice "Development only", :dev
45
+ end
46
+
47
+ config[sel][:type] = type
48
+
49
+ ver = @pmt.ask("\n Is there specific version pattern (including the ~>/>/>=/= of gemspec) for the gem in production? (Not mandatory) : ".yellow)
50
+ config[sel][:version] = ver if not_empty?(ver)
51
+
52
+ @pmt.puts " ** Done configure for gem #{sel}".yellow
53
+ selections.delete_if { |v| v == sel }
54
+ break if selections.length == 0
55
+
56
+ end
57
+
58
+ config
59
+
60
+ when :development_gem_temporary_promoted
61
+ @pmt.puts "\n Development gem(s) temporary promoted to production status".yellow
62
+
63
+ when :no_development_gems_found
64
+ @pmt.puts "\n No development gem(s) in used found".yellow
65
+
66
+ end
67
+ end
68
+
24
69
  end
25
70
 
26
71
  def build(*pargs, &block)
@@ -0,0 +1,171 @@
1
+
2
+ require 'bundler'
3
+
4
+ module Release
5
+ module Gem
6
+
7
+ class GemDepError < StandardError; end
8
+
9
+ class GemDep
10
+ include TR::CondUtils
11
+
12
+ def initialize(root, opts = { })
13
+ @root = root
14
+ @devGems = {}
15
+ @gemConfig = {}
16
+ @fileHistory = {}
17
+ load_gemfile_deps
18
+ load_gemspec_deps
19
+ end
20
+
21
+ def load_gemfile_deps
22
+ gdef = Bundler::Definition.build(gemfile_file, nil, {})
23
+ gdef.dependencies.each do |d|
24
+ if not d.source.nil? and d.source.path.to_s != "."
25
+ @devGems[d.name] = d.source.path.to_s
26
+ end
27
+ end
28
+ end
29
+
30
+ def load_gemspec_deps
31
+ gs = ::Gem::Specification.load(gemspec_file)
32
+ gs.dependencies.each do |d|
33
+ if not d.source.nil? and d.source.path.to_s != "."
34
+ @devGems[d.name] = d.source.path.to_s
35
+ end
36
+ end
37
+ end
38
+
39
+ def has_development_gem?
40
+ not_empty?(@devGems)
41
+ end
42
+
43
+ def development_gem
44
+ @devGems
45
+ end
46
+
47
+ def configure_gem(name, opts = { type: :runtime, version: "" })
48
+ raise GemDepError, "Given option to configure the gem is empty" if is_empty?(opts)
49
+ raise GemDepError, "Given option is not a hash. Hash wity keys :type and/or :version (can be empty) is expected" if not opts.is_a?(Hash)
50
+ raise GemDepError, "Production gem type not given. Please provide the gem type via key :type (valid value is either :runtime or :dev)" if is_empty?(opts[:type])
51
+
52
+ if @devGems.keys.include?(name.to_s)
53
+ @gemConfig[name.to_s] = opts
54
+ else
55
+ raise GemDepError, "Name '#{name}' is not in the list of development gems. Valid value including : #{@devGems.keys.join(", ")}"
56
+ end
57
+ end
58
+
59
+ def transfer_gem
60
+ if not all_dev_gems_has_config?
61
+ raise GemDepError, "Not all gem has configuration. Gem required configuration includes: #{not_configured_gem.join(", ")}"
62
+ end
63
+
64
+ remove_dev_gem_from_gemfile
65
+ add_gem_to_gemspec(@gemConfig)
66
+
67
+ end
68
+
69
+ def all_dev_gems_has_config?
70
+ not_configured_gem.length == 0
71
+ end
72
+
73
+ def not_configured_gem
74
+ @devGems.keys.difference(@gemConfig.keys)
75
+ end
76
+
77
+ def restore_dev_gem
78
+ @fileHistory.each do |k,v|
79
+ FileUtils.mv(k,"#{k}.prod")
80
+ FileUtils.cp(v,k)
81
+ end
82
+ @fileHistory.clear
83
+ end
84
+
85
+ private
86
+ def remove_dev_gem_from_gemfile
87
+ if has_development_gem?
88
+ orin = gemfile_file
89
+ dest = "#{gemfile_file}.dev"
90
+ FileUtils.cp(orin, dest)
91
+ @fileHistory[orin] = dest
92
+
93
+ tmpOut = "#{orin}.tmp"
94
+
95
+ File.open(tmpOut, "w") do |f|
96
+ cont = File.read(dest)
97
+ cont.each_line do |l|
98
+ next if l =~ /^gem ('|")(#{development_gem.keys.join("|")})('|")/
99
+ f.puts l
100
+ end
101
+ end
102
+
103
+ FileUtils.rm(orin)
104
+ FileUtils.mv(tmpOut, orin)
105
+
106
+ # to make sure has_development_gem? return false in subsequent run
107
+ load_gemfile_deps
108
+
109
+ end
110
+ end
111
+
112
+ def add_gem_to_gemspec(spec = {})
113
+
114
+ if has_development_gem?
115
+
116
+ orin = gemspec_file
117
+ dest = "#{gemspec_file}.dev"
118
+ FileUtils.cp(orin, dest)
119
+ @fileHistory[orin] = dest
120
+
121
+ tmpOut = "#{orin}.tmp"
122
+
123
+ cont = File.read(gemspec_file)
124
+ lastEnd = cont.rindex("end")
125
+
126
+ File.open(tmpOut, "w") do |f|
127
+ f.write cont[0...lastEnd]
128
+ spec.each do |k,v|
129
+ case v[:type]
130
+ when :runtime
131
+ f.puts " spec.add_dependency \"#{k}\"#{is_empty?(v[:version]) ? "" : ", \"#{v[:version]}\""}"
132
+ when :dev
133
+ f.puts " spec.add_development_dependency \"#{k}\"#{is_empty?(v[:version]) ? "" : ", \"#{v[:version]}\""}"
134
+ end
135
+ end
136
+
137
+ f.puts "end"
138
+ end
139
+
140
+ FileUtils.rm(orin)
141
+ FileUtils.mv(tmpOut, orin)
142
+
143
+ # to make sure has_development_gem? return false in subsequent run
144
+ load_gemspec_deps
145
+
146
+ end
147
+
148
+
149
+ end
150
+
151
+ def gemspec_file
152
+ if @_gemspec.nil?
153
+ @_gemspec = Dir.glob(File.join(@root,"*.gemspec"))
154
+ raise GemDepError, "Cannot find gemspec at '#{@root}'" if is_empty?(@_gemspec)
155
+ @_gemspec = @_gemspec.first
156
+ end
157
+ @_gemspec
158
+ end
159
+
160
+ def gemfile_file
161
+ if @_gemfile_file.nil?
162
+ @_gemfile_file = Dir.glob(File.join(@root,"Gemfile"))
163
+ raise GemDepError, "Cannot find Gemfile at '#{@root}'" if is_empty?(@_gemfile_file)
164
+ @_gemfile_file = @_gemfile_file.first
165
+ end
166
+ @_gemfile_file
167
+ end
168
+
169
+ end
170
+ end
171
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Release
4
4
  module Gem
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.4"
6
6
  end
7
7
  end
data/tasks/standard.rake CHANGED
@@ -38,6 +38,12 @@ namespace :gem do
38
38
  end
39
39
  end
40
40
 
41
+ #desc "Release test"
42
+ #task :test_release do
43
+ # stdFlow = File.join(File.dirname(__FILE__),"..","templates","standard_flow")
44
+ # require stdFlow
45
+ #end
46
+
41
47
  desc "Copy the standard flow to project local so modification of the flow is possible"
42
48
  task :customize_flow do
43
49
  stdFlow = File.join(File.dirname(__FILE__),"..","templates","standard_cli_flow.rb")
@@ -4,20 +4,22 @@ require 'release/gem'
4
4
 
5
5
  puts "\n Standard GEM CLI release flow version #{Release::Gem::VERSION}\n".yellow
6
6
 
7
- begin
8
-
9
- Release::Gem.engine(:gem, root: Dir.getwd) do
7
+ Release::Gem.engine(:gem, root: Dir.getwd) do
10
8
 
9
+ begin
11
10
  # step 1 : run test
12
11
  run_test(:rspec)
13
12
 
14
13
  gem_cli_action do
15
14
 
16
15
  # step 2 : check dependency
17
- release_dependencies
16
+ release_dependencies
18
17
 
19
18
  # step 3 : build the gem
20
19
  st, ver = build
20
+
21
+ dependency_restore
22
+
21
23
  if st
22
24
  # step 4, push the gem to rubygems
23
25
  push(version: ver)
@@ -26,6 +28,7 @@ begin
26
28
 
27
29
  end # gem_cli_action
28
30
 
31
+
29
32
  vcs_cli_action do
30
33
  @selVer = value(:selected_version)
31
34
 
@@ -39,17 +42,20 @@ begin
39
42
  push
40
43
 
41
44
  end # vcs_action block
45
+ rescue Release::Gem::Abort => ex
46
+ STDERR.puts "\n -- Aborted by user. Message was : #{ex.message}\n".red
47
+ rescue TTY::Reader::InputInterrupt => ex
48
+ rescue Exception => ex
49
+ STDERR.puts "\n -- Error thrown. Message was : #{ex.message}".red
50
+ STDERR.puts "\n#{ex.backtrace.join("\n")}" if ENV["RELGEM_DEBUG"] == true
51
+ ensure
52
+ gem_dependency_restore
53
+ end
42
54
 
43
- end # Release::Gem::Engine block
55
+ end # Release::Gem::Engine block
44
56
 
45
- puts "\n *** GEM standard release flow done!\n".green
57
+ puts "\n *** GEM CLI standard release flow done!\n".green
46
58
 
47
- rescue Release::Gem::Abort => ex
48
- STDERR.puts "\n -- Aborted by user. Message was : #{ex.message}\n".red
49
- rescue TTY::Reader::InputInterrupt => ex
50
- rescue Exception => ex
51
- STDERR.puts "\n -- Error thrown. Message was : #{ex.message}".red
52
- end
53
59
 
54
60
 
55
61
 
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'gem/release'
3
+ require 'release/gem'
4
4
 
5
5
  require 'tty/prompt'
6
6
 
@@ -8,17 +8,56 @@ pmt = TTY::Prompt.new
8
8
 
9
9
  pmt.puts "\n Standard GEM release flow version #{Release::Gem::VERSION}\n".yellow
10
10
 
11
- begin
12
11
 
13
- Release::Gem.engine(:gem, root: Dir.getwd, ui: STDOUT) do
12
+ Release::Gem.engine(:gem, root: Dir.getwd, ui: STDOUT) do
14
13
 
14
+ begin
15
15
  # step 1 : run test
16
16
  run_test(:rspec)
17
17
 
18
18
  gem_action do
19
19
 
20
20
  # step 2 : check dependency
21
- release_dependencies
21
+ release_dependencies do |ops, *args|
22
+ case ops
23
+ when :action_start
24
+ pmt.say "\n Release dependencies starting...\n".yellow
25
+
26
+ when :define_gem_prod_config
27
+
28
+ config = {}
29
+ selections = args.first[:gems]
30
+
31
+ loop do
32
+
33
+ sel = pmt.select("\n The following development gems requires configuration. Please select one to configure") do |m|
34
+ selections.each do |g|
35
+ m.choice g, g
36
+ end
37
+ end
38
+
39
+ config[sel] = {} if config[sel].nil?
40
+
41
+ type = pmt.select("\n The gem in production will be runtime or development ? ") do |m|
42
+ m.choice "Runtime", :runtime
43
+ m.choice "Development only", :dev
44
+ end
45
+
46
+ config[sel][:type] = type
47
+
48
+ ver = pmt.ask("\n Is there specific version pattern (including the ~>/>/>=/= of gemspec) for the gem in production? (Not mandatory) : ")
49
+ config[sel][:version] = ver if not_empty?(ver)
50
+
51
+ pmt.puts " ** Done configure for gem #{sel}"
52
+ selections.delete_if { |v| v == sel }
53
+ break if selections.length == 0
54
+
55
+ end
56
+
57
+ config
58
+
59
+ end
60
+ end
22
61
 
23
62
  # step 3 : build the gem
24
63
  st, ver = build do |ops, *args|
@@ -199,7 +238,7 @@ begin
199
238
  end
200
239
  end
201
240
 
202
-
241
+
203
242
  push do |ops, *args|
204
243
  case ops
205
244
  when :select_remote
@@ -244,17 +283,19 @@ begin
244
283
 
245
284
  end # vcs_action block
246
285
 
247
- end # Release::Gem::Engine block
248
-
249
- pmt.puts "\n *** GEM standard release flow done!\n".green
250
286
 
251
- rescue Release::Gem::Abort => ex
252
- pmt.puts "\n -- Aborted by user. Message was : #{ex.message}\n".red
253
- rescue TTY::Reader::InputInterrupt => ex
254
- rescue Exception => ex
255
- pmt.puts "\n -- Error thrown. Message was : #{ex.message}".red
287
+ rescue Release::Gem::Abort => ex
288
+ pmt.puts "\n -- Aborted by user. Message was : #{ex.message}\n".red
289
+ rescue TTY::Reader::InputInterrupt => ex
290
+ rescue Exception => ex
291
+ pmt.puts "\n -- Error thrown. Message was : #{ex.message}".red
292
+ pmt.puts ex.backtrace.join("\n")
293
+ ensure
294
+ gem_dependency_restore
295
+ end
256
296
  end
257
297
 
298
+ pmt.puts "\n *** GEM standard release flow done!\n".green
258
299
 
259
300
 
260
301
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: release-gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: gvcs
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: git_cli
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  description: ''
84
112
  email:
85
113
  - chris@antrapol.com
@@ -97,6 +125,7 @@ files:
97
125
  - lib/release/gem/gem_action.rb
98
126
  - lib/release/gem/gem_cli_action.rb
99
127
  - lib/release/gem/gem_engine.rb
128
+ - lib/release/gem/gemdep.rb
100
129
  - lib/release/gem/vcs_action.rb
101
130
  - lib/release/gem/vcs_cli_action.rb
102
131
  - lib/release/gem/version.rb