Skip to content

Commit

Permalink
Merge pull request #504 from welaika/local_hooks_auto_cd
Browse files Browse the repository at this point in the history
Local hooks auto cd
  • Loading branch information
alessandro-fazzi authored Jan 4, 2019
2 parents 7c20d22 + 00e5b07 commit dd2d950
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
8 changes: 5 additions & 3 deletions lib/wordmove/hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.run(action, step, cli_options)
)

unless hooks.local_hooks.empty?
Wordmove::Hook::Local.run(hooks.local_hooks, cli_options[:simulate])
Wordmove::Hook::Local.run(hooks.local_hooks, options[:local], cli_options[:simulate])
end

return if hooks.remote_hooks.empty?
Expand Down Expand Up @@ -66,14 +66,16 @@ def self.logger
parent.logger
end

def self.run(commands, simulate = false)
def self.run(commands, options, simulate = false)
logger.task "Running local hooks"

wordpress_path = options[:wordpress_path]

commands.each do |command|
logger.task_step true, "Exec command: #{command}"
return true if simulate

stdout_return = `#{command} 2>&1`
stdout_return = `cd #{wordpress_path} && #{command} 2>&1`
logger.task_step true, "Output: #{stdout_return}"

if $CHILD_STATUS.exitstatus.zero?
Expand Down
2 changes: 1 addition & 1 deletion lib/wordmove/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Wordmove
VERSION = "3.2.3".freeze
VERSION = "3.3.0".freeze
end
5 changes: 4 additions & 1 deletion spec/fixtures/movefiles/with_hooks
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<% require 'tmpdir' %>

global:
sql_adapter: "default"

local:
vhost: "http://localhost:8080"
wordpress_path: "/home/welaika/sites/your_site"
wordpress_path: "<%= Dir.tmpdir %>"

database:
name: "database_name"
Expand All @@ -30,6 +32,7 @@ ssh_with_hooks:
before:
local:
- 'echo "Calling hook push before local"'
- 'pwd'
remote:
- 'echo "Calling hook push before remote"'
after:
Expand Down
18 changes: 17 additions & 1 deletion spec/hook_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper'
require 'tmpdir'

describe Wordmove::Hook do
let(:common_options) { { "wordpress" => true, "config" => movefile_path_for('with_hooks') } }
Expand All @@ -24,21 +25,31 @@
end

let(:options) { common_options.merge("environment" => 'ssh_with_hooks') }

it "runs registered before local hooks" do
expect { cli.invoke(:push, [], options) }
.to output(/Calling hook push before local/)
.to_stdout_from_any_process
end

it "runs registered before local hooks in the wordpress folder" do
expect { cli.invoke(:push, [], options) }
.to output(/#{Dir.tmpdir}/)
.to_stdout_from_any_process
end

it "runs registered before remote hooks" do
expect { cli.invoke(:push, [], options) }
.to output(/Calling hook push before remote/)
.to_stdout_from_any_process
end

it "runs registered after local hooks" do
expect { cli.invoke(:push, [], options) }
.to output(/Calling hook push after local/)
.to_stdout_from_any_process
end

it "runs registered after remote hooks" do
expect { cli.invoke(:push, [], options) }
.to output(/Calling hook push after remote/)
Expand Down Expand Up @@ -67,26 +78,31 @@
end

let(:options) { common_options.merge("environment" => 'ssh_with_hooks') }

it "runs registered before local hooks" do
expect { cli.invoke(:pull, [], options) }
.to output(/Calling hook pull before local/)
.to_stdout_from_any_process
end

it "runs registered before remote hooks" do
expect { cli.invoke(:pull, [], options) }
.to output(/Calling hook pull before remote/)
.to_stdout_from_any_process
end

it "runs registered after local hooks" do
expect { cli.invoke(:pull, [], options) }
.to output(/Calling hook pull after local/)
.to_stdout_from_any_process
end

it "runs registered after remote hooks" do
expect { cli.invoke(:pull, [], options) }
.to output(/Calling hook pull after remote/)
.to_stdout_from_any_process
end

it "return remote stdout" do
expect { cli.invoke(:pull, [], options) }
.to output(/Stubbed remote stdout/)
Expand Down Expand Up @@ -154,7 +170,7 @@

context "#local_hooks" do
it "returns all the local hooks" do
expect(config.local_hooks).to eq ['echo "Calling hook push before local"']
expect(config.local_hooks).to eq ['echo "Calling hook push before local"', 'pwd']
end
end

Expand Down

0 comments on commit dd2d950

Please sign in to comment.