This is absolutely possible both in theory and practice although I wouldn't attempt to complete it entirely using a post-receive hook.
The ideal solution would be to have a CI server for example Jenkins (http://jenkins-ci.org/) sat listening with a job configured to handle migrations and use the post-receive hook to trigger this job via either the CLI interface or a cURL request. This takes the onus of a build away from Git (where it doesn't belong) and into CI (where it does).
There are a number of decent CI solutions out there, both free and proprietary which will handle all of this for you with some basic configuration.
The configured job when triggered, checks out your repo (based on a branch you specify) into its own workspace directory and can then call a script to build it as an application.
# post-receive hook
curl http://my.ci-server.local/job/drush_command/buildWithParameters?&GITBRANCH=$GIT_BRANCH&delay=0
my.ci-server.local
Your locally installed CI server installationdrush_command
would be the name of your jobGIT_BRANCH
is the name of the branch to build (default develop???)
Within the CI job you would then have a script which executes steps similar to the following:
# GitIgnore file
savedValue:0001
# bash script
savedValue=$(cat $WORKSPACE/.gitignore | grep 'savedValue' | cut -d: -f2);
newValue=$(savedValue);
for file in $(ls $WORKSPACE/drush_commands); do
currentValue=$(echo $file | cut -d. -f1);
if [ $currentValue -gt $savedValue ] ; then
drush en -y "${currentValue}.txt}";
if [ $currentValue > $newValue ] ; then
newValue=$currentValue;
fi
fi
done
sed -i '' "s/savedValue.*/savedValue:$newValue/" $WORKSPACE/.gitignore;
You could further extend this to handle changes to data by having a separate script called after the loop which looks for other scripts to execute which would then pick up the changes to carry out from a separate directory?
Couple of points:
- I wouldn't add the saved value to the .gitignore file - this isn't really the place for it. Use a separate configuration file (e.g.
conf/last_enabled
) for this kind of information. - The loop isn't going to work terribly well if you have files within the
drush_commands
dir which are not named '001.txt 002.txt' etc. You'll have to filter around these to make sure you're getting the latest.
Hope this helps.