Created
March 19, 2018 23:41
-
-
Save bspaulding/5d1481552273dd269f7b16dcdcfbb522 to your computer and use it in GitHub Desktop.
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
#!/bin/sh | |
## React Native pre-push hook | |
## -------------------------- | |
## Requires: | |
## - concurrently from npm | |
## - assumes you have test:ios and test:android tasks setup for any native unit tests | |
remote="$1" | |
url="$2" | |
z40=0000000000000000000000000000000000000000 | |
if [ "$SKIP_CHECKS" = "true" ] | |
then | |
exit 0 | |
fi | |
if [ -z "$COMPARE_SHA" ] | |
then | |
COMPARE_SHA=master | |
fi | |
# https://stackoverflow.com/questions/1527049/join-elements-of-an-array | |
function join { local d=$1; shift; echo -n "$1"; shift; printf "%s" "${@/#/$d}"; } | |
while read local_ref local_sha remote_ref remote_sha | |
do | |
if [ "$local_sha" = $z40 ] | |
then | |
# Handle delete | |
: | |
else | |
declare -a CHECK_CMDS | |
if [ "$(git diff $COMPARE_SHA -- src)" != "" ] | |
then | |
echo "JS changed..." | |
CHECK_CMDS+=("flow" "yarn run lint" "jest --silent --coverage --bail") | |
fi | |
if [ "$(git diff $COMPARE_SHA -- ios)" != "" ] | |
then | |
echo "iOS changed..." | |
CHECK_CMDS+=("yarn run test:ios") | |
fi | |
if [ "$(git diff $COMPARE_SHA -- android)" != "" ] | |
then | |
echo "Android changed..." | |
CHECK_CMDS+=("yarn run test:android") | |
fi | |
cmdstr=$(printf '"%s" ' "${CHECK_CMDS[@]}") | |
eval concurrently --kill-others-on-fail $cmdstr | |
if [ $? -ne 0 ]; then | |
exit 1 | |
fi | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment