release-gem 0.1.5 → 0.1.6

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: 4a3f43d3c0b887a2346a0ee9b126a6f7a2edd0715f77b910762caeec3056bd76
4
- data.tar.gz: 937d525b33b1695c16ddd1ff3edd77a554ea8be086832cc1052d27e468d4b7a0
3
+ metadata.gz: b5f829021df7a73c3e93c06b2e4d788f103a1f0ac096d3c472a7b4cfd575122c
4
+ data.tar.gz: 7c4a3acaa233d7bcff3a1ef308dbdfe3ea7b669f3418d3205072b6b2c5b9ada2
5
5
  SHA512:
6
- metadata.gz: ca0da466583bf5191772d82a08507acaca1db045a6e93c6dc9573ed5a445f58a31570328f73a0f1840fcc328bfadf92fc40b03696a46086628ebfe1a99d828ea
7
- data.tar.gz: b2a5f5d9ec4d3bda1fb86bed8b001b85ca7b1e12fefe585dba8297dcda51cd76f7b9acccddd63192c6119bb0237ba671dd0cb7662847c9d7cf9960f0e0b74b91
6
+ metadata.gz: e8cc062083ef870fd5ef74eff9b9d8b05072b2348096d10fddab73c8d1ad2cf3ad81ce52dcf5c5447787103429e6c14f970189729a3873293358a432bf83aeb8
7
+ data.tar.gz: 9ae8f560785f812de5578155547df4ab94deefafa4e741fb2d6b23af13f063c672ae93a75cbce10abc5067d5be7abf640d4aa46f359808ab26f9d66c5327049e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- release-gem (0.1.5)
4
+ release-gem (0.1.6)
5
5
  colorize
6
6
  git_cli
7
7
  gvcs
@@ -329,7 +329,7 @@ module Release
329
329
  end
330
330
 
331
331
  def method_missing(mtd, *args, &block)
332
- if not @engine.nil? and @engine.respond_to?(mtd)
332
+ if not @engine.nil?
333
333
  @engine.send(mtd, *args, &block)
334
334
  else
335
335
  super
@@ -0,0 +1,179 @@
1
+
2
+
3
+ module Release
4
+ module Gem
5
+
6
+ class ReleaseInfectorError < StandardError; end
7
+
8
+ #
9
+ # Setup the release-gem into other gem project automatically!
10
+ #
11
+ class ReleaseInfector
12
+ include TR::CondUtils
13
+ include TR::TerminalUtils
14
+
15
+ def initialize(root, name)
16
+ @root = root
17
+ @name = name
18
+ @backupFiles = {}
19
+ end
20
+
21
+ def infect(&block)
22
+ if not is_release_gem_installed?
23
+ add_to_gemspec(&block)
24
+ Bundler.with_clean_env do
25
+ res = `cd #{@root} && bundle`
26
+ end
27
+ end
28
+
29
+ if not is_rakefile_activated?
30
+ activate_rakefile(&block)
31
+ end
32
+ end
33
+
34
+ def trigger_release_gem(&block)
35
+
36
+ block.call(:triggering_release_gem) if block
37
+
38
+ poss = tu_possible_terminal
39
+ raise ReleaseInfectorError, "No possible terminal found" if is_empty?(poss)
40
+
41
+ Bundler.with_clean_env do
42
+
43
+ cmd = "cd #{@root} && rake gem:release"
44
+ terminal = ""
45
+ if block
46
+ terminal = block.call(:select_terminal, name: @name, options: poss)
47
+ terminal = poss.first if is_empty?(terminal)
48
+
49
+ block.call(:new_terminal_launching, name: @name, terminal: terminal)
50
+ tu_new_terminal(terminal, cmd)
51
+ else
52
+ terminal = poss.first
53
+ block.call(:new_terminal_launching, name: @name, terminal: terminal)
54
+ tu_new_terminal(terminal, cmd)
55
+ end
56
+
57
+ block.call(:new_terminal_launched, name: @name, terminal: terminal) if block
58
+
59
+ end
60
+
61
+ end
62
+
63
+ def is_release_gem_installed?
64
+ #Bundler.with_clean_env do
65
+ Bundler.with_unbundled_env do
66
+
67
+ res = `cd #{@root} && bundle 2>&1`
68
+
69
+ puts res
70
+
71
+ if $?.success?
72
+ found = false
73
+ res.each_line do |l|
74
+ if l =~ / release-gem /
75
+ found = true
76
+ break
77
+ end
78
+ end
79
+
80
+ found
81
+ else
82
+ raise ReleaseInfectorError, "Error running bundle in '#{@root}'. Error was :\n#{res}"
83
+ end
84
+
85
+ end
86
+ end # is_release_gem_installed?
87
+
88
+ def add_to_gemspec(&block)
89
+
90
+
91
+ gs = Dir.glob(File.join(@root,"*.gemspec"))
92
+ raise ReleaseInfectorError, "gemspec not found at '#{@root}'" if is_empty?(gs)
93
+
94
+ block.call(:adding_to_gemspec, gemspec: gs) if block
95
+
96
+ if gs.length > 1
97
+ if block
98
+ gs = block.call(:multiple_gemspecs, gs)
99
+ else
100
+ raise ReleaseInfectorError, "There are more than 1 gemspec file found (#{gs.length} found). Since no block to filter out the required one, this will be an error condition"
101
+ end
102
+
103
+ else
104
+ gs = gs.first
105
+ end
106
+
107
+ cont = File.read(gs)
108
+ lastEnd = cont.rindex("end")
109
+
110
+ FileUtils.mv(gs, "#{gs}.bak")
111
+ @backupFiles[gs] = "#{gs}.bak"
112
+
113
+ File.open(gs, "w") do |f|
114
+ f.write cont[0...lastEnd]
115
+ f.puts " spec.add_development_dependency 'release-gem'"
116
+ f.puts "end"
117
+ end
118
+ block.call(:gemspec_updated, name: @name, gemspec: gs )
119
+
120
+ end # add_to_gemspec
121
+
122
+ def activate_rakefile(&block)
123
+
124
+ rf = File.join(@root,"Rakefile")
125
+ if not File.exist?(rf)
126
+ rfCont <<-END
127
+ # frozen_string_literal: true
128
+
129
+ require "bundler/gem_tasks"
130
+ require "rspec/core/rake_task"
131
+
132
+ require "release/gem"
133
+
134
+ RSpec::Core::RakeTask.new(:spec)
135
+
136
+ task default: :spec
137
+ END
138
+ block.call(:creating_new_rakefile, rakefile: rf )
139
+ File.open(rf,"w") do |f|
140
+ f.write rfCont
141
+ end
142
+ else
143
+
144
+ block.call(:adding_to_rakefile, rakefile: rf )
145
+
146
+ cont = File.read(rf)
147
+ FileUtils.mv(rf, "#{rf}.bak")
148
+ @backupFiles[rf] = "#{rf}.bak"
149
+
150
+ File.open(rf,"w") do |f|
151
+ f.puts cont
152
+ f.puts "require 'release/gem'"
153
+ end
154
+
155
+ block.call(:rakefile_updated, name: @name, rakefile: rf) if block
156
+
157
+ end
158
+ end
159
+
160
+ def is_rakefile_activated?
161
+ rf = File.join(@root,"Rakefile")
162
+ if not File.exist?(rf)
163
+ false
164
+ else
165
+ cont = File.read(rf)
166
+ found = false
167
+ cont.each_line do |l|
168
+ if l =~ /require ('|")(release\/gem)("|')/
169
+ found = true
170
+ break
171
+ end
172
+ end
173
+ found
174
+ end
175
+ end
176
+
177
+ end
178
+ end
179
+ end
@@ -42,6 +42,72 @@ module Release
42
42
  instance_eval(&block) if block
43
43
  end
44
44
 
45
+ #
46
+ # Special operation since the gem build will only include files from
47
+ # git ls-files
48
+ #
49
+ def commit_new_files(msg = nil, &block)
50
+
51
+ res = :value
52
+ if block
53
+
54
+ loop do
55
+
56
+ stgDir, stgFiles = @ws.staged_files
57
+ newDir, newFiles = @ws.new_files
58
+
59
+ if is_empty?(newFiles)
60
+ res = :skip
61
+ break
62
+ end
63
+
64
+ newFiles.delete_if { |f| stgFiles.include?(f) }
65
+ newDir.delete_if { |f| stgDir.include?(f) }
66
+
67
+ res = block.call(:select_files_to_commit, { new: { files: newFiles, dirs: newDir }, staged: { files: stgFiles, dirs: stgDir }, vcs: self } )
68
+
69
+ break if res == :skip or res == :done
70
+
71
+ end
72
+
73
+ if res == :done
74
+
75
+ stgDir, stgFiles = @ws.staged_files
76
+ block.call(:staged_elements_of_commit, { files: stgFiles, dirs: stgDir })
77
+
78
+ msg = block.call(:commit_message) if is_empty?(msg)
79
+ raise VcsActionError, "Commit message is empty" if is_empty?(msg)
80
+
81
+ cp "Commit with user message : #{msg}"
82
+ st, res = @ws.commit(msg)
83
+ if st
84
+ block.call(:commit_successful, res) if block
85
+ else
86
+ block.call(:commit_failed, res) if block
87
+ end
88
+ [st, res]
89
+
90
+ end
91
+
92
+
93
+ elsif not_empty?(msg)
94
+
95
+ newDir, newFiles = @ws.new_files
96
+ add_to_staging(*newFiles)
97
+
98
+ cp "Commit with user message : #{msg}"
99
+ st, res = @ws.commit(msg)
100
+ if st
101
+ block.call(:commit_successful, res) if block
102
+ else
103
+ block.call(:commit_failed, res) if block
104
+ end
105
+ [st, res]
106
+
107
+ end
108
+
109
+ end
110
+
45
111
  def commit(msg = nil, &block)
46
112
 
47
113
  res = :value
@@ -57,6 +123,12 @@ module Release
57
123
 
58
124
  modFiles.delete_if { |f| stgFiles.include?(f) }
59
125
  modDir.delete_if { |f| stgDir.include?(f) }
126
+
127
+ newFiles.delete_if { |f| stgFiles.include?(f) }
128
+ newDir.delete_if { |f| stgDir.include?(f) }
129
+
130
+ delFiles.delete_if { |f| stgFiles.include?(f) }
131
+ delDir.delete_if { |f| stgDir.include?(f) }
60
132
 
61
133
  # block should call vcs for add, remove, ignore and other operations
62
134
  res = block.call(:select_files_to_commit, { modified: { files: modFiles, dirs: modDir }, new: { files: newFiles, dirs: newDir }, deleted: { files: delFiles, dirs: delDir }, staged: { files: stgFiles, dirs: stgDir }, vcs: self, counter: counter } )
@@ -20,6 +20,105 @@ module Release
20
20
  instance_eval(&block) if block
21
21
  end
22
22
 
23
+ def commit_new_files(*args, &block)
24
+ res = @inst.commit_new_files do |ops, *args|
25
+
26
+ preset = false
27
+ if block
28
+ res = block.call(ops, *args)
29
+ if res.nil?
30
+ preset = true
31
+ else
32
+ res
33
+ end
34
+ else
35
+ preset = true
36
+ end
37
+
38
+ if preset
39
+
40
+ case ops
41
+ when :select_files_to_commit
42
+ mfiles = args.first
43
+ @prmt.puts pmsg("\n Files already added to staging : ")
44
+ mfiles[:staged].each do |k,v|
45
+ v.each do |vv|
46
+ @prmt.puts " * #{vv}"
47
+ end
48
+ end
49
+
50
+ @prmt.puts ""
51
+
52
+ sel = @prmt.multi_select pmsg("\n Following are new files that could be added to version control : ") do |m|
53
+
54
+ mfiles[:new].each do |k,v|
55
+ v.each do |vv|
56
+ m.choice vv, vv.path
57
+ end
58
+ end
59
+
60
+ m.choice "Skip", :skip #if mfiles[:counter] == 0
61
+ m.choice "Done", :done
62
+ m.choice "Abort", :abort
63
+ end
64
+
65
+ if sel.include?(:abort)
66
+ raise Release::Gem::Abort, "User aborted"
67
+ elsif sel.include?(:skip)
68
+ :skip
69
+ else
70
+ res = :done if sel.include?(:done)
71
+ s = sel.clone
72
+ s.delete_if { |e| e == :done }
73
+ if not_empty?(s)
74
+ st, cres = add_to_staging(*s) if not_empty?(s)
75
+ if st
76
+ @prmt.puts pmsg("\n Files added successfully", :green)
77
+ else
78
+ @prmt.puts pmsg("\n Files failed to be added. Message was : #{cres}", :red)
79
+ end
80
+ end
81
+
82
+ res
83
+
84
+ end
85
+
86
+ when :commit_message
87
+ msg = ""
88
+ loop do
89
+ msg = @prmt.ask(pmsg("\n Commit message : "), required: true)
90
+ confirm = @prmt.yes?(pmsg(" Commit message : #{msg}\n Proceed? No to provide a new commit message "))
91
+ if confirm
92
+ break
93
+ end
94
+ end
95
+
96
+ msg
97
+
98
+ when :staged_elements_of_commit
99
+
100
+ elements = args.first
101
+ @prmt.puts pmsg("\n Following new files/directories shall be committed in this session : ")
102
+ elements.each do |k,v|
103
+ v.each do |vv|
104
+ @prmt.puts " * #{vv}"
105
+ end
106
+ end
107
+
108
+ when :commit_successful
109
+ @prmt.puts pmsg("\n Changes committed",:green)
110
+ @prmt.puts args.first
111
+
112
+ when :commit_failed
113
+ @prmt.puts pmsg("\n Changes failed to be committed. Error was : #{args.first}")
114
+
115
+ end
116
+ end
117
+ end # commit_new_files block
118
+
119
+ end # commit_new_files
120
+
121
+
23
122
  def commit(*args, &block)
