-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
|
||
# flags: | ||
# -s = script name | ||
# -n = how many times to retry | ||
# -r (optional) = run git reset in between retries | ||
|
||
# usage example: | ||
# ./retry-command.sh -s lint -n 5 | ||
# ./retry-command.sh -s publish:local -n 3 -r true | ||
|
||
while getopts s:n:r: option | ||
do | ||
case "${option}" | ||
in | ||
s) SCRIPT=${OPTARG};; | ||
n) N=${OPTARG};; | ||
r) GIT_RESET=${OPTARG};; | ||
esac | ||
done | ||
|
||
# initialize counter | ||
n=0 | ||
# loop until n > first param | ||
until [ "$n" -gt $N ] | ||
do | ||
# $1 is the argument passed in, e.g. publish:local | ||
# if the publish command succeeds, `break` exits the loop | ||
npm run $SCRIPT && break | ||
|
||
if [[ $GIT_RESET ]] | ||
then | ||
# reset git HEAD (remove the package.json changes made by lerna) | ||
echo "Resetting git HEAD" | ||
git reset --hard | ||
fi | ||
|
||
if [ "$n" -eq $N ]; | ||
then | ||
echo "Returning error" | ||
exit 1 | ||
fi | ||
|
||
# increment counter | ||
n=$((n+1)) | ||
|
||
# wait 5 seconds | ||
sleep 5 | ||
echo "Retry $n of $N" | ||
done |