I site I'm working on uses a post-receive
git hook for deploying changes to the server.
At the moment, it looks like this:
#!/bin/sh
# default cpanel stuff
branch=$(/usr/local/cpanel/3rdparty/bin/git branch | awk '$1 == "*"{print $2}')
while read oldrev newrev ref
do
if [ "x$ref" == "xrefs/heads/$branch" ]
then
echo "Recieved update on checked-out branch, queueing deployment."
(cd .. ; /usr/bin/uapi VersionControlDeployment create repository_root=$PWD)
fi
branch=`echo $ref | cut -d/ -f3`
cd ../
# run from dir outside of .git
# unset git dir because git ugh https://stackoverflow.com/a/10513684
unset GIT_DIR
if [ "master" == "$branch" ]; then
# echo this is master
# create new working tree in the desired directory
git --work-tree=../prod-test checkout -f $branch
fi
if [ "develop" == "$branch" ]; then
# echo this is develop
git --work-tree=../staging checkout -f $branch
fi
done < /dev/stdin
That works fine. I push from my local and the changes get deployed to staging.
But I want project config and plugin update changes to be automatically applied rather than having to visit the CP and click the sync changes button.
I've seen elsewhere that the way to do that is to run
./craft project-config/sync
./craft clear-caches/all
composer update
so I thought I could add it to the hook, just above done < /dev/stdin
but it doesn't work, I still have to manually update.
Has anyone else done something like this before?
cd
into the right directory where thecraft
script is located. Depending on your server settings you may also need to run it as a different user withsudo -u someone-else
. What happens when you run the command manually? – James Smith Mar 11 '20 at 11:20./craft project-config/sync >> git-hooks-log-file.txt
– James Smith Mar 12 '20 at 9:47