24
123
  res = @inst.commit do |ops, *args|
25
124
 
@@ -60,7 +159,7 @@ module Release
60
159
 
61
160
  end
62
161
 
63
- m.choice "Skip", :skip if mfiles[:counter] == 0
162
+ m.choice "Skip", :skip #if mfiles[:counter] == 0
64
163
  m.choice "Done", :done
65
164
  m.choice "Abort", :abort
66
165
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Release
4
4
  module Gem
5
- VERSION = "0.1.5"
5
+ VERSION = "0.1.6"
6
6
  end
7
7
  end
@@ -15,6 +15,8 @@ Release::Gem.engine(:gem, root: Dir.getwd) do
15
15
  # step 2 : check dependency
16
16
  release_dependencies
17
17
 
18
+ vcs_commit_new_files
19
+
18
20
  # step 3 : build the gem
19
21
  st, ver = build
20
22
 
@@ -59,6 +59,87 @@ Release::Gem.engine(:gem, root: Dir.getwd, ui: STDOUT) do
59
59
  end
60
60
  end
61
61
 
62
+ ## Check in NEW file first or else the gem build will not pick up by the git ls-files
63
+ vcs_commit_new_files do |ops, *args|
64
+
65
+ case ops
66
+ when :select_files_to_commit
67
+ mfiles = args.first
68
+ pmt.puts "\n Files already added to staging : ".yellow
69
+ mfiles[:staged].each do |k,v|
70
+ v.each do |vv|
71
+ pmt.puts " * #{vv}"
72
+ end
73
+ end
74
+
75
+ pmt.puts ""
76
+
77
+ sel = pmt.multi_select "\n Following are new files that could be added to version control : ".yellow do |m|
78
+
79
+ [:modified, :new, :deleted].each do |cat|
80
+ mfiles[cat].each do |k,v|
81
+ v.each do |vv|
82
+ m.choice vv, vv.path
83
+ end
84
+ end
85
+
86
+ end
87
+
88
+ m.choice "Skip", :skip if mfiles[:counter] == 0
89
+ m.choice "Done", :done
90
+ m.choice "Abort", :abort
91
+ end
92
+
93
+ if sel.include?(:abort)
94
+ raise Release::Gem::Abort, "User aborted"
95
+ elsif sel.include?(:skip)
96
+ :skip
97
+ else
98
+ res = :done if sel.include?(:done)
99
+ s = sel.clone
100
+ s.delete_if { |e| e == :done }
101
+ if not_empty?(s)
102
+ st, cres = add_to_staging(*s) if not_empty?(s)
103
+ if st
104
+ pmt.puts "\n Files added successfully".green
105
+ else
106
+ pmt.puts "\n Files failed to be added. Message was : #{cres}".red
107
+ end
108
+ end
109
+
110
+ res
111
+ end
112
+
113
+ when :commit_message
114
+ msg = ""
115
+ loop do
116
+ msg = pmt.ask("\n Commit message : ".yellow, required: true)
117
+ confirm = pmt.yes?(" Commit message : #{msg}\n Proceed? No to provide a new commit message ".yellow)
118
+ if confirm
119
+ break
120
+ end
121
+ end
122
+ msg
123
+
124
+ when :staged_elements_of_commit
125
+ elements = args.first
126
+ pmt.puts "\n Following files/directories shall be committed in this session : ".yellow
127
+ elements.each do |k,v|
128
+ v.each do |vv|
129
+ pmt.puts " * #{vv}"
130
+ end
131
+ end
132
+
133
+ when :commit_successful
134
+ pmt.puts "\n Changes committed".green
135
+
136
+ when :commit_failed
137
+ pmt.puts "\n Changes failed to be committed. Error was : #{args.first}"
138
+
139
+ end
140
+
141
+ end
142
+
62
143
  # step 3 : build the gem
63
144
  st, ver = build do |ops, *args|
64
145
  case ops
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.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris
@@ -126,6 +126,7 @@ files:
126
126
  - lib/release/gem/gem_cli_action.rb
127
127
  - lib/release/gem/gem_engine.rb
128
128
  - lib/release/gem/gemdep.rb
129
+ - lib/release/gem/release_infector.rb
129
130
  - lib/release/gem/vcs_action.rb
130
131
  - lib/release/gem/vcs_cli_action.rb
131
132
  - lib/release/gem/version.rb