herkko 0.0.17 → 0.0.18

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
  SHA1:
3
- metadata.gz: 0ad6707152df95d3628eb7ba4a27fbe51e7dc596
4
- data.tar.gz: fb7b02717ca7de3d3c60da871754e0ab3a01e161
3
+ metadata.gz: c1e2100d4e2787a0e4b82f31ae76cae01c01cae2
4
+ data.tar.gz: d84269eef9d2bfe6898cd3514a952b4383fc299b
5
5
  SHA512:
6
- metadata.gz: 73a6ecec9219fc2f4acc5302a765cb2fece32190e0b649967163c1ee95c1b908edd533eb6e850a04113edd75194792aacc3d5f28564ab652a73ae6281e97479c
7
- data.tar.gz: 27d0141de48b61f0b01408de3e1573d744ebbd257ae9b5c1ad4d889488373f8a4829b8e1a282c11b412f131885dadb479ad91fdc2f8d75eaf4aed5d9a5d7f2b1
6
+ metadata.gz: 93192575889e27eb04995b2cb9f723dc23a0dbeca40cb65d87ed3f6e395e5e34d779cc890bf793b820fff3530e81bb09973320d115807d406ea62e42a7b81e79
7
+ data.tar.gz: 718ca2b403d0b3233855d16f5a35878ae77e46d427116a5232349e85301397bdf8de270b11d1e62a3ec3deaf1dcb9d35ee92d65d57301d3739744ac11f262ad6
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "herkko"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/lib/herkko/runner.rb CHANGED
@@ -36,7 +36,10 @@ module Herkko
36
36
  end
37
37
 
38
38
  def print_usage
39
- Herkko.puts File.read(File.join(File.dirname(__FILE__), "..", "..", "usage.txt"))
39
+ usage_contents = File.read(
40
+ File.join(File.dirname(__FILE__), "..", "..", "usage.txt")
41
+ )
42
+ Herkko.puts usage_contents
40
43
  end
41
44
 
42
45
  def changelog
@@ -48,6 +51,9 @@ module Herkko
48
51
  Herkko.info "Doing #{forced? ? "forced(!) " : ""}deployment to #{environment}..."
49
52
  fetch_currently_deployed_version
50
53
 
54
+ Herkko.info "Pushing commit #{to_be_deployed_sha} from branch #{current_branch} to Heroku..."
55
+ puts
56
+
51
57
  Herkko.info("Deploying changes:")
52
58
 
53
59
  puts
@@ -104,9 +110,13 @@ module Herkko
104
110
  end
105
111
 
106
112
  def push_new_code
107
- Herkko.info "Pushing commit #{to_be_deployed_sha} from branch #{current_branch} to Heroku..."
108
- puts
109
- Herkko.run_with_output("git", "push", environment, "#{to_be_deployed_sha}:master", forced? ? "--force" : nil)
113
+ Herkko.run_with_output(
114
+ "git",
115
+ "push",
116
+ environment,
117
+ "#{to_be_deployed_sha}:master",
118
+ forced? ? "--force" : nil
119
+ )
110
120
  puts
111
121
  end
112
122
 
@@ -129,27 +139,33 @@ module Herkko
129
139
  def deploy!
130
140
  run_migrations = migrations_needed?
131
141
 
132
- if use_maintenace_mode?
133
- enable_maintenance_mode
134
- end
135
-
136
- push_new_code
142
+ in_maintenance_mode do
143
+ push_new_code
144
+
145
+ if run_migrations
146
+ if procfile_release_defined?
147
+ Herkko.info "This release has new migrations but because project has Release Phase defined in Procfile, the migrations are not automatically run."
148
+ else
149
+ migrate
150
+ end
151
+ else
152
+ Herkko.info "No need to migrate."
153
+ end
137
154
 
138
- if run_migrations
139
- migrate
140
- else
141
- Herkko.info "No need to migrate."
155
+ if seed_file_changed?
156
+ Herkko.info "NOTE: Seed file seem the have changed. Make sure to run it if needed."
157
+ end
142
158
  end
143
159
 
144
- if seed_file_changed?
145
- Herkko.info "NOTE: Seed file seem the have changed. Make sure to run it if needed."
146
- end
160
+ print_after_deployment_instructions
161
+ end
147
162
 
148
- if use_maintenace_mode?
149
- disable_maintenance_mode
150
- end
163
+ def in_maintenance_mode
164
+ enable_maintenance_mode if use_maintenace_mode?
151
165
 
152
- print_after_deployment_instructions
166
+ yield
167
+
168
+ disable_maintenance_mode if use_maintenace_mode?
153
169
  end
154
170
 
155
171
  def skip_ci_check?
@@ -168,6 +184,13 @@ module Herkko
168
184
  file_changed?("db/seeds.rb")
169
185
  end
170
186
 
187
+ def procfile_release_defined?
188
+ return false unless File.exist?("Procfile")
189
+
190
+ procfile_contents = File.read("Procfile")
191
+ !!procfile_contents.match(/^release:/)
192
+ end
193
+
171
194
  def current_branch
