heroku_hatchet 4.0.2 → 4.0.3

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: fa556ab6fdabb69a56ba6ce5569cee34f4cc63edeb7fc457b6e688b13327c195
4
- data.tar.gz: e5c85e1b3e78e20c048878807e1263813cceb175a3e824471163c112adcb3b04
3
+ metadata.gz: 1369acdf78065d7a2a8679e428f3fff5505a9ab4b0ee42165269e775eaceb1b9
4
+ data.tar.gz: e6c777f04fae2dcf40c54431680372ae7e8ccc105d3144f19b09b81eb29d5dd4
5
5
  SHA512:
6
- metadata.gz: 3a64cc18c16afc07f97de99b76d5a8a5b2232a4fce4e0c287b0326a5536722fb210a5a0fd3153606900f6a9784356741c80794844e51b774351cd664d4fa0d86
7
- data.tar.gz: 1f1dbec3966889e0504f02fb6d66ec8059970868dedffa92b72dfa5a69710c692a3210941e8fe10d52260767b7cd65718f29346e62191fd70772538fef594bbf
6
+ metadata.gz: 704504fbb115cb2b06fb02ca46edd790fb58c94e6e3e6008cd5b414c3b29424835a19b56a4d1e5c8d050f5a81c6b6013a1f2c66ca054ab30ef6bc258874d1354
7
+ data.tar.gz: 11e646721d3e75cda5c9af6636ee27240944c84b681db85aad963a5b93b3d02dd41cf45253b8e54768ab6ae550854a93cc70f72e20a2d5bbe3053810fd5e980d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## HEAD
2
2
 
