mirror of
https://github.com/mandiant/capa.git
synced 2025-12-22 07:10:29 -08:00
Add hooks for running linters and tests
Add the `scripts/setup-hooks.sh` script which sets the following hooks up: - The `post-commit` hook runs the linter after every `git commit`, letting you know if there are code style or rule linter offenses you need to fix. - The `pre-push` hook runs the linter and the tests and block the `git push` if they do not succeed. This way you realise if everything is alright without the need of sending a PR.
This commit is contained in:
34
scripts/hooks/post-commit
Executable file
34
scripts/hooks/post-commit
Executable file
@@ -0,0 +1,34 @@
|
||||
|
||||
# Use a console with emojis support for a better experience
|
||||
|
||||
# Stash uncommited changes
|
||||
MSG="post-commit-$(date +%s)"
|
||||
git stash push -kqum $MSG
|
||||
STASH_LIST=$(git stash list)
|
||||
if [[ "$STASH_LIST" == *"$MSG"* ]]; then
|
||||
echo "Uncommited changes stashed with message '$MSG', if you abort before they are restored run \`git stash pop\`"
|
||||
fi
|
||||
|
||||
# Run style checker and print state (it doesn't block the commit)
|
||||
pycodestyle --config=./ci/tox.ini ./capa/ > style-checker-output.log 2>&1
|
||||
if [ $? == 0 ]; then
|
||||
echo 'Style checker succeeds!! 💘'
|
||||
else
|
||||
echo 'Style checker failed 😭\nCheck style-checker-output.log for details'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Run rule linter and print state (it doesn't block the commit)
|
||||
python ./scripts/lint.py ./rules/ > rule-linter-output.log 2>&1
|
||||
if [ $? == 0 ]; then
|
||||
echo 'Rule linter succeeds!! 💖'
|
||||
else
|
||||
echo 'Rule linter failed 😭\nCheck rule-linter-output.log for details'
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# Restore stashed changes
|
||||
if [[ "$STASH_LIST" == *"$MSG"* ]]; then
|
||||
git stash pop -q --index
|
||||
echo "Stashed changes '$MSG' restored"
|
||||
fi
|
||||
Reference in New Issue
Block a user