-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #141 from quadratic-funding/fix-hook
Fix unable to run pre-commit hook in Ubuntu
- Loading branch information
Showing
2 changed files
with
35 additions
and
34 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 "$?" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |