-
Notifications
You must be signed in to change notification settings - Fork 167
Hooks
You can find general hooks usage information in movefile.yml configurations explained. This is a sort of F.A.Q. before any question has been made.
Wordmove supports running arbitrary commands during deploy operations. This is how they are represented in the movefile.yml
:
hooks: # Remote hooks won't work with FTP
push:
before:
- command: 'echo "do something"'
where: local
raise: false # raise is true by default
after:
- command: 'echo "do something"'
where: remote
pull:
before:
- command: 'echo "do something"'
where: local
raise: false
after:
- command: 'echo "do something"'
where: remote
Hooks are optional. You can remove the entire hooks
key from movefile.yml
or you can configure just the hooks you need, erasing the others.
Each hook want a sequence - which is the YAML representation of an Array - of command objects.
Commands must be quoted. Prefer single quote, since double quotes are often used inside the command self. If you won't quote commands, they will easily break our toy because there are too many over-complex escaping scenario. So be wise, be happy.
Hooks are under the vigilance of the doctor
command, so you can wordmove doctor
to check their formal validation.
Remote hooks will be run in the $HOME directory of your user. If your home is not your site's document root and if you want to run, e.g. a wp
command, you will have to cd
by yourself:
Both remote and local hooks will be run inside wordpress_path
as per your movefile.yml
configuration.
You can naturally change directory chaining you commands e.g.:
cd other_dire && pwd
Hooks are always executed in order and are synchronous, so the configuration should be procedurally fully respected. What you read is what you get.
By default hooks will throw exception when one command will fail, interrupting any further operation. They can be configured to not raise exception if their command fails. This is crucial when you have a deploy chain where some commands may fail (maybe due to external services? or just because they are not important?) and you want your deploy to continue.
For example
hooks:
push:
before:
- command: 'exit 1'
where: remote
raise: false
- command: 'echo "Still working"'
where: local
the above first command will fail, but the second will be executed; since this are before-push hooks, the push will happens too.
The error is visibly logged anyway.
The where
key accepts two keywords: local
and remote
. With this option you can choose where to execute the command. The remote
will always be the environment specified from the command line with the -e
flag, or the default one when you have a single remote.
Having multiple remote environment, you cannot execute commands on other environments than the one you're push/pulling to/from.
Feel free to populate this section with yours.
hooks:
push:
before:
- command: 'npx webpack' # run webpack to build frontend
where: local
- command: 'rm -rf ./tmp/*' # blank local temp directory
where: local
after:
- command: 'bash ./scripts/slack_notify.sh' # notify colleagues/customers on Slack/Ryver chat
where: local
- command: 'wp rewrite flush' # you know that :)
where: remote
- command: 'wp option set blog_public 0' # hide WP from search engine on staging
where: remote
- command: 'find . -type f -exec chmod 664 {}+' # fix permissions and blame your hosting provider
where: remote
- command: 'find . -type d -exec chmod 755 {}+' # N.B.: blaming is not yet supported by Wordmove
where: remote
We preserve documentation for older version of the "hooks" feature.
Wordmove has 8 hooks which will be called if populated with commands. This is how they are represented in the movefile.yml
:
hooks: # Remote hooks won't work with FTP
push:
before:
local:
- 'echo "Do something locally before push"'
remote:
- 'echo "Do something remotely before push"'
after:
local:
- 'echo "Do something locally after push"'
remote:
- 'echo "Do something remotely after push"'
pull:
before:
local:
- 'echo "Do something locally before pull"'
remote:
- 'echo "Do something remotely before pull"'
after:
local:
- 'echo "Do something locally after pull"'
remote:
- 'echo "Do something remotely after pull"'
Hooks are optional. You can remove the entire hooks
key from movefile.yml
or you can configure just the hooks you need, erasing the others.
Each hook want a sequence - which is the YAML representation of an Array - of commands.
Commands must be quoted. Prefer single quote, since double quotes are often used inside the command self. If you won't quote commands, they will easily break our toy :)
Hooks are under the vigilance of the doctor
command, so you can wordmove doctor
to check their formal validation.
Remote hooks will be run in the $HOME directory of your user. If your home is not your site's document root and if you want to run, e.g. a wp
command, you will have to cd
by yourself:
Since v3.0.0 remote hooks will be run inside wordpress_path
as per your movefile.yml
configuration.
Local hooks will be run from the directory where wordmove
was invoked.
Feel free to populate this section with yours.
hooks:
push:
before:
local:
- 'npx webpack' # run webpack to build frontend
- 'rm -rf ./tmp/*' # blank local temp directory
after:
local:
- 'bash ./scripts/slack_notify.sh' # notify colleagues/customers on Slack/Ryver chat
remote:
- 'wp rewrite flush' # you know that :)
- 'wp option set blog_public 0' # hide WP from search engine on staging
- 'find . -type f -exec chmod 664 {}+' # fix permissions and blame your hosting provider
- 'find . -type d -exec chmod 755 {}+' # N.B.: blaming is not yet supported by Wordmove
All started a long time ago in the feature request #143, opened by @joeguilmette :) Open source not always follows our expectations or timing needs, but participating and make proposals is always inspirational. Thank you Joe!