heroku_hatchet 4.0.2 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/hatchet.rb +1 -0
- data/lib/hatchet/app.rb +70 -14
- data/lib/hatchet/version.rb +1 -1
- data/test/hatchet/app_test.rb +55 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1369acdf78065d7a2a8679e428f3fff5505a9ab4b0ee42165269e775eaceb1b9
|
4
|
+
data.tar.gz: e6c777f04fae2dcf40c54431680372ae7e8ccc105d3144f19b09b81eb29d5dd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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,
|
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 =
|
28
|
-
@stack =
|
29
|
-
@debug =
|
30
|
-
@allow_failure =
|
31
|
-
@labs = ([] <<
|
32
|
-
@buildpacks =
|
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
|
-
|
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
|
-
|
295
|
-
|
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
|
data/lib/hatchet/version.rb
CHANGED
data/test/hatchet/app_test.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2018-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: platform-api
|