Last active
May 15, 2020 16:24
-
-
Save mslattery-lilly/e7c34d0ff21204d62912269fa087f7e8 to your computer and use it in GitHub Desktop.
Build on commit.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# A poor man's CI server for gradle jobs. | |
# PUt in root directory of project. | |
# If GIT_URL is set, it will clone for you. | |
# Will speak and display pop up on build status change. | |
set -eu | |
INTERVAL=60 | |
GIT_URL='' | |
BRANCH='develop' | |
TASK='test' | |
lastsuccessful=true | |
init() { | |
if [[ -n "$GIT_URL" ]] && ! [[ -d .git ]]; then | |
git init | |
git remote add origin "$GIT_URL" | |
git pull origin "$BRANCH" | |
fi | |
} | |
build() { | |
commit="$(git rev-parse --short HEAD)" | |
result=0 | |
if ! nice -n 12 ./gradlew "$TASK" --no-daemon > "gradle-${commit}.log" 2>&1; then | |
grep -i failed "gradle-${commit}.log" | |
result=1 | |
fi | |
return "$result" | |
} | |
alert() { | |
zenity --error --text "$(date +%T) $1" & | |
#notify-send "$1" | |
speak-ng "$1" | |
echo "$(date +%T) $1" | tee -a ci.log | |
} | |
loop() { | |
git checkout "$BRANCH" | |
lastcommit="$(git rev-parse --short HEAD)" | |
while true; do | |
git checkout "$BRANCH" | |
git pull -q --all | |
commit="$(git log --branches --remotes --pretty=format:%h -1)" | |
if [[ "$lastcommit" != "$commit" ]]; then | |
echo "$(date +%T) lastsuccessful=$lastsuccessful $commit" | |
git --no-pager log --oneline "${lastcommit}..${commit}" --graph | |
if "$lastsuccessful" && ! build; then | |
alert "Build failed" | |
lastsuccessful=false | |
elif ! "$lastsuccessful" && build; then | |
alert "Build successful" | |
lastsuccessful=true | |
fi | |
echo "$(date +%T) done." | |
fi | |
lastcommit="$commit" | |
sleep "$INTERVAL" | |
done | |
} | |
main() { | |
init | |
loop | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment