Last active
November 8, 2021 12:16
-
-
Save DanielCardonaRojas/d8d8d34304856c850ce5179fc90559ff to your computer and use it in GitHub Desktop.
githooks for flutter development
This file contains hidden or 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/sh | |
if ! head -1 "$1" | grep -qE "^(feat|fix|chore|docs|test|style|refactor|perf|build|ci|revert)(\(.+?\))?: .{1,}$"; then | |
echo "Aborting commit. Your commit message is invalid." >&2 | |
exit 1 | |
fi | |
if ! head -1 "$1" | grep -qE "^.{1,88}$"; then | |
echo "Aborting commit. Your commit message is too long." >&2 | |
exit 1 | |
fi | |
# echo "$(cat $1)" | commitlint |
This file contains hidden or 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 | |
trap 'exit 130' INT | |
staged_files=$(git --no-pager diff --cached --name-only --diff-filter=M) | |
git_grep=$(git --no-pager grep -l -E --cached "path:\s+\.\.\/\.\.\/" $staged_files) | |
if match=$git_grep && echo $git_grep | grep -q "pubspec"; then | |
echo "Please remove local dependencies in $match" | |
exit 1 | |
fi | |
set -e | |
directories=$(git --no-pager diff --cached --dirstat=cumulative,0 | awk '{print $2}' | cut -d "/" -f1 | uniq) | |
for dir in $directories; do | |
if [ -f "$dir/analysis_options.yaml" ]; then | |
(cd $dir && flutter analyze) | |
fi | |
done |
This file contains hidden or 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 | |
set -e | |
trap 'exit 130' INT | |
directories=$(git --no-pager diff HEAD~1 --cached --dirstat=cumulative | awk '{print $2}' | cut -d "/" -f1 | uniq) | |
for dir in $directories; do | |
if [ -d "./$dir/test" ]; then | |
echo "Testing $dir..." | |
(cd $dir && flutter test) | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For mono repos with multiple packages inside
rename these by removing
.sh
extension and put in .githooks folder