Weblog entry #4 for fugit
#4
SVN post-commit triggers syncing with dev-site
Posted by fugit on Mon 12 Jul 2010 at 21:42
Currently we use a perl module svn::notify. This is normally combined with svn::notify::config which uses YAML for configuration.
A user requested that we do post-commit rsyncs only when a trigger file is updated. This is a quick blogpost about doing the trigger files.
They did not require any additional security they just wanted to be able to deploy via a trigger file.
Below is the script I used to allow for trigger files:
You don't need all of the debug info but I found it helpful. There is a horrible hack that I was to lazy to fix for re-setting the repo and rev after getopt.
The script can take multiply pairs of trigger files and the path to be rsynced if the trigger file was updated. All of the work is done under main. First the variables are read in and then it checks to see if the trigger file was updated using svnlook.
At the end of the script I call other svn::notify::config setups that get synced with out triggers.
Please post any comments if you would like more info on the trigger script or using svn::notify.
A user requested that we do post-commit rsyncs only when a trigger file is updated. This is a quick blogpost about doing the trigger files.
They did not require any additional security they just wanted to be able to deploy via a trigger file.
Below is the script I used to allow for trigger files:
#!/bin/sh
#CONFIG
DEBUG=""
REPOS="$1" # RESET AFTER GETOPTS
REV="$2" # RESET AFTER GETOPTS
SVNLOOK=/usr/local/bin/svnlook
TRIGGER_PAIRS=":" #spaces between each pair
while getopts "d" optionName; do
case "$optionName" in
d) DEBUG="1";;
[?]) echo "Usage: $0 [-d] "
esac
done
shift $(($OPTIND - 1))
# SET AFTER GETOPTS
REPOS="$1"
REV="$2"
#MAIN
# CHECK FOR TRIGGERED SYNCS
for trigger_pair in $TRIGGER_PAIRS
do
TRIGGER_FILE=`echo $trigger_pair |awk -F: {' print $1 '}`
COMMIT_FILE=`echo $trigger_pair |awk -F: {' print $2 '}`
# DEBUG
if [ -n "$debug" ]
then
echo "TRIGGER_FILE: $TRIGGER_FILE" # DEBUG
echo "TRIGGER_PAIR $trigger_pair" # DEBUG
echo "COMMIT_FILE: $COMMIT_FILE" # DEBUG
fi
if [ ! -z "$( $svnlook changed -r $rev $repos | egrep "$trigger_file" $changed )" ]
then
# DEBUG
if [ -n "$debug" ]
then
echo TRIGGER DEBUG: $REPOS/hooks/${COMMIT_FILE} "$REPOS" "$REV" # DEBUG
fi
$REPOS/hooks/${COMMIT_FILE} "$REPOS" "$REV"
fi
done
# END CHECK FOR TRIGGERED SYNCS #
# NON TRIGGERED SYNCS
# CALL YAML:SVN::NOTIFY SYNC for
$REPOS/hooks/ "$REPOS" "$REV"
# END NON TRIGGERED SYNCS
You don't need all of the debug info but I found it helpful. There is a horrible hack that I was to lazy to fix for re-setting the repo and rev after getopt.
The script can take multiply pairs of trigger files and the path to be rsynced if the trigger file was updated. All of the work is done under main. First the variables are read in and then it checks to see if the trigger file was updated using svnlook.
At the end of the script I call other svn::notify::config setups that get synced with out triggers.
Please post any comments if you would like more info on the trigger script or using svn::notify.