Last active
August 29, 2015 14:13
-
-
Save ryanberckmans/f85b5ab93428f92f5a07 to your computer and use it in GitHub Desktop.
"grails test-app" notification with bash and OSX
This file contains hidden or 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
# OSX+bash notifications for "grails test-app" | |
# --- | |
# Pops up an OSX notification with "PASS/FAIL" whenever a "grails test-app" command finishes. | |
# Limitations | |
# --- | |
# Only shows notification if "grails test-app" created a new /target/test-reports/html/all.html | |
# Uses bash history, so it might not work if you have a shell alias for "grails test-app" | |
# Only works for one grails repository at a time. | |
# If you have two repositories simultaneously running "grails test-app", it won't work. | |
# Prepends to PROMPT_COMMAND which may not be compatible with more advanced setups. | |
# Future plans | |
# --- | |
# Detect early build failures, so a notification is popped up when all.html isn't regenerated | |
# create /tmp/grails-notify/all.html to serve as a timestamp since last `grails test-app` | |
# Note - only works for one repo. To make this approach compatible with multiple cloned projects, this file must be unique per clone | |
grails-notify-test-timestamp() { | |
mkdir -p /tmp/grails-notify && touch /tmp/grails-notify/all.html | |
} | |
grails-notify-create-test-app-notification() { | |
TEST_REPORT_FILE="`git rev-parse --show-toplevel 2> /dev/null`/target/test-reports/html/all.html" | |
if [[ "`grep -C5 -m2 -i "executed" $TEST_REPORT_FILE | grep -c "without a single error or failure"`" -gt "0" ]]; then | |
TEST_STATUS="PASS" | |
else | |
TEST_STATUS="FAIL" | |
fi | |
/usr/bin/osascript -e "display notification \"\" with title \"grails test-app $TEST_STATUS\"" | |
} | |
grails-notify() { | |
# git rev-parse --show-toplevel just dumps the root git directory for `pwd`, and 2> /dev/null prevents complaints when not actually in a git repo | |
if [[ "`git rev-parse --show-toplevel 2> /dev/null`/target/test-reports/html/all.html" -nt "/tmp/grails-notify/all.html" ]]; then | |
grails-notify-test-timestamp | |
grails-notify-create-test-app-notification | |
fi | |
} | |
# run grails-notify-test-timestamp on startup, otherwise notification will fire when all.html is first detected | |
grails-notify-test-timestamp | |
# PROMPT_COMMAND is executed after each bash command terminates | |
if [ -z "$PROMPT_COMMAND" ]; then | |
export PROMPT_COMMAND="grails-notify" | |
else | |
export PROMPT_COMMAND="grails-notify && $PROMPT_COMMAND" | |
fi |
This file contains hidden or 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
0. be using OSX and bash shell | |
1. copy .grails-config to your ~ home directory | |
2. in your .bash_profile or .bashrc, source "~/.grails-config" | |
Done! Your "grails test-app" commands should now trigger OSX notifications upon completion. See "Limitations" in .grails-config. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment