hanzo 0.5 → 0.6

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: 803ef303a0cfc9a80e8b5054eebeb94296170084
4
- data.tar.gz: c4f0ae51305685c86224f45ab3b6668941e81a39
3
+ metadata.gz: 5f2163d68dba551ae26f662a1e0feef58ce68189
4
+ data.tar.gz: 28cd31d65ed3326257f96a45a757a0434d7ddacd
5
5
  SHA512:
6
- metadata.gz: 07529e76fcd35dd0e11902cbe46cd93f3c5831fe46d949fc48f615afbc3abd1080f2796b8efe0de4df3ca53bd7ba580dae639cb920c4265f393b65c8d82cb8f2
7
- data.tar.gz: 022c69701c64406218bc681857a2e24d75773cd717e608c6edc658b24410980be6b84a591892bde19b895ac8fd07fd66297cf2ca377fc2e7c97171cd16f74c10
6
+ metadata.gz: 69325cbe09fc4fac847142901acb2c5e144a65dc15546c50095600b78d94c094c0525c5322338784faca7be2a590384c7d526dd10ae664f6a848a9b1d5b08302
7
+ data.tar.gz: 382cee77dcbd708ccbe8334c7211d5256b132bf06469bc8d32160247e23e84d0890f0538ac79121f90870bfd1d236aea233d87de6ffd1b8e875be8713d1b20ba
data/README.md CHANGED
@@ -25,11 +25,17 @@ gem 'hanzo'
25
25
  Create an `.hanzo.yml` file at the root of your app that will contain a map of
26
26
  remotes, with the remote as the key and the Heroku application name as the value.
27
27
 
28
+ You can also specify commands that can be ran on the application after a
29
+ successful deploy. Hanzo will prompt to run each of them, they each will be ran
30
+ with `heroku run` and the application will be restarted at the end.
31
+
28
32
  ```yaml
29
33
  remotes:
30
34
  qa: heroku-app-name-qa
31
35
  staging: heroku-app-name-staging
32
36
  production: heroku-app-name-production
37
+ after_deploy:
38
+ - rake db:migrate
33
39
  ```
34
40
 
35
41
  ### Install remotes
@@ -4,12 +4,6 @@ module Hanzo
4
4
  UnknownEnvironment = Class.new(StandardError)
5
5
  UninstalledEnvironment = Class.new(StandardError)
6
6
 
7
- # Constants
8
- MIGRATION_COMMANDS = {
9
- 'db/migrate' => 'rake db:migrate',
10
- 'priv/repo/migrations' => 'mix ecto.migrate'
11
- }
12
-
13
7
  protected
14
8
 
15
9
  def initialize_variables
@@ -20,7 +14,7 @@ module Hanzo
20
14
  def initialize_cli
21
15
  initialize_help && return if @env.nil?
22
16
 
23
- deploy && run_migrations
17
+ deploy && run_after_deploy_commands
24
18
  rescue UnknownEnvironment
25
19
  Hanzo.unindent_print "Environment `#{@env}` doesn't exist. Add it to .hanzo.yml and run:\n hanzo install remotes", :red
26
20
  Hanzo.unindent_print "\nFor more information, read https://github.com/mirego/hanzo#install-remotes", :red
@@ -48,14 +42,21 @@ module Hanzo
48
42
  Hanzo.run "git push -f #{@env} #{branch}:master"
49
43
  end
50
44
 
51
- def run_migrations
52
- return if migration_directory.nil?
53
- return unless Hanzo.agree('Run database migrations?')
45
+ def run_after_deploy_commands
46
+ return unless after_deploy_commands.any?
47
+
48
+ after_deploy_commands.each do |command|
49
+ next unless Hanzo.agree("Run `#{command}` on #{@env}?")
50
+ Hanzo.run "heroku run #{command} --remote #{@env}"
51
+ end
54
52
 
55
- Hanzo.run "heroku run #{migration_command} --remote #{@env}"
56
53
  Hanzo.run "heroku ps:restart --remote #{@env}"
57
54
  end
58
55
 
56
+ def after_deploy_commands
57
+ Hanzo.config['after_deploy'] || []
58
+ end
59
+
59
60
  def validate_environment_existence!
60
61
  raise UnknownEnvironment unless fetcher.exist?
61
62
  raise UninstalledEnvironment unless fetcher.installed?
@@ -64,13 +65,5 @@ module Hanzo
64
65
  def fetcher
65
66
  @fetcher ||= Hanzo::Fetchers::Environment.new(@env)
66
67
  end
67
-
68
- def migration_directory
69
- MIGRATION_COMMANDS.keys.find { |directory| Dir.exist?(directory) }
70
- end
71
-
72
- def migration_command
73
- MIGRATION_COMMANDS[migration_directory]
74
- end
75
68
  end
76
69
  end
data/lib/hanzo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hanzo
2
- VERSION = '0.5'.freeze
2
+ VERSION = '0.6'.freeze
3
3
  end
@@ -2,32 +2,23 @@ require 'spec_helper'
2
2
 
3
3
  describe Hanzo::CLI do
4
4
  describe :deploy do
