forked from digital-asset/daml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
precommit: add check for modified files under packages with `main-onl…
…y` targets. (digital-asset#17993) Since digital-asset#17989 A simple heuristic to remind you to consider adding `run-all-tests: true` to your commit message if making changes in corners of the codebase most likely affected.
- Loading branch information
1 parent
4794454
commit 51bf3da
Showing
2 changed files
with
37 additions
and
0 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,30 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Checks whether any of the modified files sit under packages with targets marked as 'main-only'. | ||
# | ||
# This is as intended a simple heuristic to avoid accidentally omitting 'run-all-tests: true' | ||
# on a PR branch which touches those files. | ||
# | ||
|
||
DADE_SKIP_MAIN_ONLY_CHECK="${DADE_SKIP_MAIN_ONLY_CHECK:-$(git log -1 --format=%b | tr -d ' ' | grep '^run-all-tests:true$')}" | ||
if [[ -n "$DADE_SKIP_MAIN_ONLY_CHECK" ]]; then | ||
# The user has been explicit about whether they want all tests run, | ||
# either by setting the env var, or adding a line to their last commit. | ||
exit 0; | ||
fi | ||
|
||
MODIFIED_FILES=$(echo "$@" | xargs -n1 | sort) | ||
MAIN_ONLY_DIRS=$(bazel query "attr(tags, 'main-only', //...)" 2>/dev/null | awk -F: '{print $1}' | sort -u | sed -e 's|^//||') | ||
|
||
# Does a cartesian product of the main-only dirs and modified files, and filters to files that are within dir. | ||
SUSPECT_FILES=$(join -j99 <(echo "$MAIN_ONLY_DIRS") <(echo "$MODIFIED_FILES") | awk '$1 == substr($2, 1, length($1)) {print $2}') | ||
|
||
if [[ -n "$SUSPECT_FILES" ]]; then | ||
echo " | ||
The following modified files sit under a directory with 'main-only' targets: | ||
$SUSPECT_FILES | ||
Consider putting a line with 'run-all-tests: true' in your PR description, or \`export DADE_SKIP_MAIN_ONLY_CHECK=1\` and try again. | ||
" >&2 | ||
exit 1 | ||
fi |