SVN hooks

99 views
Skip to first unread message

Jean Baptiste FAVRE

unread,
Aug 12, 2010, 5:03:39 AM8/12/10
to puppet...@googlegroups.com
Hello list,
I'm planning to deploy and use Puppet at work.
For this, I've set up a SVN server to keep track of all changes in
modules & manifests.

Reading documentation to be able to define coding rules, I want to put
some SVN hooks to ensure for correct syntax and coding rules respect.

Does anybody here use such scripts ? Are some public version available ?
Or am I wrong going this way ?

Regards,
JB

Eric Heydrick

unread,
Aug 12, 2010, 5:24:39 AM8/12/10
to puppet...@googlegroups.com

We have an SVN post-commit hook that does a syntax check on manifests and
templates. It could be extended to enforce coding standards if you wanted.
The script is contained within http://forge.puppetlabs.com/ghoneycutt/svn
or grab it directly at
http://github.com/ghoneycutt/puppet-svn/raw/master/files/puppet/hooks/pre-commit

-Eric

Jean Baptiste FAVRE

unread,
Aug 12, 2010, 5:52:54 AM8/12/10
to puppet...@googlegroups.com
Hello Eric,
Thanks for the link.
My bad, did not think about looking into puppet svn modules :-/

Will try it asap,
Regards,
JB

Le 12/08/2010 11:24, Eric Heydrick a �crit :


> On Thu, 12 Aug 2010, Jean Baptiste FAVRE wrote:
>
>> Hello list,
>> I'm planning to deploy and use Puppet at work.
>> For this, I've set up a SVN server to keep track of all changes in

>> modules& manifests.

Alexander Kriventsov

unread,
Aug 12, 2010, 5:12:49 AM8/12/10
to puppet...@googlegroups.com
12.08.2010 13:03, Jean Baptiste FAVRE пишет:

You're on a good way.
I'm using pre-commit hook to check syntax on FreeBSD, so you should to
check path

#!/bin/sh
#
# SVN pre-commit hook to check Puppet syntax for .pp files
# Modified from
http://mail.madstop.com/pipermail/puppet-users/2007-March/002034.html
#

REPOS="$1"
TXN="$2"

tmpfile=`mktemp /tmp/XXXXX`
export HOME=/
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
SVNLOOK=/usr/local/bin/svnlook
PUPPET=/usr/local/bin/puppet

$SVNLOOK changed -t "$TXN" "$REPOS" | awk '{print $2}' | grep '\.pp$' |
while read line
do
$SVNLOOK cat -t "$TXN" "$REPOS" "$line" > $tmpfile
if [ $? -ne 0 ]
then
echo "Warning: Failed to checkout $line" >&2
fi
$PUPPET --color=false --confdir=/tmp --vardir=/tmp --parseonly
--ignoreimport $tmpfile >&2
if [ $? -ne 0 ]
then
echo "Puppet syntax error in $line." >&2
exit 2
fi
done
res=$?
rm -f $tmpfile

if [ $res -ne 0 ]
then
exit $res
fi


>
> Regards,
> JB
>


--
Alexander Kriventsov

Gustavo Soares

unread,
Aug 12, 2010, 9:30:24 AM8/12/10
to puppet...@googlegroups.com
I am also using some hooks, but for git. I've been using to hooks: client-side hooks and server-side hooks.


Gus



--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.


Joe McDonagh

unread,
Aug 12, 2010, 9:51:43 AM8/12/10
to puppet...@googlegroups.com

Hello list,
>>> I'm planning to deploy and use Puppet at work.
>>> For this, I've set up a SVN server to keep track of all changes in
>>> modules& manifests.
>>>
>>> Reading documentation to be able to define coding rules, I want to put
>>> some SVN hooks to ensure for correct syntax and coding rules respect.
>>>
>>> Does anybody here use such scripts ? Are some public version
>>> available ?
>>> Or am I wrong going this way ?

This is mine, it does some extra syntax checking:

#!/bin/bash
# This file is managed by Puppet

export TMPDIR="/tmp/svntmp"

if [ ! -e "TMPDIR" ]; then
mkdir -p $TMPDIR && chmod 1777 $TMPDIR
fi

export ERRCOUNT=0
export PATH="/usr/bin:/bin"
export REPOS="$1"
export TMPFILE=$(mktemp -p $TMPDIR)
export TXN="$2"

while read LINE; do
svnlook cat -t "$TXN" "$REPOS" "$LINE" > "$TMPFILE"

if [ $? -ne 0 ]; then

echo "Warning: Failed to checkout $LINE" >&2
fi

EXT=$(echo $LINE | awk -F'.' '{ print $NF }')

case "$EXT" in
"erb")
erb -x -T '-' $TMPFILE | ruby -c

if [ $? -ne 0 ]; then

echo "ERB parsing error in $LINE" >&2
let ERRCOUNT+=1
fi
;;
"pp")
/usr/bin/puppet --color=false --parseonly --ignoreimport
"$TMPFILE"

if [ $? -ne 0 ]; then

echo "Puppet syntax error in $LINE" >&2
let ERRCOUNT+=1
fi
;;
"rb")
ruby -c $TMPFILE

if [ $? -ne 0 ]; then

echo "Ruby syntax error in $LINE" >&2
let ERRCOUNT+=1
fi
;;
"sh")
bash -n $TMPFILE

if [ $? -ne 0 ]; then

echo "Bash syntax error in $LINE" >&2
let ERRCOUNT+=1
fi
;;
*)
continue
;;
esac
done < <(svnlook changed -t "$TXN" "$REPOS" | awk '{print $2}')

rm -f "$TMPFILE"
exit $ERRCOUNT


--
Joe McDonagh
AIM: YoosingYoonickz
IRC: joe-mac on freenode
"When the going gets weird, the weird turn pro."

Reply all
Reply to author
Forward
0 new messages