3
+ ## 4.0.3
4
+
5
+ - Introduce explicit `before_deploy` block that is called, well...before deploy happens. If any changes are made to disk at this time then contents are committed to disk (https://github.com/heroku/hatchet/pull/51)
6
+ - Allow running `deploy` block inside of an `in_directory` block (https://github.com/heroku/hatchet/pull/51)
7
+ - Introduce Hatchet::App#commit! that will commit any files to a repo in the current directory. (https://github.com/heroku/hatchet/pull/51)
8
+
3
9
  ## 4.0.2
4
10
 
5
11
  - Support for running Hatchet tests on Heroku CI by defaulting to `ENV['HEROKU_TEST_RUN_BRANCH']` (#48)
data/lib/hatchet.rb CHANGED
@@ -6,6 +6,7 @@ require 'json'
6
6
  require 'stringio'
7
7
  require 'fileutils'
8
8
  require 'stringio'
9
+ require 'date'
9
10
 
10
11
  module Hatchet
11
12
  end
data/lib/hatchet/app.rb CHANGED
@@ -21,16 +21,28 @@ module Hatchet
21
21
  end
22
22
  end
23
23
 
24
- def initialize(repo_name, options = {})
24
+ def initialize(repo_name,
25
+ stack: "",
26
+ name: default_name,
27
+ debug: nil,
28
+ debugging: nil,
29
+ allow_failure: false,
30
+ labs: [],
31
+ buildpack: nil,
32
+ buildpacks: nil,
33
+ buildpack_url: nil,
34
+ before_deploy: nil
35
+ )
25
36
  @repo_name = repo_name
26
37
  @directory = config.path_for_name(@repo_name)
27
- @name = options[:name] || "hatchet-t-#{SecureRandom.hex(10)}"
28
- @stack = options[:stack]
29
- @debug = options[:debug] || options[:debugging]
30
- @allow_failure = options[:allow_failure] || false
31
- @labs = ([] << options[:labs]).flatten.compact
32
- @buildpacks = options[:buildpack] || options[:buildpacks] || options[:buildpack_url] || self.class.default_buildpack
38
+ @name = name
39
+ @stack = stack
40
+ @debug = debug || debugging
41
+ @allow_failure = allow_failure
42
+ @labs = ([] << labs).flatten.compact
43
+ @buildpacks = buildpack || buildpacks || buildpack_url || self.class.default_buildpack
33
44
  @buildpacks = Array(@buildpacks)
45
+ @before_deploy = before_deploy
34
46
  @reaper = Reaper.new(api_rate_limit: api_rate_limit)
35
47
  end
36
48
 
@@ -148,14 +160,27 @@ module Hatchet
148
160
  puts "Hatchet setup: #{name.inspect} for #{repo_name.inspect}"
149
161
  create_app
150
162
  set_labs!
151
- # heroku.put_config_vars(name, 'BUILDPACK_URL' => @buildpack)
152
- buildpack_list = @buildpacks.map {|pack| { buildpack: pack }}
163
+ buildpack_list = @buildpacks.map { |pack| { buildpack: pack } }
153
164
  api_rate_limit.call.buildpack_installation.update(name, updates: buildpack_list)
165
+
166
+ call_before_deploy
154
167
  @app_is_setup = true
155
168
  self
156
169
  end
157
170
  alias :setup :setup!
158
171
 
172
+ def before_deploy(&block)
173
+ raise "block required" unless block
174
+ @before_deploy = block
175
+
176
+ self
177
+ end
178
+
179
+
180
+ def commit!
181
+ local_cmd_exec!('git add .; git commit -m next')
182
+ end
183
+
159
184
  def push_without_retry!
160
185
  raise NotImplementedError
161
186
  end
@@ -170,10 +195,14 @@ module Hatchet
170
195
  end
171
196
 
172
197
  def in_directory(directory = self.directory)
198
+ yield directory and return if @already_in_dir
199
+
173
200
  Dir.mktmpdir do |tmpdir|
174
201
  FileUtils.cp_r("#{directory}/.", "#{tmpdir}/.")
175
202
  Dir.chdir(tmpdir) do
203
+ @already_in_dir = true
176
204
  yield directory
205
+ @already_in_dir = false
177
206
  end
178
207
  end
179
208
  end
@@ -192,7 +221,6 @@ module Hatchet
192
221
  self.teardown!
193
222
  end
194
223
 
195
-
196
224
  def push
197
225
  max_retries = @allow_failure ? 1 : RETRIES
198
226
  max_retries.times.retry do |attempt|
@@ -208,7 +236,6 @@ module Hatchet
208
236
  alias :push_with_retry :push
209
237
  alias :push_with_retry! :push_with_retry
210
238
 
211
-
212
239
  def retry_error_message(error, attempt, max_retries)
213
240
  attempt += 1
214
241
  return "" if attempt == max_retries
@@ -290,9 +317,38 @@ module Hatchet
290
317
  @api_rate_limit ||= ApiRateLimit.new(@platform_api)
291
318
  end
292
319
 
293
- private
294
- # if someone uses bundle exec
295
- def bundle_exec
320
+ private def needs_commit?
321
+ out = local_cmd_exec!('git status --porcelain').chomp
322
+
323
+ return false if out.empty?
324
+ true
325
+ end
326
+
327
+ private def local_cmd_exec!(cmd)
328
+ out = `#{cmd}`
329
+ raise "Command: #{cmd} failed: #{out}" unless $?.success?
330
+ out
331
+ end
332
+
333
+ private def default_name
334
+ "hatchet-t-#{SecureRandom.hex(10)}"
335
+ end
336
+
337
+ private def call_before_deploy
338
+ return unless @before_deploy
339
+ raise "before_deploy: #{@before_deploy.inspect} must respond to :call" unless @before_deploy.respond_to?(:call)
340
+ raise "before_deploy: #{@before_deploy.inspect} must respond to :arity" unless @before_deploy.respond_to?(:arity)
341
+
342
+ if @before_deploy.arity == 1
343
+ @before_deploy.call(self)
344
+ else
345
+ @before_deploy.call
346
+ end
347
+
348
+ commit! if needs_commit?
349
+ end
350
+
351
+ private def bundle_exec
296
352
  if defined?(Bundler)
297
353
  Bundler.with_clean_env do
298
354
  yield
@@ -1,3 +1,3 @@
1
1
  module Hatchet
2
- VERSION = "4.0.2"
2
+ VERSION = "4.0.3"
3
3
  end
@@ -7,4 +7,59 @@ class AppTest < Minitest::Test
7
7
  app.create_app
8
8
  assert_equal stack, app.platform_api.app.info(app.name)["build_stack"]["name"]
9
9
  end
10
+
11
+ def test_before_deploy
12
+ @called = false
13
+ @dir = false
14
+
15
+ app = Hatchet::App.new("default_ruby")
16
+ def app.push_with_retry!; end # Don't actually deploy
17
+
18
+ app.before_deploy do
19
+ @called = true
20
+ @dir = Dir.pwd
21
+ end
22
+
23
+ app.deploy do
24
+ assert_equal true, @called
25
+ assert_equal Dir.pwd, @dir
26
+ end
27
+
28
+ refute_equal Dir.pwd, @dir
29
+ end
30
+
31
+ def test_auto_commits_code
32
+ string = "foo#{SecureRandom.hex}"
33
+
34
+ app = Hatchet::App.new("default_ruby")
35
+ def app.push_with_retry!; end # Don't actually deploy
36
+
37
+ app.before_deploy do |app|
38
+ assert_equal false, app.send(:needs_commit?)
39
+ `echo "#{string}" > Gemfile`
40
+ assert_equal true, app.send(:needs_commit?)
41
+ end
42
+ app.deploy do
43
+ assert_equal string, File.read("Gemfile").chomp
44
+ assert_equal false, app.send(:needs_commit?)
45
+ end
46
+ end
47
+
48
+
49
+ def test_nested_in_directory
50
+ string = "foo#{SecureRandom.hex}"
51
+
52
+ app = Hatchet::App.new("default_ruby")
53
+ def app.push_with_retry!; end # Don't actually deploy
54
+
55
+ app.in_directory do
56
+ `echo "#{string}" > Gemfile`
57
+ dir = Dir.pwd
58
+
59
+ app.deploy do
60
+ assert_equal string, File.read("Gemfile").chomp
61
+ assert_equal Dir.pwd, dir
62
+ end
63
+ end
64
+ end
10
65
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroku_hatchet
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.2
4
+ version: 4.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Schneeman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-29 00:00:00.000000000 Z
11
+ date: 2018-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: platform-api