heroku_hatchet 3.0.6 → 3.1.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: d13cac9a330ace0d1cf9f4cc3994b32d56f35e91ba5aa5fd0a6262bd1f49fe38
4
- data.tar.gz: b1b8809b146182aca8173146ab7bcf703aaf929311d69ef0b45219d6088da078
3
+ metadata.gz: 7705d38debbab89dedc8a49709edc3622dd8e3c24c019a11b1709c7bd9224977
4
+ data.tar.gz: c2cc84b1898f3c6401f3549339f25c44a985ef71bd870faea736f9d0e5155d1b
5
5
  SHA512:
6
- metadata.gz: 20a9d41e88f5bdab3e41671cce20cc14947e8e3dc13fb1997c3dd5dda5d7cb55ab224543257dbcf5205696bedfa2d0f2d47fc162f1c1d408d2696121d8cf172d
7
- data.tar.gz: 9e138c6c8cdce9b773560540153777d6e8c12cc3c13b7969a0b6261e99a02e542865a9f4945d175998dbd09885c018ed9474ffd9219d57febe775ea51bde31c9
6
+ metadata.gz: bfb9317a73bce407d199e2f87b210bd014b86e102d5de04a3f0a95e1aad4871a6b789ebe0e3e322e2eb140797a42ed9b5b81d0b3e109850bb056110b99f3129c
7
+ data.tar.gz: e7c68939dfff5a7d28754a16a6934cc1a2a5821424df408487632dfa62fcab1e38a5eb23527fdceadf63d64c72ff3a3455c72568504211c3ebfaec2b59175d81
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## HEAD
2
2
 
3
+ ## 3.1.0
4
+
5
+ - Introduce a lockfile #42
6
+
3
7
  ## 3.0.6
4
8
 
5
9
  - Fix double delete error #41
data/bin/hatchet CHANGED
@@ -14,14 +14,17 @@ require 'hatchet'
14
14
  require 'thor'
15
15
  require 'threaded'
16
16
  require 'date'
17
+ require 'yaml'
17
18
 
18
19
  class HatchetCLI < Thor
19
20
  desc "install", "installs repos defined in 'hatchet.json'"
20
21
  def install
21
22
  warn_dot_ignore!
23
+ lock_hash = YAML.safe_load(File.read('hatchet.lock')).to_h
22
24
  puts "Installing repos for hatchet"
23
25
  dirs.map do |directory, git_repo|
24
26
  Threaded.later do
27
+ commit = lock_hash.fetch(directory) { raise "expected #{directory} to be locked but it is not, please run `hatchet lock` and commit the results"}
25
28
  directory = File.expand_path(directory)
26
29
  if Dir[directory].present?
27
30
  puts "== pulling '#{git_repo}' into '#{directory}'\n"
@@ -30,10 +33,33 @@ class HatchetCLI < Thor
30
33
  puts "== cloning '#{git_repo}' into '#{directory}'\n"
31
34
  clone(directory, git_repo)
32
35
  end
36
+ checkout_commit(directory, commit)
33
37
  end
34
38
  end.map(&:join)
35
39
  end
36
40
 
41
+ desc "locks to specific git commits", "updates hatchet.lock"
42
+ def lock
43
+ lock_hash = {}
44
+ dirs.map do |directory, git_repo|
45
+ Threaded.later do
46
+ puts "== locking #{directory}"
47
+ unless Dir.exist?(directory)
48
+ raise "Bad git repo #{git_repo.inspect}" if bad_repo?(git_repo)
49
+ clone(directory, git_repo, quiet: false)
50
+ end
51
+
52
+ commit = commit_at_directory(directory)
53
+ lock_hash[directory] = commit
54
+ end
55
+ end.map(&:join)
56
+
57
+ lock_hash = lock_hash.sort
58
+ File.open('hatchet.lock', 'w') {|f| f << lock_hash.to_yaml }
59
+
60
+ puts "Done!"
61
+ end
62
+
37
63
  desc "list", "lists all repos and their destination listed in hatchet.json"
38
64
  def list
39
65
  repos.each do |repo, directory|
@@ -59,6 +85,11 @@ class HatchetCLI < Thor
59
85
 
60
86
  private
61
87
 
88
+ def bad_repo?(url)
89
+ `git ls-remote --exit-code -h "#{url}"`
90
+ $? != 0
91
+ end
92
+
62
93
  def warn_dot_ignore!
63
94
  return false unless File.exist?('.gitignore')
64
95
 
@@ -80,14 +111,22 @@ class HatchetCLI < Thor
80
111
  config.dirs
81
112
  end
82
113
 
83
- def pull(path, git_repo)
84
- puts `cd #{path} && git pull --rebase #{git_repo} master --quiet`
114
+ def checkout_commit(directory, commit)
115
+ cmd("cd #{directory} && git reset --hard #{commit}")
116
+ end
117
+
118
+ def commit_at_directory(directory)
119
+ cmd("cd #{directory} && git log -n1 --pretty=format:%H").strip
85
120
  end