5
- let(:env) { 'production' }
6
- let(:branch) { '1.0.0' }
7
- let(:deploy!) { Hanzo::CLI.new(['deploy', env]) }
8
- let(:heroku_remotes) { { 'production' => 'heroku-app-production' } }
9
- let(:migration_dir) { 'db/migrate' }
10
-
11
- let(:migration_question) { 'Run database migrations?' }
12
- let(:deploy_question) { "Branch to deploy in #{env}:" }
13
-
14
- let(:migration_cmd) { "heroku run rake db:migrate --remote #{env}" }
15
- let(:restart_cmd) { "heroku ps:restart --remote #{env}" }
16
- let(:deploy_cmd) { "git push -f #{env} #{branch}:master" }
5
+ let(:deploy!) { Hanzo::CLI.new(['deploy', 'production']) }
6
+ let(:deploy_question) { 'Branch to deploy in production:' }
7
+ let(:deploy_command) { "git push -f production 1.0.0:master" }
17
8
 
18
9
  before do
19
10
  expect(Hanzo::Installers::Remotes).to receive(:environments).and_return(['production'])
20
11
  expect(Hanzo::Installers::Remotes).to receive(:installed_environments).and_return(['production'])
21
12
  end
22
13
 
23
- context 'successful deploy and without migrations' do
24
- let(:migrations_exist) { false }
14
+ context 'successful deploy and without after_deploy commands' do
25
15
  let(:deploy_result) { true }
16
+ let(:config) { {} }
26
17
 
27
18
  before do
28
- expect(Dir).to receive(:exist?).with(instance_of(String)).at_least(:once).and_return(migrations_exist)
29
- expect(Hanzo).to receive(:ask).with(deploy_question).and_return(branch)
30
- expect(Hanzo).to receive(:run).with(deploy_cmd).once.and_return(deploy_result)
19
+ allow(Hanzo).to receive(:config).and_return(config)
20
+ expect(Hanzo).to receive(:ask).with(deploy_question).and_return('1.0.0')
21
+ expect(Hanzo).to receive(:run).with(deploy_command).once.and_return(deploy_result)
31
22
  end
32
23
 
33
24
  it 'should git push to heroku upstream' do
@@ -35,49 +26,37 @@ describe Hanzo::CLI do
35
26
  end
36
27
  end
37
28
 
38
- context 'with existing migrations' do
39
- let(:migrations_exist) { true }
29
+ context 'with existing after_deploy commands' do
30
+ let(:config) { { 'after_deploy' => %w(foo bar) } }
40
31
 
41
32
  before do
42
- expect(Hanzo).to receive(:ask).with(deploy_question).and_return(branch)
43
- expect(Hanzo).to receive(:run).with(deploy_cmd).once.and_return(deploy_result)
33
+ allow(Hanzo).to receive(:config).and_return(config)
34
+ expect(Hanzo).to receive(:ask).with(deploy_question).and_return('1.0.0')
35
+ expect(Hanzo).to receive(:run).with(deploy_command).once.and_return(deploy_result)
44
36
  end
45
37
 
46
38
  context 'with successful deploy' do
47
39
  let(:deploy_result) { true }
48
40
 
49
41
  before do
50
- expect(Dir).to receive(:exist?).with(instance_of(String)).at_least(:once).and_return(migrations_exist)
51
- end
52
-
53
- context 'and migrations that should be ran' do
54
- before do
55
- expect(Hanzo).to receive(:agree).with(migration_question).and_return(true)
56
- expect(Hanzo).to receive(:run).with(migration_cmd)
57
- expect(Hanzo).to receive(:run).with(restart_cmd)
58
- end
59
-
60
- specify { deploy! }
42
+ expect(Hanzo).to receive(:agree).with('Run `foo` on production?').and_return(true)
43
+ expect(Hanzo).to receive(:run).with('heroku run foo --remote production')
44
+ expect(Hanzo).to receive(:agree).with('Run `bar` on production?').and_return(true)
45
+ expect(Hanzo).to receive(:run).with('heroku run bar --remote production')
46
+ expect(Hanzo).to receive(:run).with('heroku ps:restart --remote production')
61
47
  end
62
48
 
63
- context 'and migrations that should not be ran' do
64
- before do
65
- expect(Hanzo).to receive(:agree).with(migration_question).and_return(false)
66
- expect(Hanzo).not_to receive(:run).with(migration_cmd)
67
- expect(Hanzo).not_to receive(:run).with(restart_cmd)
68
- end
69
-
70
- specify { deploy! }
71
- end
49
+ specify { deploy! }
72
50
  end
73
51
 
74
52
  context 'without successful deploy' do
75
53
  let(:deploy_result) { false }
76
54
 
77
55
  before do
78
- expect(Hanzo).not_to receive(:agree).with(migration_question)
79
- expect(Hanzo).not_to receive(:run).with(migration_cmd)
80
- expect(Hanzo).not_to receive(:run).with(restart_cmd)
56
+ expect(Hanzo).not_to receive(:agree)
57
+ expect(Hanzo).not_to receive(:run).with('heroku run foo --remote production')
58
+ expect(Hanzo).not_to receive(:run).with('heroku run bar --remote production')
59
+ expect(Hanzo).not_to receive(:run).with('heroku ps:restart --remote production')
81
60
  end
82
61
 
83
62
  specify { deploy! }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanzo
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: '0.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Garneau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-11 00:00:00.000000000 Z
11
+ date: 2017-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  version: '0'
151
151
  requirements: []
152
152
  rubyforge_project:
153
- rubygems_version: 2.5.1
153
+ rubygems_version: 2.6.8
154
154
  signing_key:
155
155
  specification_version: 4
156
156
  summary: Hanzo is a tool to handle deployments in multiple environments on Heroku.