[Xfce4-commits] <xfce-git-hooks:master> Prepare buildbot notifications in post-receive, send in post-update.
Jannis Pohlmann
noreply at xfce.org
Tue Sep 29 13:58:01 CEST 2009
Updating branch refs/heads/master
to c99304a2905cebfda3da74774b7e55b0d650102e (commit)
from 1a3455349145bd8a8564a517c83a8402caf938b1 (commit)
commit c99304a2905cebfda3da74774b7e55b0d650102e
Author: Jannis Pohlmann <jannis at xfce.org>
Date: Tue Sep 29 13:54:43 2009 +0200
Prepare buildbot notifications in post-receive, send in post-update.
The post-receive hook now writes its three parameters into
/var/spool/git-buildbot-updates and the post-update hook later reads
these lines and passes them to the buildbot update script one by one.
To avoid conflicts or corrupted files, we're using flock here. The
post-receive hook obtains an exclusive lock while the post-update hook
only needs a shared lock.
hooks/post-receive-01-buildbot | 17 +++++++++++++++--
hooks/post-update-02-buildbot | 24 ++++++++++++++++++++++++
post-receive | 5 +----
post-update | 11 +++++++++++
4 files changed, 51 insertions(+), 6 deletions(-)
diff --git a/hooks/post-receive-01-buildbot b/hooks/post-receive-01-buildbot
index a63e550..9babcda 100755
--- a/hooks/post-receive-01-buildbot
+++ b/hooks/post-receive-01-buildbot
@@ -1,10 +1,23 @@
#!/bin/sh
+QUEUE_FILE=/var/spool/git-buildbot-updates
+LOCK_FILE=/var/spool/.git-buildbot-updates-lock
+
if echo $0 | grep -q '^/'; then
mydir=`dirname $0`
else
mydir=`pwd`/`dirname $0`
fi
-# Do nothing for now until this is tested.
-echo "$1 $2 $3" | $mydir/git_buildbot.py > /dev/null
+(
+ # Obtain an exclusive lock for writing to the queue file
+ flock --exclusive --timeout 10 200
+
+ # Append the post-receive information to the queue file
+ echo "$1 $2 $3" >> $QUEUE_FILE
+
+ # Make sure to unlock the file when the command is aborted
+ trap 'flock --unlock 200' INT TERM EXIT
+) 200>$LOCK_FILE
+
+# echo "$1 $2 $3" | $mydir/git_buildbot.py > /dev/null
diff --git a/hooks/post-update-02-buildbot b/hooks/post-update-02-buildbot
new file mode 100755
index 0000000..2cba543
--- /dev/null
+++ b/hooks/post-update-02-buildbot
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+QUEUE_FILE=/var/spool/git-buildbot-updates
+LOCK_FILE=/var/spool/.git-buildbot-updates-lock
+
+if echo $0 | grep -q '^/'; then
+ mydir=`dirname $0`
+else
+ mydir=`pwd`/`dirname $0`
+fi
+
+(
+ # Obtain a shared lock for reading from the queue file
+ flock --shared --timeout 10 200
+
+ # Read the post-receive information from the file step by
+ # step and let the buildbot know about it
+ cat $QUEUE_FILE | while read P1 P2 P3; do
+ echo "$P1 $P2 $P3" | $mydir/git_buildbot.py
+ done
+
+ # Make sure to unlock the file when the command is aborted
+ trap 'flock --unlock 200' INT TERM EXIT
+) 200>$LOCK_FILE
diff --git a/post-receive b/post-receive
index cb15993..06041a3 100755
--- a/post-receive
+++ b/post-receive
@@ -2,8 +2,6 @@
XFCE_GIT_HOOK_DIR="/usr/local/share/xfce-git-hooks"
-XFCE_GIT_HOOK_DIR="/usr/local/share/xfce-git-hooks"
-
if [ -z "$GIT_DIR" ]; then
echo "GIT_DIR is unset!" >&2
exit 1
@@ -15,6 +13,5 @@ export REPO="`basename $parent`/`basename $path`"
unset parent path
while read oldrev newrev refname; do
- $XFCE_GIT_HOOK_DIR/hooks/post-receive-01-buildbot \
- "$oldrev" "$newrev" "$refname"
+ $XFCE_GIT_HOOK_DIR/hooks/post-receive-01-buildbot "$oldrev" "$newrev" "$refname"
done
diff --git a/post-update b/post-update
index daaf191..92a20ed 100755
--- a/post-update
+++ b/post-update
@@ -2,4 +2,15 @@
XFCE_GIT_HOOK_DIR="/usr/local/share/xfce-git-hooks"
+if [ -z "$GIT_DIR" ]; then
+ echo "GIT_DIR is unset!" >&2
+ exit 1
+fi
+
+[[ "$GIT_DIR" = "." ]] && path="`pwd`" || path="$GIT_DIR"
+parent="`dirname $path`"
+export REPO="`basename $parent`/`basename $path`"
+unset parent path
+
$XFCE_GIT_HOOK_DIR/hooks/post-update-01-server-info
+$XFCE_GIT_HOOK_DIR/hooks/post-update-02-buildbot
More information about the Xfce4-commits
mailing list