Skip to content

Commit

Permalink
Support using scie-pants in the pre-commit hook. (pantsbuild#18823)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaos authored Apr 25, 2023
1 parent daf9c36 commit 4038a8c
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions build-support/githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

set -e

# If you use the `pants` scie, you may "export _PANTS_PRE_COMMIT_BINARY=pants" in order to use the same bootstrapped
# pants setup for this pre-commit hook as you get from the command line for any other pants command.
: "${_PANTS_PRE_COMMIT_BINARY:=./pants}"

# NB: pre-commit runs in the context of GIT_WORK_TREE, ie: pwd == REPO_ROOT
source build-support/common.sh

Expand All @@ -21,19 +25,19 @@ if git diff "${MERGE_BASE}" --name-only | grep '\.rs$' > /dev/null; then
fi

echo "* Typechecking"
./pants --changed-since="${MERGE_BASE}" --changed-dependents=transitive check
$_PANTS_PRE_COMMIT_BINARY --changed-since="${MERGE_BASE}" --changed-dependents=transitive check

echo "* Checking linters, formatters, and headers"
./pants --changed-since="${MERGE_BASE}" lint ||
die "If there were formatting errors, run \`./pants --changed-since=$(git rev-parse --symbolic "${MERGE_BASE}") fmt\`"
$_PANTS_PRE_COMMIT_BINARY --changed-since="${MERGE_BASE}" lint ||
die "If there were formatting errors, run \`$_PANTS_PRE_COMMIT_BINARY --changed-since=$(git rev-parse --symbolic "${MERGE_BASE}") fmt\`"

if git diff "${MERGE_BASE}" --name-only | grep build-support/bin/generate_github_workflows.py > /dev/null; then
echo "* Checking GitHub workflows generation"
./pants run build-support/bin/generate_github_workflows.py -- --check
$_PANTS_PRE_COMMIT_BINARY run build-support/bin/generate_github_workflows.py -- --check
fi

echo "* Checking __init__.py files"
./pants run build-support/bin/check_inits.py
$_PANTS_PRE_COMMIT_BINARY run build-support/bin/check_inits.py

echo "* Checking for banned imports"
./pants run build-support/bin/check_banned_imports.py
$_PANTS_PRE_COMMIT_BINARY run build-support/bin/check_banned_imports.py

0 comments on commit 4038a8c

Please sign in to comment.