86
121
 
87
- def clone(path, git_repo)
122
+ def pull(path, git_repo, commit: false)
123
+ cmd("cd #{path} && git pull --rebase #{git_repo} master --quiet")
124
+ end
125
+
126
+ def clone(path, git_repo, quiet: true)
88
127
  path = File.join(path, '..') # up one dir to prevent repos/codetriage/codetriage/#...
89
128
  FileUtils.mkdir_p(path)
90
- puts `cd #{path} && git clone #{git_repo} --quiet`
129
+ cmd("cd #{path} && git clone #{git_repo} --quiet", quiet: quiet)
91
130
  end
92
131
 
93
132
  def bundle_exec
@@ -99,6 +138,15 @@ class HatchetCLI < Thor
99
138
  yield
100
139
  end
101
140
  end
141
+
142
+ def cmd(command, let_fail: false, stdin: nil, quiet: true)
143
+ command = "printf '#{stdin}' | #{command}" if stdin
144
+ puts "Running: #{command}" unless quiet
145
+ result = `#{command}`
146
+ return result if let_fail
147
+ raise "Command #{command} failed:\n#{result}" unless $?.success?
148
+ return result
149
+ end
102
150
  end
103
151
 
104
152
  HatchetCLI.start(ARGV)
data/hatchet.json CHANGED
@@ -1,5 +1,7 @@
1
1
  {
2
- "hatchet": {"directory": "test/fixtures"},
2
+ "hatchet": {
3
+ "directory": "test/fixtures"
4
+ },
3
5
  "rails3": ["sharpstone/rails3_mri_193"],
4
6
  "rails2": ["sharpstone/rails2blog"],
5
7
  "bundler": ["sharpstone/no_lockfile"],
@@ -7,5 +9,6 @@
7
9
  "ci": [
8
10
  "sharpstone/rails5_ruby_schema_format",
9
11
  "sharpstone/rails5_ci_fails_no_database"
10
- ]
12
+ ],
13
+ "lock": ["sharpstone/lock_fail"]
11
14
  }
data/hatchet.lock ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ - - test/fixtures/repos/bundler/no_lockfile
3
+ - 1947ce9a9c276d5df1c323b2ad78d1d85c7ab4c0
4
+ - - test/fixtures/repos/ci/rails5_ci_fails_no_database
5
+ - 3044f05febdfbbe656f0f5113cf5968ca07e34fd
6
+ - - test/fixtures/repos/ci/rails5_ruby_schema_format
7
+ - 3e63c3e13f435cf4ab11265e9abd161cc28cc552
8
+ - - test/fixtures/repos/default/default_ruby
9
+ - da748a59340be8b950e7bbbfb32077eb67d70c3c
10
+ - - test/fixtures/repos/lock/lock_fail
11
+ - da748a59340be8b950e7bbbfb32077eb67d70c3c
12
+ - - test/fixtures/repos/rails2/rails2blog
13
+ - b37357a498ae5e8429f5601c5ab9524021dc2aaa
14
+ - - test/fixtures/repos/rails3/rails3_mri_193
15
+ - 88c5d0d067cfd11e4452633994a85b04627ae8c7
@@ -1,3 +1,3 @@
1
1
  module Hatchet
2
- VERSION = "3.0.6"
2
+ VERSION = "3.1.0"
3
3
  end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ class LockTest < Minitest::Test
4
+ def test_app_with_failure_can_be_locked_to_prior_commit
5
+ Hatchet::GitApp.new("lock_fail").deploy do |app|
6
+ assert app.deployed?
7
+ end
8
+ end
9
+ 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: 3.0.6
4
+ version: 3.1.0
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-03-19 00:00:00.000000000 Z
11
+ date: 2018-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: platform-api
@@ -196,6 +196,7 @@ files:
196
196
  - bin/hatchet
197
197
  - hatchet.gemspec
198
198
  - hatchet.json
199
+ - hatchet.lock
199
200
  - lib/hatchet.rb
200
201
  - lib/hatchet/anvil_app.rb
201
202
  - lib/hatchet/app.rb
@@ -218,6 +219,7 @@ files:
218
219
  - test/hatchet/git_test.rb
219
220
  - test/hatchet/heroku_api_test.rb
220
221
  - test/hatchet/labs_test.rb
222
+ - test/hatchet/lock_test.rb
221
223
  - test/hatchet/multi_cmd_runner_test.rb
222
224
  - test/test_helper.rb
223
225
  homepage: https://github.com/heroku/hatchet
@@ -258,5 +260,6 @@ test_files:
258
260
  - test/hatchet/git_test.rb
259
261
  - test/hatchet/heroku_api_test.rb
260
262
  - test/hatchet/labs_test.rb
263
+ - test/hatchet/lock_test.rb
261
264
  - test/hatchet/multi_cmd_runner_test.rb
262
265
  - test/test_helper.rb