Created
July 8, 2021 12:49
-
-
Save mnojek/79622528283d4dfc5dfee9fc3349a7fc to your computer and use it in GitHub Desktop.
Robot Framework and Python syntax git pre-commit hook
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 | |
# this hook checks quality of Robot Framework and Python files | |
# it runs only on changed and staged files with specific extensions | |
# any issue that is found will be notified and will block the commit | |
syntax_fail=false | |
while read file; do | |
# do a check only on the robot files | |
if [[ "$file" =~ (.robot|.resource)$ ]]; then | |
robocop=$(robocop "$file") | |
status=$? | |
if [ $status -ne 0 ]; then | |
echo "Robot Framework syntax check failed for file: $file" | |
syntax_fail=true | |
fi | |
fi | |
# do a check only on the python files | |
if [[ "$file" =~ (.py)$ ]]; then | |
pylama=$(pylama "$file") | |
status=$? | |
if [ $status -ne 0 ]; then | |
echo "Python syntax check failed for file: $file" | |
syntax_fail=true | |
fi | |
fi | |
# only check files that are staged and Added, Copied or Modified | |
done < <(git diff --cached --name-only --diff-filter=ACM) | |
# if any issue was found, the commit will be blocked | |
if [ "$syntax_fail" = true ]; then | |
echo "Fix found issues before committing" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment