renuo-cli 1.3.1 → 1.4.0

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: 37ee2a4b983e26cfcc80c8fa8aa835f0d17fe33847cddbc687d4025bd70288c2
4
- data.tar.gz: 3b54fc5b8eebb7a89987841e15f8656a60d21aff8468e2a4863c137120acaa53
3
+ metadata.gz: d06bce9aa4b4a3585383e216d0ec8a40934c744c0ef744ef6c5b93662bc48b7c
4
+ data.tar.gz: 38a4a1b6d6bdcf1e752b6e06ef35bde896f4369a51e7d6e1094b581d7e876445
5
5
  SHA512:
6
- metadata.gz: 0bfd21df7ce5bc73b8bc2e0d10b08af3806b8fba660f45ce8e3d72ee91b0b47549256ff791bd17bd6f6255c7ef1fae6676a13f441337866a662b920d585c68bf
7
- data.tar.gz: 2ec35a8e4fae858c3d4b237bd85af709fdca99640924ca5e84b587eb47c466c4ebf29d6622016dddcc156a1e86c732fb6da844929b8cd75569a1045e622e5708
6
+ metadata.gz: 2287372eff3dd81ddb3c615b03aa8bc5509008b8e349450ac5c4bceb2ee5710456b5035f35e2f9fd5210cf81bf9c175240268610de422971d3c5f2a8a14eb6b9
7
+ data.tar.gz: ccb4f801d47581ce421ef865410e55456774ac98e1f3252430ee3ad1750dbceabb71253590add5e48d4f589f6b6babf993d6c6dfec9f1659bdfe1b891327024f
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.0
1
+ 2.5.1
data/lib/renuo/cli.rb CHANGED
@@ -127,8 +127,9 @@ module Renuo
127
127
 
128
128
  command 'release' do |c|
129
129
  c.syntax = 'renuo release'
130
- c.summary = 'Deploy a project to master in one command.'
131
- c.description = 'Deploys a project to master as either a Major, Minor, Patch or Custom release.'
130
+ c.summary = 'Release a projects state of develop (on github) to master in one command.'
131
+ c.description = 'Creates a new release version of a project on master as either a Major, Minor, '\
132
+ 'Patch or Custom release based on the current state of develop on Github'
132
133
  c.example 'renuo release my-project minor', 'release a minor release of my-project'
133
134
  c.example 'renuo release my-project custom 2.5.0', 'release my-project as release 2.5.0'
134
135
  c.action do|args|
@@ -1,136 +1,148 @@
1
1
  class ReleaseProject
2
2
  UPDATE_TYPES = %w[major minor patch custom].freeze
3
- TEMP_FOLDER_NAME = ('_RENUO_RELEASE_TEMP_' + rand(100_000_000).to_s).freeze
4
- MOVE_TO_TEMP = "mkdir -p #{TEMP_FOLDER_NAME} && cd #{TEMP_FOLDER_NAME}".freeze
3
+ TMP_FOLDER_NAME = ('_RENUO_RELEASE_TEMP_' + rand(100_000_000).to_s).freeze
4
+ MOVE_TO_TMP_FOLDER = "mkdir -p #{TMP_FOLDER_NAME} && cd #{TMP_FOLDER_NAME}".freeze
5
5
 
6
6
  def run(args)
7
- project_name, @update_type, @version = args
8
- validate_update_type(@update_type, @version)
9
- @version = validate_version(@version)
10
- validate_project_name(project_name)
11
- compare_develop_master(project_name)
12
- release(project_name, @update_type, @version)
7
+ @project_name, @update_type, @version = args
8
+ validate_project_name
9
+ validate_update_type
10
+ validate_custom_version_format
11
+ compare_develop_master
12
+ checkout_project
13
+ @version ||= calculate_version
14
+ release
13
15
  ensure
14
16
  cleanup
15
17
  end
16
18
 
17
- def validate_update_type(update_type, version)
18
- if version && update_type != UPDATE_TYPES[3]
19
- say('>> Do not specify a version for a non-custom release. Given version will be ignored.')
19
+ private
20
+
21
+ def validate_project_name
22
+ abort('>> No project name given.') unless @project_name
23
+ end
24
+
25
+ def validate_update_type
26
+ unless valid_update_type?
27
+ abort('>> Please provide the desired update type: major, minor, patch or custom. '\
28
+ 'If you are unsure about the type please read https://semver.org')
20
29
  end
21
30
 
22
- if !version && update_type == UPDATE_TYPES[3]
23
- @version = ask('>> Please enter your desired version for your custom release (X.Y.Z):')
24
- validate_update_type(@update_type, @version)
31
+ if !custom_version? && @version
32
+ abort('>> Do not specify a version for a non-custom release. Given version will be ignored.')
25
33
  end
26
34
 
27
- return if UPDATE_TYPES.include? update_type
35
+ abort('>> Please enter your desired version for the custom release.') if custom_version? && @version.nil?
36
+ end
28
37
 
