-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add pre-push hook to verify formatting (#29)
- Loading branch information
Showing
5 changed files
with
69 additions
and
2 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
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 @@ | ||
.bin |
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
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,49 @@ | ||
#!/usr/bin/sh | ||
|
||
echo "checking formatting with stylua." | ||
echo "use NO_VERIFY=1 or --no-verify to skip pre-push check" | ||
echo "" | ||
|
||
# Get the version defined in the CI stylua check config | ||
STYLUA_VERSION="$(awk '/rev:/ {print $2;}' .pre-commit-config.yaml)" | ||
|
||
# Use stylua installed on the $PATH if exists | ||
STYLUA_BIN="$(which stylua 2>/dev/null)" | ||
|
||
|
||
if [ ! "$STYLUA_BIN" ]; then | ||
# There may already be a stylua in .bin from a prior run | ||
if [ -d .bin/ ] && [ -f .bin/stylua ]; then | ||
echo "found stylua in .bin/" | ||
echo "" | ||
STYLUA_BIN=".bin/stylua" | ||
else | ||
echo "stylua must be installed. ${STYLUA_VERSION} is used by this repo." | ||
echo "attempt to download and install it? y/N" | ||
read -r input | ||
if [ "$input" = 'y' ]; then | ||
mkdir .bin/ | ||
wget -O .bin/stylua.zip "https://github.com/JohnnyMorganz/StyLua/releases/download/$STYLUA_VERSION/stylua-linux.zip" | ||
cd .bin || exit 1 | ||
unzip stylua.zip 1>/dev/null && rm stylua.zip | ||
cd .. || exit 1 | ||
STYLUA_BIN=".bin/stylua" | ||
else | ||
exit 1 | ||
fi | ||
fi | ||
elif [ "$($STYLUA_BIN --version)" != "$STYLUA_VERSION" ]; then | ||
echo "repo uses stylua $STYLUA_VERSION, but $($STYLUA_BIN --version) was found on PATH." | ||
echo "this may cause discrepancies with the CI check." | ||
echo "continuing anyway..." | ||
echo "" | ||
fi | ||
|
||
# Use stylua to check formatting; disallow push on fail | ||
CHECK_OUTPUT="$($STYLUA_BIN --check ./)" | ||
if [ "$CHECK_OUTPUT" ]; then | ||
echo "run 'stylua ./' before pushing" | ||
echo "$CHECK_OUTPUT" | ||
exit 1 | ||
fi | ||
exit 0 |
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,16 @@ | ||
#!/usr/bin/sh | ||
|
||
if [ ! -d .git ]; then | ||
echo "not in a git-managed repo." | ||
exit 1 | ||
fi | ||
|
||
mkdir -p .git/hooks | ||
if [ -f .git/hooks/pre-push ]; then | ||
echo "pre-push hook already exists in this repo." | ||
echo "consider manually merging your custom hook with the one defined here." | ||
exit 1 | ||
fi | ||
|
||
cp tools/hooks/pre-push .git/hooks/ || exit 1 | ||
exit 0 |