mirror of
https://github.com/quadratic-gardens/qfi.git
synced 2026-01-10 06:28:12 -05:00
Merge pull request #141 from quadratic-funding/fix-hook
Fix unable to run pre-commit hook in Ubuntu
This commit is contained in:
@@ -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
32
.husky/scripts/_pre-commit
Executable 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
|
||||
Reference in New Issue
Block a user