Skip to content

Instantly share code, notes, and snippets.

@mnojek
Last active July 8, 2021 12:59
Show Gist options
  • Save mnojek/df27843872d936bea50a87980549b715 to your computer and use it in GitHub Desktop.
Save mnojek/df27843872d936bea50a87980549b715 to your computer and use it in GitHub Desktop.
Robot Framework syntax Git pre-commit hook
#!/bin/bash
# this hook checks quality of Robot Framework files using Robocop linter tool
# it runs only on changed and staged files with .robot or .resource extension
# any issue that is found will be notified and will block the commit operation
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"
exit 1
fi
fi
# only check files that are staged
done < <(git diff --cached --name-only --diff-filter=ACM)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment