Skip to content

Instantly share code, notes, and snippets.

@dgageot
Created February 9, 2011 12:44
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgageot/818406 to your computer and use it in GitHub Desktop.
Save dgageot/818406 to your computer and use it in GitHub Desktop.
Server-less continuous integration
#!/bin/bash
function alert_user {
echo "${1}"
if [ ! -z `which growlnotify` ]; then
growlnotify `basename $0` -m "${1}"
fi
}
function exit_ko {
alert_user "${1}"
if [ "$1" != "no-push" ]; then
oreilles_push "10" "0"
fi
exit 1
}
function exit_ok {
alert_user "${1}"; oreilles_push "0" "0"; exit 0
}
function oreilles_push {
if [ ! -z `which wget` ]; then
wget --timeout=5 --tries=1 -q -O /dev/null "http://api.nabaztag.com/vl/FR/api.jsp?sn=XXXXXXXXXXXXX&token=XXXXXXXX&ear=ok&posright=${1}&posleft=${2}"
fi
}
if [ "$1" != "no-push" ]; then
oreilles_push "10" "10"
fi
PROJECT_DIR=$(pwd)
BRANCH=$(git branch --no-color | awk '$1=="*" {print $2}')
ORIGIN=$(git remote -v | awk '$1=="origin" && $3=="(push)" {print $2}')
git fetch
git add -A; git ls-files --deleted -z | xargs -0 -I {} git rm {}; git commit -m "wip"
git rebase origin/${BRANCH}
if [ "$?" -ne 0 ]
then
git rebase --abort
git log -n 1 | grep -q -c "wip" && git reset HEAD~1
exit_ko "Unable to rebase. please pull or rebase and fix conflicts manually."
fi
git log -n 1 | grep -q -c "wip" && git reset HEAD~1
rm -Rf ../privatebuild
git clone -slb "${BRANCH}" . ../privatebuild
cd ../privatebuild
export MAVEN_OPTS="-Xmx2G -XX:MaxPermSize=1G"
mvn -T4 install -PfullPackage
BUILD_RESULT=$?
if [ "$1" == "no-push" ]; then
alert_user "Not publishing, as per the no-push option"; exit 0
fi
if [ $BUILD_RESULT -ne 0 ]; then
exit_ko "Unable to build"
fi
git push $ORIGIN $BRANCH
if [ $? -ne 0 ]; then
exit_ko "Unable to push"
fi
cd ${PROJECT_DIR} && git fetch
exit_ok "Yet another successful push!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment