mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-09 08:04:45 +00:00
fix(hooks): treat Gradle distribution download failure as infra skip
The pre-push spotless gate already skips itself (warn + exit 0) when `./gradlew spotlessApply` fails for infra reasons, so a restricted sandbox can't strand a push over formatting. But its detection regex only covered dependency-resolution/network errors, not the case where the Gradle wrapper can't download the pinned distribution itself — e.g. an egress-proxy 40x on `gradle-<ver>-bin.zip`. That surfaced as a hard BLOCK on an XML-only change even though CI's spotlessCheck would pass. Add the distribution-bootstrap markers (the `gradle-<ver>-bin.zip` URL, the Java `Server returned HTTP response code` download exception, and "could not install gradle") to the infra-skip regex. These strings only appear when gradlew failed before running any task, so they can't mask a real formatting/compile failure (verified: a spotlessKotlinCheck violation still blocks). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0157AWJNEzybTuegstbWiQ6B
This commit is contained in:
@@ -64,9 +64,13 @@ before="$(git diff HEAD -- '*.kt' '*.kts' 2>/dev/null | sha1sum)"
|
||||
log="$(mktemp /tmp/spotless-gate.XXXXXX.log)"
|
||||
if ! ./gradlew spotlessApply >"$log" 2>&1; then
|
||||
# Distinguish a formatting failure (block) from Gradle being unable to RUN —
|
||||
# e.g. deps can't resolve in a restricted sandbox. An infra failure must not
|
||||
# strand the agent; warn and let CI's spotlessCheck be the backstop.
|
||||
if grep -qiE "could not resolve|could not (get|download)|handshake|connect timed out|no address|unable to (find|resolve) host|read timed out" "$log"; then
|
||||
# e.g. deps can't resolve, or the wrapper can't even download the Gradle
|
||||
# distribution, in a restricted sandbox. An infra failure must not strand the
|
||||
# agent; warn and let CI's spotlessCheck be the backstop. The distribution
|
||||
# patterns (the `gradle-<ver>-bin.zip` URL, the Java download exception, and a
|
||||
# proxy 40x on that fetch) only appear when `./gradlew` failed *before* running
|
||||
# any task, so they can't mask a real formatting/compile error.
|
||||
if grep -qiE "could not resolve|could not (get|download)|handshake|connect timed out|no address|unable to (find|resolve) host|read timed out|server returned http response code|gradle-[0-9][0-9.]*-(bin|all)\.zip|could not install gradle" "$log"; then
|
||||
echo "WARN: could not run spotlessApply (Gradle infra/network failure), skipping the formatting gate." >&2
|
||||
echo " CI's spotlessCheck still enforces formatting on the PR." >&2
|
||||
rm -f "$log"
|
||||
|
||||
Reference in New Issue
Block a user