Skip to content

Instantly share code, notes, and snippets.

@michalczukm
Last active December 11, 2020 01:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michalczukm/d5c7336fd3451b53d48f49d886a87c70 to your computer and use it in GitHub Desktop.
Save michalczukm/d5c7336fd3451b53d48f49d886a87c70 to your computer and use it in GitHub Desktop.
Run linter on git pre-push
#!/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
@michalczukm
Copy link
Author

Don't mind tabs. This gist must really love tabs-8 configuration.

@michalczukm
Copy link
Author

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