Last active
December 11, 2017 16:11
-
-
Save maugre/e39f965689abe264ec7f164c5cb3f268 to your computer and use it in GitHub Desktop.
Rebuild a Go project when a code change is detected.
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
#!/usr/bin/env bash | |
P=`pwd` | |
BUILDNAME=/tmp/${P##*/}-build | |
function goRun() { | |
echo "-- Building..." | |
## Build new binary | |
go build -i -o $BUILDNAME ./cmd/frontend/*.go | |
## Kill previous and run new binary | |
if [[ $? -eq 0 ]]; | |
then | |
killall -q ${BUILDNAME##*/} | |
$BUILDNAME & | |
VAR=$! | |
echo "Started process" $VAR | |
fi | |
} | |
while true | |
do | |
goRun | |
## Wait | |
inotifywait -qre close_write,modify,move --include '[.*](go|tpl)$' . | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment