git fetch is basically just one string comparison if there are no new commits [0], I don’t think it’s as costly as you make it sound.
#!/bin/sh
BUILDDIR=/home/buildhook/.ib-build
BUILD=`grep build |cut -d" " -f2`
if [ -n "$BUILD" ]
then
touch $BUILDDIR/$BUILD
fi
And then the buildhook user has a job that runs every minute by cron: #!/bin/sh
BUILDDIR=/home/buildhook/.ib-build
BUILD=`ls -t $BUILDDIR | head -1`
if [ -n "$BUILD" ]
then
rm -f $BUILDDIR/$BUILD
(
echo Building $BUILD on builder...
ssh builder time ./build $BUILD
) 2>&1 | mail -s "Building $BUILD on builder" build@example.com
fi
For my use case, on this repo, pushing to a branch with the word "build" in its name will trigger a build of that commit, which builds and packages it into a dpkg, and the build server hosts a private apt repository so I can just `apt-get update; apt-get install blah` on all the servers.An alternative strategy is pushing to a different repo on a build server, etc.
If you want to use a callback for this I'd recommend still polling periodically anyway.