From fc04d445d0aa9d8168cb934e1350c73e83cb61a3 Mon Sep 17 00:00:00 2001 From: Alessandro Fazzi Date: Fri, 4 Jan 2019 18:08:05 +0100 Subject: [PATCH 1/2] Auto-cd in wordpress folder before running local hooks Remote hooks were already ran into the remote wordpress directory. It was confusing that local and remote hooks needed different approach to be written. usually you run `wordmove` inside the WP root folder, but in some scenarios you could be working inside the theme's folder or inside a plugin's one. Now you are free to launch wordmove from the directory you are in and local hooks' commands will auto-cd inside WP root before being invoked. --- lib/wordmove/hook.rb | 8 +++++--- spec/fixtures/movefiles/with_hooks | 5 ++++- spec/hook_spec.rb | 18 +++++++++++++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/lib/wordmove/hook.rb b/lib/wordmove/hook.rb index cdd35cc..aa2f52f 100644 --- a/lib/wordmove/hook.rb +++ b/lib/wordmove/hook.rb @@ -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? @@ -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? diff --git a/spec/fixtures/movefiles/with_hooks b/spec/fixtures/movefiles/with_hooks index 0b5e31c..fddc9be 100644 --- a/spec/fixtures/movefiles/with_hooks +++ b/spec/fixtures/movefiles/with_hooks @@ -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" @@ -30,6 +32,7 @@ ssh_with_hooks: before: local: - 'echo "Calling hook push before local"' + - 'pwd' remote: - 'echo "Calling hook push before remote"' after: diff --git a/spec/hook_spec.rb b/spec/hook_spec.rb index a0b7880..033bf4b 100644 --- a/spec/hook_spec.rb +++ b/spec/hook_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require 'tmpdir' describe Wordmove::Hook do let(:common_options) { { "wordpress" => true, "config" => movefile_path_for('with_hooks') } } @@ -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/) @@ -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/) @@ -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 From 00e5b078db99d947567ab429d1c84375536efcfa Mon Sep 17 00:00:00 2001 From: Alessandro Fazzi Date: Fri, 4 Jan 2019 18:12:29 +0100 Subject: [PATCH 2/2] Bump version --- lib/wordmove/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wordmove/version.rb b/lib/wordmove/version.rb index 056ae08..7ecfe01 100644 --- a/lib/wordmove/version.rb +++ b/lib/wordmove/version.rb @@ -1,3 +1,3 @@ module Wordmove - VERSION = "3.2.3".freeze + VERSION = "3.3.0".freeze end