29
- @update_type = ask('>> Please enter your desired update type (major minor patch custom):')
30
- validate_update_type(@update_type, version)
38
+ def valid_update_type?
39
+ UPDATE_TYPES.include? @update_type
31
40
  end
32
41
 
33
- def validate_version(version)
34
- return nil if version.nil?
35
- version = version.match(/\d+\.\d+\.\d+/)
36
- return version if version
37
- abort('>> Invalid Version Number. Use format X.Y.Z for your version.')
42
+ def custom_version?
43
+ @update_type == UPDATE_TYPES[3]
38
44
  end
39
45
 
40
- def validate_project_name(project_name)
41
- abort('>> No project name given.') unless project_name
42
- unless system("#{MOVE_TO_TEMP} && hub clone #{project_name} && " \
43
- "cd #{folder_name(project_name)} && git checkout master && git flow init -d")
44
- cleanup
45
- abort('>> Project not found on Github.')
46
- end
46
+ def validate_custom_version_format
47
+ return if @version.nil?
48
+ abort('>> Invalid Version Number. Use format X.Y.Z for your version.') unless @version =~ /\d+\.\d+\.\d+/
47
49
  end
48
50
 
49
- def compare_develop_master(project_name)
50
- say('Please double-check what is going to be deployed.')
51
- system "open https://github.com/#{project_name}/compare/master...develop"
51
+ def compare_develop_master
52
+ puts 'Please double-check what is going to be deployed.'
53
+ open_comparison_page
52
54
  abort unless agree('Are you fine with those changes?')
53
55
  end
54
56
 
55
- def release(project_name, update_type, version)
56
- version ||= update_version_number(current_version(project_name), update_type)
57
-
58
- release_start project_name, update_type, version
59
-
60
- say ">> Project successfully released with version #{version}."
57
+ def open_comparison_page
58
+ system "open https://github.com/#{@project_name}/compare/master...develop"
61
59
  end
62
60
 
63
- def release_start(project_name, update_type, version)
64
- abort('>> Unable to pull from Github. Cancelling release.') unless checkout? project_name
65
-
66
- if update_type != UPDATE_TYPES[3] && !version_bump?(project_name, current_version(project_name))
67
- abort('>> Please bump the version in files manually. Cancelling release.')
61
+ def checkout_project
62
+ unless system("#{MOVE_TO_TMP_FOLDER} && hub clone #{@project_name} && " \
63
+ "cd #{folder_name} && git checkout master && git pull origin master &&" \
64
+ 'git checkout develop && git pull origin develop && git flow init -d')
65
+ abort('>> Project not found on Github.')
68
66
  end
69
-
70
- ask_for_final_confirmation(project_name, update_type, version)
71
-
72
- return if release_flow(project_name, version)
73
- abort('>> Unable to finish release and push to master. Cancelling release.')
74
67
  end
75
68
 
76
- def checkout?(project_name)
77
- system("#{move_and_cd(project_name)} && " \
78
- 'git checkout master && git pull origin master && ' \
79
- 'git checkout develop && git pull origin develop')
69
+ def calculate_version
70
+ current_version_parts = current_version.split('.').map(&:to_i)
71
+ type_index = UPDATE_TYPES.index(@update_type)
72
+ current_version_parts[type_index + 1..-1] = [0] * (2 - type_index)
73
+ current_version_parts[type_index] += 1
74
+ current_version_parts.join('.')
80
75
  end
81
76
 
82
- def version_bump?(project_name, current_version)
83
- grep = "grep -R -F --color --exclude-dir=.git --exclude=Gemfile* '#{current_version}' ."
84
- if system("#{move_and_cd(project_name)} && #{grep}")
85
- agree(">> Current version number (#{current_version}) found in above files. " \
86
- ' Do you wish to continue without changing it?')
77
+ def release
78
+ ask_for_final_confirmation
79
+ start_release_branch
80
+ bump_version
81
+ if finish_release_branch
82
+ puts ">> Project successfully released with version #{@version}."
87
83
  else
88
- true
84
+ abort('>> Unable to finish release and push to master. Cancelling release.')
89
85
  end
90
86
  end
91
87
 
92
- def release_flow(project_name, version)
93
- system("#{move_and_cd(project_name)} &&" \
94
- "git flow release start #{version} && " \
95
- "GIT_MERGE_AUTOEDIT=no git flow release finish -m #{version} #{version} && " \
96
- 'git checkout master && git push origin master && ' \
97
- 'git checkout develop && git push origin develop && ' \
98
- 'git push --tags')
99
- end
100
-
101
- def current_version(project_name)
102
- describe = "#{move_and_cd(project_name)} && git describe --tags"
88
+ def current_version
89
+ return @current_version if @current_version
90
+ describe = cmd_in_folder('git describe --tags')
103
91
  tag = '`git rev-list --tags --max-count=1`'
104
- if `#{move_and_cd(project_name)} && git tag` == ''
105
- '0.0.0'
106
- else
107
- `#{describe} #{tag}`.strip
92
+ @current_version = if `#{cmd_in_folder('git tag')}` == ''
93
+ '0.0.0'
94
+ else
95
+ `#{describe} #{tag}`.strip
96
+ end
97
+ end
98
+
99
+ def bump_version
100
+ version_bumped = find_and_replace_version
101
+
102
+ return unless version_bumped
103
+ system(cmd_in_folder("git add . && git commit -m \"bump version\" && git push -u origin release/#{@version}"))
104
+ end
105
+
106
+ def find_and_replace_version
107
+ find_files_with_version.split("\n").any? do |file_name|
108
+ puts "Replace the version in #{file_name}?"
109
+ print_version_found(file_name)
110
+ if agree('confirm?')
111
+ bump_version_in_file(file_name)
112
+ true
113
+ else
114
+ false
115
+ end
108
116
  end
109
117
  end
110
118
 
111
- def update_version_number(version, update_type)
112
- version = version.split('.').map(&:to_i)
113
- type_index = UPDATE_TYPES.index(update_type)
114
- version[type_index + 1..-1] = [0] * (2 - type_index)
115
- version[type_index] += 1
116
- version.join('.')
119
+ def find_files_with_version
120
+ excluded_dirs = %w[.git node_modules tmp].map { |dir| "--exclude-dir=#{dir}" }.join(' ')
121
+ grep_current_version = "grep -rl -F #{excluded_dirs} --include='*.rb' #{current_version} ."
122
+ `#{cmd_in_folder(grep_current_version)}`
117
123
  end
118
124
 
119
- def move_and_cd(project_name)
120
- "#{MOVE_TO_TEMP} && cd #{folder_name(project_name)}"
125
+ def print_version_found(file_name)
126
+ system(cmd_in_folder("grep -A 1 -B 1 --color #{current_version} #{file_name}"))
121
127
  end
122
128
 
123
- def folder_name(project_name)
124
- project_name.split('/').last
129
+ def bump_version_in_file(file_name)
130
+ system(cmd_in_folder("sed -i '' 's|#{current_version}|#{@version}|g' #{file_name}"))
125
131
  end
126
132
 
127
- def cleanup
128
- system("rm -rf #{TEMP_FOLDER_NAME}")
133
+ def start_release_branch
134
+ system(cmd_in_folder("git flow release start #{@version}"))
135
+ end
136
+
137
+ def finish_release_branch
138
+ system(cmd_in_folder("GIT_MERGE_AUTOEDIT=no git flow release finish -m #{@version} #{@version} && " \
139
+ 'git checkout develop && git push origin develop && ' \
140
+ 'git checkout master && git push origin master --tags'))
129
141
  end
130
142
 
131
- def ask_for_final_confirmation(project_name, update_type, version)
132
- unless agree(">> Are you sure you wish to deploy '#{project_name}' " \
133
- "as a #{update_type} release (#{current_version(project_name)} => #{version})?")
143
+ def ask_for_final_confirmation
144
+ unless agree(">> Are you sure you wish to deploy '#{@project_name}' " \
145
+ "as a #{@update_type} release (#{current_version} => #{@version})?")
134
146
  abort('>> Cancelling Release.')
135
147
  end
136
148
 
@@ -140,4 +152,20 @@ class ReleaseProject
140
152
  abort('>> Very good. Go home now.')
141
153
  end
142
154
  end
155
+
156
+ def cmd_in_folder(command)
157
+ "#{move_and_cd} && #{command}"
158
+ end
159
+
160
+ def move_and_cd
161
+ "#{MOVE_TO_TMP_FOLDER} && cd #{folder_name}"
162
+ end
163
+
164
+ def folder_name
165
+ @project_name.split('/').last
166
+ end
167
+
168
+ def cleanup
169
+ system("rm -rf #{TMP_FOLDER_NAME}")
170
+ end
143
171
  end
@@ -1,6 +1,6 @@
1
1
  module Renuo
2
2
  module Cli
3
- VERSION = '1.3.1'.freeze
3
+ VERSION = '1.4.0'.freeze
4
4
  NAME = 'renuo-cli'.freeze
5
5
  end
6
6
  end
data/renuo-cli.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency 'redcarpet', '~> 3.0'
24
24
 
25
25
  spec.add_development_dependency 'aruba', '~> 0.14.5'
26
- spec.add_development_dependency 'bundler', '~> 1.16'
26
+ spec.add_development_dependency 'bundler', '~> 2.0'
27
27
  spec.add_development_dependency 'coveralls', '~> 0.8.9'
28
28
  spec.add_development_dependency 'cucumber', '~> 3.1'
29
29
  spec.add_development_dependency 'mdl', '~> 0.4.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: renuo-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renuo AG
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-28 00:00:00.000000000 Z
11
+ date: 2019-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '1.16'
89
+ version: '2.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '1.16'
96
+ version: '2.0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: coveralls
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -273,7 +273,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
273
273
  version: '0'
274
274
  requirements: []
275
275
  rubyforge_project:
276
- rubygems_version: 2.7.3
276
+ rubygems_version: 2.7.6
277
277
  signing_key:
278
278
  specification_version: 4
279
279
  summary: The Renuo CLI automates some common workflows.