Skip to content

Commit e7db5c6

Browse files
authored
Make run_spotless.sh more verbose and strict (#2485)
Some developers ran into issues with spotless-fmt skipping formatting silently on their local machines and then failing in CI. This PR now fails if there are any modified Java files and prints a warning if there are no changed Java files and Maven is not present. Follow-up for #2361 Authors: - Igor Motov (https://github.com/imotov) Approvers: - James Lamb (https://github.com/jameslamb) URL: #2485
1 parent 42de42a commit e7db5c6

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ repos:
100100
files: ^java/(cuvs-java|cuvs-lucene)/([^/]+/)?src/.*\.java$
101101
exclude: .*/panama/.*
102102
language: script
103+
verbose: true
103104
- id: clang-format-with-cmake-placeholders
104105
name: clang-format-with-cmake-placeholders
105106
entry: python3 ci/checks/clang_format_with_cmake_placeholders.py

ci/checks/run_spotless.sh

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,36 @@
55
# pre-commit hook wrapper that runs 'spotless:apply' to format the Java sources of every Maven
66
# project under java/.
77
#
8-
# Most cuvs contributors do not work on the Java client and do not have Maven installed. For them
9-
# (running outside CI without Maven) this skips gracefully, so that 'pre-commit run --all-files'
10-
# does not require every contributor to install Maven. In CI, Maven is expected to be available and
11-
# its absence is treated as an error.
8+
# Most cuvs contributors do not work on the Java client and do not have Maven installed. For them,
9+
# running 'pre-commit run --all-files' matches every Java source file in the repo regardless of
10+
# whether they touched any of it, so this skips gracefully when Maven is missing and there are no
11+
# actual local changes to Java sources. In CI, and for anyone who has actually modified Java
12+
# sources locally, Maven is expected to be available and its absence is treated as an error.
1213

1314
set -euo pipefail
1415

16+
# Keep these in sync with the spotless-fmt hook's 'files'/'exclude' entries in
17+
# .pre-commit-config.yaml.
18+
JAVA_SRC_PATTERN='^java/(cuvs-java|cuvs-lucene)/([^/]+/)?src/.*\.java$'
19+
JAVA_SRC_EXCLUDE='.*/panama/.*'
20+
21+
java_sources_modified() {
22+
git status --porcelain --untracked-files=all -- java/cuvs-java java/cuvs-lucene |
23+
cut -c4- |
24+
grep -Ev "${JAVA_SRC_EXCLUDE}" |
25+
grep -Eq "${JAVA_SRC_PATTERN}"
26+
}
27+
1528
if ! command -v mvn >/dev/null 2>&1; then
1629
if [ "${CI:-false}" = "true" ]; then
1730
echo "spotless-fmt: 'mvn' is required in CI but was not found on PATH." >&2
1831
exit 1
1932
fi
20-
echo "spotless-fmt: skipping Java formatting ('mvn' not installed and not running in CI)." >&2
33+
if java_sources_modified; then
34+
echo "spotless-fmt: 'mvn' is required to format modified Java sources but was not found on PATH." >&2
35+
exit 1
36+
fi
37+
echo "spotless-fmt: 'mvn' was not found on PATH and no Java sources were modified, skipping Java formatting." >&2
2138
exit 0
2239
fi
2340

0 commit comments

Comments
 (0)