Merge pull request #141 from quadratic-funding/fix-hook

Fix unable to run pre-commit hook in Ubuntu
This commit is contained in:
daodesigner
2022-06-23 09:15:22 -07:00
committed by GitHub
2 changed files with 35 additions and 34 deletions

View File

@@ -1,37 +1,6 @@
#!/bin/sh
BASE_DIR="$( cd "$( dirname "$0" )" && pwd )"
# Return `true` if files under `packages/contracts/contracts/` directory has been changed or added. Otherwise, return `false`
is_contracts_changed()
{
result="false"
git_changes=$(git diff --cached --name-status)
while read -r line; do
changed_file_path=$(echo "$line" | awk '/packages/ {print $2}')
file_status=$(echo "$line" | cut -c 1)
if [ "$file_status" = 'A' ] || [ "$file_status" = 'M' ]
then
case $changed_file_path in packages/contracts/contracts/*)
result="true"
esac
fi
done <<< "$git_changes"
echo "$result"
}
. "$(dirname "$0")/_/husky.sh"
# Check lint for all subpackage
npx lint-staged
RETURN_CODE=$(is_contracts_changed)
if [ $RETURN_CODE = "true" ]; then
# Run contract tests
npx yarn workspace @quadratic-funding/contracts typechain
npx yarn workspace @quadratic-funding/contracts test:unit
fi
bash "$BASE_DIR"/scripts/_pre-commit
exit "$?"

32
.husky/scripts/_pre-commit Executable file
View File

@@ -0,0 +1,32 @@
#!/bin/bash
# Return `true` if files under `packages/contracts/contracts/` directory has been changed or added. Otherwise, return `false`
is_contracts_changed()
{
result="false"
git_changes=$(git diff --cached --name-status)
while read -r line; do
changed_file_path=$(echo "$line" | awk '/packages/ {print $2}')
file_status=$(echo "$line" | cut -c 1)
if [ "$file_status" = 'A' ] || [ "$file_status" = 'M' ]
then
case $changed_file_path in packages/contracts/contracts/*)
result="true"
esac
fi
done <<< "$git_changes"
echo "$result"
}
# Check lint for all subpackage
npx lint-staged
RETURN_CODE=$(is_contracts_changed)
if [ $RETURN_CODE = "true" ]; then
# Run contract tests
npx yarn workspace @quadratic-funding/contracts typechain
npx yarn workspace @quadratic-funding/contracts test:unit
fi