172
195
  Herkko.run("git", "rev-parse", "--abbrev-ref", "HEAD")[0].strip
173
196
  end
@@ -181,7 +204,13 @@ module Herkko
181
204
  end
182
205
 
183
206
  def file_changed?(file_path)
184
- files = Herkko.run("git", "diff", "--name-only", currently_deployed_to(environment), to_be_deployed_sha)[0]
207
+ files = Herkko.run(
208
+ "git",
209
+ "diff",
210
+ "--name-only",
211
+ currently_deployed_to(environment),
212
+ to_be_deployed_sha
213
+ )[0]
185
214
 
186
215
  files.split("\n").any? {|filename| filename.match(Regexp.new(file_path)) }
187
216
  end
@@ -191,11 +220,19 @@ module Herkko
191
220
  end
192
221
 
193
222
  def git_changelog
194
- Herkko.run("git", "log", "--pretty=format:%C(yellow)%h %Cblue%ad%Creset %an %Cgreen%s%Creset", "--date=short", "#{currently_deployed_to(environment)}..#{to_be_deployed_sha}")[0]
223
+ Herkko.run(
224
+ "git",
225
+ "log",
226
+ "--pretty=format:%C(yellow)%h %Cblue%ad%Creset %an %Cgreen%s%Creset",
227
+ "--date=short",
228
+ "#{currently_deployed_to(environment)}..#{to_be_deployed_sha}"
229
+ )[0]
195
230
  end
196
231
 
197
232
  def print_after_deployment_instructions
198
- after_deployment_instructions = Dir.glob(File.join(Dir.pwd, "after_deployment.*"))
233
+ after_deployment_instructions = Dir.glob(
234
+ File.join(Dir.pwd, "after_deployment.*")
235
+ )
199
236
  if after_deployment_instructions.any?
200
237
  Herkko.info "After deployment instructions:"
201
238
  after_deployment_instructions.each do |file_name|
data/lib/herkko/travis.rb CHANGED
@@ -1,29 +1,12 @@
1
1
  # travis login --pro
2
2
  # travis history -l1 -bmaster
3
3
  module Herkko
4
+ # Checks status of CI build from Travis.
4
5
  class Travis
5
6
  def status_for(branch)
6
7
  if travis_cli_installed?
7
8
  status = fetch_status(branch)
8
- if status[1].length > 0
9
- Herkko.info "There was an error with checking Travis: #{status[1]}"
10
- :red
11
- else
12
- if status[0].strip.length == 0
13
- :not_used
14
- else
15
- case status[0].split(":")[0]
16
- when /passed/
17
- :green
18
- when /started/
19
- :yellow
20
- when /created/
21
- :queued
22
- else
23
- :red
24
- end
25
- end
26
- end
9
+ status_to_code(status)
27
10
  else
28
11
  Herkko.info "Travis CLI has not been installed, run: gem install travis"
29
12
  :unknown
@@ -33,11 +16,39 @@ module Herkko
33
16
  private
34
17
 
35
18
  def fetch_status(branch)
36
- Herkko.run("travis", "history", "--skip-version-check", "-l", "1", "-b", branch)
19
+ Herkko.run(
20
+ "travis",
21
+ "history",
22
+ "--skip-version-check",
23
+ "-l",
24
+ "1",
25
+ "-b",
26
+ branch
27
+ )
37
28
  end
38
29
 
39
30
  def travis_cli_installed?
40
31
  system("which travis > /dev/null 2>&1")
41
32
  end
33
+
34
+ def status_to_code(status)
35
+ if status[1].empty?
36
+ Herkko.info "There was an error with checking Travis: #{status[1]}"
37
+ :red
38
+ elsif status[0].strip.empty?
39
+ :not_used
40
+ else
41
+ case status[0].split(":")[0]
42
+ when /passed/
43
+ :green
44
+ when /started/
45
+ :yellow
46
+ when /created/
47
+ :queued
48
+ else
49
+ :red
50
+ end
51
+ end
52
+ end
42
53
  end
43
54
  end
@@ -1,3 +1,3 @@
1
1
  module Herkko
2
- VERSION = "0.0.17"
2
+ VERSION = "0.0.18".freeze
3
3
  end
data/lib/herkko.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "herkko/version"
2
2
  require "herkko/runner"
3
3
 
4
+ # Main module of Herkko deployment tool.
4
5
  module Herkko
5
6
  @@debug = false
6
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: herkko
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vesa Vänskä
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-16 00:00:00.000000000 Z
11
+ date: 2017-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,6 +44,7 @@ description: It's highly opinionated and might not suit your needs. It has certa
44
44
  email:
45
45
  - vesa@vesavanska.com
46
46
  executables:
47
+ - console
47
48
  - herkko
48
49
  extensions: []
49
50
  extra_rdoc_files: []
@@ -53,6 +54,7 @@ files:
53
54
  - LICENSE.txt
54
55
  - README.md
55
56
  - Rakefile
57
+ - bin/console
56
58
  - bin/herkko
57
59
  - herkko.gemspec
58
60
  - lib/herkko.rb