Last active
December 11, 2020 01:10
-
-
Save michalczukm/d5c7336fd3451b53d48f49d886a87c70 to your computer and use it in GitHub Desktop.
Run linter on git pre-push
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 | |
# add it as `pre-push` file in your repository `.git/hooks folder` | |
# to test it - run `git push --dry-run`, it might be helpful :) | |
echo "============================= pre-push started ============================= " | |
remote="$1" | |
url="$2" | |
z40=0000000000000000000000000000000000000000 | |
actual=`pwd` | |
scripts=() | |
apps=('fe-app-folder-1' 'fe-app-folder-2') | |
for i in "${!apps[@]}" | |
do | |
scripts[$i]="cd $(git rev-parse --show-toplevel)/"${apps[$i]}" && npm run lint && npm run build:prod" | |
done | |
while read local_ref local_sha remote_ref remote_sha | |
do | |
if [ "$local_sha" = $z40 ] | |
then | |
: | |
else | |
range="$remote_sha..$local_sha" | |
if [ "$remote_sha" = $z40 ] || [ -n "$range" ]; then | |
for script in "${scripts[@]}" | |
do | |
eval "$script" | |
done | |
if [ $? -ne 0 ]; then | |
printf "\n\nLinter failed :( \t when running: $script)\n" | |
exit 1 | |
fi | |
fi | |
fi | |
done | |
echo "============================= pre-push completed! ============================= " | |
exit 0 |
Updated - for multiple applications checking (with the same commands)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't mind tabs. This gist must really love tabs-8 configuration.