From a54ae77e085010ba1ff923c3c36b4693a72b4b91 Mon Sep 17 00:00:00 2001 From: Ben Hook <5009589+benhook1013@users.noreply.github.com> Date: Thu, 15 Oct 2026 17:54:52 +1300 Subject: [PATCH 1/3] Allow jOOQ resolution recovery in CI --- .github/scripts/run-gradle-module-checks.sh | 49 ++++++++ .../gradle-dependency-recovery-contract.sh | 107 ++++++++++++++++++ 2 files changed, 156 insertions(+) diff --git a/.github/scripts/run-gradle-module-checks.sh b/.github/scripts/run-gradle-module-checks.sh index 72b1335dba..72efe50c2a 100644 --- a/.github/scripts/run-gradle-module-checks.sh +++ b/.github/scripts/run-gradle-module-checks.sh @@ -150,6 +150,23 @@ classify_failure_body() { cache_summary++ next } + if (line ~ /^Configuration cache state could not be cached: field `classpath` of `org\.gradle\.process\.internal\.DefaultJavaExecSpec_Decorated` bean found in field `javaExecSpec` of task `:[^`]+:generateJooq` of type `org\.gradle\.api\.tasks\.JavaExec`: error writing value of type \047org\.gradle\.api\.internal\.file\.collections\.DefaultConfigurableFileCollection\047$/) { + if (match(line, /task `:[^`]+:generateJooq`/)) { + task_reference = substr(line, RSTART, RLENGTH) + sub(/^task `/, "", task_reference) + sub(/`$/, "", task_reference) + sub(/:generateJooq$/, "", task_reference) + if (jooq_module != "" && jooq_module != task_reference) { + invalid++ + } + jooq_module = task_reference + } else { + invalid++ + } + jooq_wrapper_causes++ + cache_cause++ + next + } if (line ~ /^Configuration cache state could not be cached: field `classpath` of task `:[^`]+:compile[A-Za-z0-9]+` of type .*JavaCompile.*: error writing value of type .*DefaultResolvableConfiguration/ || line ~ /^- Task `:[^`]+:compile[A-Za-z0-9]+` of type .*JavaCompile.*: error writing value of type .*DefaultResolvableConfiguration/) { if (match(line, /`:[^`]+:compile[A-Za-z0-9]+`/)) { @@ -180,6 +197,25 @@ classify_failure_body() { if (line ~ /(compileClasspath|testCompileClasspath|integrationTestCompileClasspath|crossServiceTestCompileClasspath)/) { compile_classpath_roots++ } + configuration_name = line + sub(/^> Could not resolve all (artifacts|files) for configuration /, "", configuration_name) + sub(/[.]$/, "", configuration_name) + quote = sprintf("%c", 39) + if (substr(configuration_name, 1, 1) == quote) { + configuration_name = substr(configuration_name, 2, length(configuration_name) - 2) + } + if (configuration_name ~ /^:[[:alnum:]-]+:jooqCodegen$/) { + jooq_codegen_roots++ + root_module = configuration_name + sub(/:jooqCodegen$/, "", root_module) + if (jooq_module != "" && jooq_module != root_module) { + invalid++ + } + jooq_root_module = root_module + } + if (jooq_wrapper_causes && configuration_name !~ /^:[[:alnum:]-]+:jooqCodegen$/) { + invalid++ + } next } if (line ~ /^> Could not (find|resolve) [[:alnum:]_.-]+:[[:alnum:]_.-]+:[0-9][[:alnum:]_.-]*\.$/ || @@ -227,6 +263,10 @@ classify_failure_body() { if (invalid || resolver_roots == 0 || coordinates == 0 || (cache_summary && (cache_cause == 0 || cache_cause > 2)) || (compile_task_failure && compile_classpath_roots == 0) || + (jooq_wrapper_causes && + (jooq_wrapper_causes != 1 || jooq_codegen_roots != 1 || resolver_roots != 1 || + cache_cause != 1 || jooq_module == "" || jooq_root_module != jooq_module)) || + (!jooq_wrapper_causes && jooq_codegen_roots) || !((transient && repository_requests) || (searched && repository_urls))) { exit 1 } @@ -250,6 +290,15 @@ is_dependency_resolution_failure() { return 1 fi + if grep -Fq 'DefaultJavaExecSpec_Decorated' "$body_path" && + grep -Fq ':generateJooq' "$body_path" && + grep -Eq '^> Task :[[:alnum:]][[:alnum:]-]*:generateJooq([[:space:]]|$)' "$log_path"; then + # A generateJooq task entry means Gradle started or reused generator work; + # only the classpath/configuration-cache failure before task execution retries. + rm -f -- "$body_path" + return 1 + fi + has_substantive_failure "$log_path" || substantive_status=$? rm -f -- "$body_path" case "$substantive_status" in diff --git a/dev-tools/tests/gradle-dependency-recovery-contract.sh b/dev-tools/tests/gradle-dependency-recovery-contract.sh index 169d533511..faf57d3e7c 100644 --- a/dev-tools/tests/gradle-dependency-recovery-contract.sh +++ b/dev-tools/tests/gradle-dependency-recovery-contract.sh @@ -240,6 +240,113 @@ assert_call 2 "--refresh-dependencies --max-workers=2 -Dorg.gradle.jvmargs=-Xmx2 assert_output_contains "Could not find spring-boot-starter-jdbc-4.1.1.jar (org.springframework.boot:spring-boot-starter-jdbc:4.1.1)." assert_output_contains "refreshed-pinned-artifact-resolved" +# The captured Account failure is a pre-execution JavaExec classpath resolution +# failure wrapped by Gradle's configuration-cache serializer. It may refresh +# only when the wrapper task and jooqCodegen configuration identify the same +# module and the complete fatal cause contains only repository-resolution data. +write_jooq_captured_cause() { + cat > "$CASE_DIR/jooq-cause.log" <<'LOG' +FAILURE: Build failed with an exception. + +* What went wrong: +Configuration cache state could not be cached: field `classpath` of `org.gradle.process.internal.DefaultJavaExecSpec_Decorated` bean found in field `javaExecSpec` of task `:account-service:generateJooq` of type `org.gradle.api.tasks.JavaExec`: error writing value of type 'org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection' +> Could not resolve all files for configuration ':account-service:jooqCodegen'. +> Could not find jooq-codegen-3.21.9.jar (org.jooq:jooq-codegen:3.21.9). +Searched in the following locations: +https://repo.maven.apache.org/maven2/org/jooq/jooq-codegen/3.21.9/jooq-codegen-3.21.9.jar +> Could not find jooq-meta-extensions-3.21.9.jar (org.jooq:jooq-meta-extensions:3.21.9). +Searched in the following locations: +https://repo.maven.apache.org/maven2/org/jooq/jooq-meta-extensions/3.21.9/jooq-meta-extensions-3.21.9.jar +> Could not find jooq-meta-3.21.9.jar (org.jooq:jooq-meta:3.21.9). +Searched in the following locations: +https://repo.maven.apache.org/maven2/org/jooq/jooq-meta/3.21.9/jooq-meta-3.21.9.jar +> Could not find jooq-3.21.9.jar (org.jooq:jooq:3.21.9). +Searched in the following locations: +https://repo.maven.apache.org/maven2/org/jooq/jooq/3.21.9/jooq-3.21.9.jar +> Could not find h2-2.4.240.jar (com.h2database:h2:2.4.240). +Searched in the following locations: +https://repo.maven.apache.org/maven2/com/h2database/h2/2.4.240/h2-2.4.240.jar +> Could not find r2dbc-spi-1.0.0.RELEASE.jar (io.r2dbc:r2dbc-spi:1.0.0.RELEASE). +Searched in the following locations: +https://repo.maven.apache.org/maven2/io/r2dbc/r2dbc-spi/1.0.0.RELEASE/r2dbc-spi-1.0.0.RELEASE.jar +> Could not find jakarta.xml.bind-api-4.0.2.jar (jakarta.xml.bind:jakarta.xml.bind-api:4.0.2). +Searched in the following locations: +https://repo.maven.apache.org/maven2/jakarta/xml/bind/jakarta.xml.bind-api/4.0.2/jakarta.xml.bind-api-4.0.2.jar +> Could not find reactive-streams-1.0.3.jar (org.reactivestreams:reactive-streams:1.0.3). +Searched in the following locations: +https://repo.maven.apache.org/maven2/org/reactivestreams/reactive-streams/1.0.3/reactive-streams-1.0.3.jar +> Could not find jakarta.activation-api-2.1.3.jar (jakarta.activation:jakarta.activation-api:2.1.3). +Searched in the following locations: +https://repo.maven.apache.org/maven2/jakarta/activation/jakarta.activation-api/2.1.3/jakarta.activation-api-2.1.3.jar + +* Try: +> Run with --stacktrace option to get the stack trace. +LOG +} + +write_jooq_wrapper() { + local progress_line="$1" + write_wrapper "if [[ \"\$call_count\" -eq 1 ]]; then + if [[ -n '$progress_line' ]]; then printf '%s\\n' '$progress_line'; fi + cat '$CASE_DIR/jooq-cause.log' + exit 1 +fi +echo refreshed-captured-jooq-resolution; exit 0" +} + +new_case captured-jooq-codegen-resolution +write_jooq_captured_cause +write_jooq_wrapper '' +run_case account-service 0 +assert_call_count 2 +assert_call 1 "--max-workers=2 -Dorg.gradle.jvmargs=-Xmx2500m -Dfile.encoding=UTF-8 :account-service:check -PfullCheck" +assert_call 2 "--refresh-dependencies --max-workers=2 -Dorg.gradle.jvmargs=-Xmx2500m -Dfile.encoding=UTF-8 :account-service:check -PfullCheck" +[[ "$(cat "$CASE_DIR/sleeps")" == 0 ]] || fail "captured jOOQ artifact miss added a transient-error delay" +assert_output_contains "Configuration cache state could not be cached: field \`classpath\` of \`org.gradle.process.internal.DefaultJavaExecSpec_Decorated\`" +assert_output_contains "refreshed-captured-jooq-resolution" + +# A real generator failure is not a dependency failure and must retain its +# original result even though it came from the same JavaExec task. +new_case jooq-codegen-execution-failure +write_wrapper 'cat <<"LOG" +> Task :account-service:generateJooq FAILED +FAILURE: Build failed with an exception. +* What went wrong: +Execution failed for task '\'':account-service:generateJooq'\''. +org.jooq.exception.DataAccessException: Invalid SQL migration syntax. +* Try: +> Run with --stacktrace option to get the stack trace. +BUILD FAILED in 2s +LOG +exit 1' +run_case account-service 1 +assert_no_retry + +# An additional cause in the exact captured shape makes it mixed and therefore +# ineligible, even though its repository-resolution portion would otherwise retry. +new_case captured-jooq-mixed-cause +write_jooq_captured_cause +awk '/^\* Try:$/ { print "Could not create task :account-service:check because of unsupported plugin configuration." } { print }' \ + "$CASE_DIR/jooq-cause.log" > "$CASE_DIR/jooq-mixed-cause.log" +mv "$CASE_DIR/jooq-mixed-cause.log" "$CASE_DIR/jooq-cause.log" +write_jooq_wrapper '' +run_case account-service 1 +assert_no_retry + +# Even the captured resolver/cache wrapper cannot retry after generator work or +# substantive module compilation has started. +new_case jooq-generator-already-started +write_jooq_captured_cause +write_jooq_wrapper '> Task :account-service:generateJooq FROM-CACHE' +run_case account-service 1 +assert_no_retry + +new_case jooq-compile-already-started +write_jooq_captured_cause +write_jooq_wrapper '> Task :account-service:compileJava' +run_case account-service 1 +assert_no_retry + # The resolver retry is bounded and observes a logged numeric Retry-After. new_case http-429 # shellcheck disable=SC2016 From 429f853f55455b134107a2e9a28f53c725ca6ca0 Mon Sep 17 00:00:00 2001 From: Ben Hook <5009589+benhook1013@users.noreply.github.com> Date: Thu, 15 Oct 2026 18:20:06 +1300 Subject: [PATCH 2/3] Share bounded Gradle dependency recovery --- .github/scripts/run-gradle-module-checks.sh | 359 +-------------- .../architecture/system-architecture-cicd.md | 2 +- dev-tools/README.md | 1 + dev-tools/build-compose-service-jars.sh | 3 +- .../gradle-dependency-recovery-contract.sh | 151 +++++- .../run-gradle-with-dependency-recovery.sh | 432 ++++++++++++++++++ 6 files changed, 590 insertions(+), 358 deletions(-) create mode 100644 dev-tools/validation/run-gradle-with-dependency-recovery.sh diff --git a/.github/scripts/run-gradle-module-checks.sh b/.github/scripts/run-gradle-module-checks.sh index 72efe50c2a..8729774acf 100644 --- a/.github/scripts/run-gradle-module-checks.sh +++ b/.github/scripts/run-gradle-module-checks.sh @@ -1,362 +1,17 @@ #!/usr/bin/env bash set -euo pipefail +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" +readonly ROOT_DIR readonly MODULE="${1:-}" if [[ $# -ne 1 || ! "$MODULE" =~ ^[a-z0-9]+(-[a-z0-9]+)*$ ]]; then echo "usage: run-gradle-module-checks.sh " >&2 exit 64 fi -readonly -a CHECK_ARGS=( - --max-workers=2 - '-Dorg.gradle.jvmargs=-Xmx2500m -Dfile.encoding=UTF-8' - ":${MODULE}:check" +bash "$ROOT_DIR/dev-tools/validation/run-gradle-with-dependency-recovery.sh" \ + --runner "$ROOT_DIR/gradlew" -- \ + --max-workers=2 \ + '-Dorg.gradle.jvmargs=-Xmx2500m -Dfile.encoding=UTF-8' \ + ":${MODULE}:check" \ -PfullCheck -) - -readonly TEMP_ROOT="${RUNNER_TEMP:-${TMPDIR:-/tmp}}" -if ! TEMP_DIR="$(mktemp -d "${TEMP_ROOT%/}/firemud-gradle-check.XXXXXX")"; then - echo "unable to create Gradle check log directory" >&2 - exit 125 -fi -readonly TEMP_DIR -readonly NORMAL_LOG="$TEMP_DIR/normal.log" -readonly REFRESH_LOG="$TEMP_DIR/refresh.log" - -# Invoked indirectly by the EXIT trap below. -# shellcheck disable=SC2329 -cleanup() { - rm -f -- "$NORMAL_LOG" "$REFRESH_LOG" - rmdir -- "$TEMP_DIR" -} -trap cleanup EXIT -trap 'exit 130' INT -trap 'exit 143' TERM -trap 'exit 129' HUP - -GRADLE_EXIT=0 -run_gradle_check() { - local refresh="$1" - local log_path="$2" - local -a pipeline_status=() - - set +e - if [[ "$refresh" == true ]]; then - ./gradlew --refresh-dependencies "${CHECK_ARGS[@]}" 2>&1 | tee "$log_path" - else - ./gradlew "${CHECK_ARGS[@]}" 2>&1 | tee "$log_path" - fi - pipeline_status=("${PIPESTATUS[@]}") - set -e - - GRADLE_EXIT="${pipeline_status[0]:-125}" - if [[ "${pipeline_status[1]:-125}" -ne 0 ]]; then - echo "failed to capture complete Gradle output; refusing dependency retry" >&2 - exit 125 - fi -} - -has_substantive_failure() { - local log_path="$1" - - grep -Eq '(^|[[:space:]])(Compilation failed|Compilation error|error:|e: file:|There were failing tests)' "$log_path" && return 0 - - awk ' - /^> Task / { - task = $3 - outcome = $4 - name = task - sub(/^.*:/, "", name) - - is_compile = name ~ /^compile[A-Z][A-Za-z0-9]*$/ - is_test = !is_compile && name ~ /(^|[A-Za-z0-9])(test|Test)[A-Za-z0-9]*$/ - # buildSrc compiles the build logic during Gradle setup, not the target - # module sources whose successful execution must remain unretried. - is_build_logic = task ~ /^:buildSrc(:|$)/ - is_compile = !is_build_logic && is_compile - if (!is_test && !is_compile) { - next - } - - cached_or_skipped = outcome == "FROM-CACHE" || outcome == "UP-TO-DATE" || outcome == "NO-SOURCE" || outcome == "SKIPPED" - if (is_test && !cached_or_skipped) { - found = 1 - } else if (is_compile && outcome != "FAILED" && !cached_or_skipped) { - found = 1 - } - if (is_compile && outcome == "FAILED" && !cached_or_skipped) { - failed_compile = 1 - } - } - END { - if (found) { - exit 0 - } - if (failed_compile) { - exit 2 - } - exit 1 - } - ' "$log_path" - return $? -} - -failure_body() { - local log_path="$1" - - awk ' - /^FAILURE: Build failed with an exception\.$/ { - failures++ - in_failure = 1 - next - } - in_failure && /^\* What went wrong:$/ { - sections++ - in_body = 1 - next - } - in_body && /^\* Try:$/ { - in_body = 0 - ended = 1 - next - } - in_body { - print - } - END { - if (failures != 1 || sections != 1 || !ended || invalid) { - exit 1 - } - } - ' "$log_path" -} - -classify_failure_body() { - local log_path="$1" - - awk ' - function trim(s) { - sub(/^[[:space:]]+/, "", s) - sub(/[[:space:]]+$/, "", s) - return s - } - { - line = trim($0) - if (line == "" || line == "* What went wrong:") { - next - } - - if (line == "1 problem was found storing the configuration cache.") { - cache_summary++ - next - } - if (line ~ /^Configuration cache state could not be cached: field `classpath` of `org\.gradle\.process\.internal\.DefaultJavaExecSpec_Decorated` bean found in field `javaExecSpec` of task `:[^`]+:generateJooq` of type `org\.gradle\.api\.tasks\.JavaExec`: error writing value of type \047org\.gradle\.api\.internal\.file\.collections\.DefaultConfigurableFileCollection\047$/) { - if (match(line, /task `:[^`]+:generateJooq`/)) { - task_reference = substr(line, RSTART, RLENGTH) - sub(/^task `/, "", task_reference) - sub(/`$/, "", task_reference) - sub(/:generateJooq$/, "", task_reference) - if (jooq_module != "" && jooq_module != task_reference) { - invalid++ - } - jooq_module = task_reference - } else { - invalid++ - } - jooq_wrapper_causes++ - cache_cause++ - next - } - if (line ~ /^Configuration cache state could not be cached: field `classpath` of task `:[^`]+:compile[A-Za-z0-9]+` of type .*JavaCompile.*: error writing value of type .*DefaultResolvableConfiguration/ || - line ~ /^- Task `:[^`]+:compile[A-Za-z0-9]+` of type .*JavaCompile.*: error writing value of type .*DefaultResolvableConfiguration/) { - if (match(line, /`:[^`]+:compile[A-Za-z0-9]+`/)) { - task_reference = substr(line, RSTART, RLENGTH) - if (cache_task != "" && cache_task != task_reference) { - invalid++ - } - cache_task = task_reference - } else { - invalid++ - } - cache_cause++ - next - } - if (line ~ /^See the complete report at file:.*configuration-cache\//) { - next - } - if (line ~ /^\[Incubating\] Problems report is available at: file:.*\/build\/reports\/problems\/problems-report\.html$/ || - line == "Deprecated Gradle features were used in this build, making it incompatible with Gradle 10." || - line == "You can use \047--warning-mode all\047 to show the individual deprecation warnings and determine if they come from your own scripts or plugins." || - line == "For more on this, please refer to https://docs.gradle.org/9.8.1/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation." || - line ~ /^[0-9]+ actionable tasks: [0-9]+ executed, [0-9]+ from cache$/) { - next - } - - if (line ~ /^> Could not resolve all (artifacts|files) for configuration .+\.$/) { - resolver_roots++ - if (line ~ /(compileClasspath|testCompileClasspath|integrationTestCompileClasspath|crossServiceTestCompileClasspath)/) { - compile_classpath_roots++ - } - configuration_name = line - sub(/^> Could not resolve all (artifacts|files) for configuration /, "", configuration_name) - sub(/[.]$/, "", configuration_name) - quote = sprintf("%c", 39) - if (substr(configuration_name, 1, 1) == quote) { - configuration_name = substr(configuration_name, 2, length(configuration_name) - 2) - } - if (configuration_name ~ /^:[[:alnum:]-]+:jooqCodegen$/) { - jooq_codegen_roots++ - root_module = configuration_name - sub(/:jooqCodegen$/, "", root_module) - if (jooq_module != "" && jooq_module != root_module) { - invalid++ - } - jooq_root_module = root_module - } - if (jooq_wrapper_causes && configuration_name !~ /^:[[:alnum:]-]+:jooqCodegen$/) { - invalid++ - } - next - } - if (line ~ /^> Could not (find|resolve) [[:alnum:]_.-]+:[[:alnum:]_.-]+:[0-9][[:alnum:]_.-]*\.$/ || - line ~ /^> Could not find [^[:space:]]+ \([[:alnum:]_.-]+:[[:alnum:]_.-]+:[0-9][[:alnum:]_.-]*\)\.$/) { - coordinates++ - next - } - if (line ~ /^> Could not (get resource|GET|HEAD) [\047\042]?https?:\/\// || - line ~ /^> Could not GET https?:\/\//) { - repository_requests++ - next - } - if (line ~ /^Execution failed for task / && line ~ /:compile[A-Za-z0-9]+[\047"][.]$/) { - compile_task_failure++ - next - } - if (line == "Searched in the following locations:" || line ~ /^https?:\/\// || line ~ /^- https?:\/\// || - line == "Required by:" || line ~ /^project / || - line ~ /^> Got socket exception during request\./ || - line ~ /^> Connection (reset|timed out)$/ || - line ~ /^> SocketTimeoutException/ || - line ~ /^Received status code (429|5[0-9][0-9]) from server/ || - line ~ /^Retry-After: .+$/ || - line ~ /^(> )?There are [0-9]+ more failures with identical causes\.$/) { - if (line ~ /^Received status code /) { - transient++ - } - if (line ~ /^> Connection / || line ~ /^> SocketTimeoutException/ || line ~ /^> Got socket exception/) { - transient++ - } - if (line ~ /^Searched in the following locations:/) { - searched++ - } - if (line ~ /^https?:\/\// || line ~ /^- https?:\/\//) { - repository_urls++ - } - next - } - - # Every other line inside the fatal cause body is an additional - # or unknown cause. Do not let matching dependency text elsewhere mask it. - invalid++ - } - END { - if (invalid || resolver_roots == 0 || coordinates == 0 || - (cache_summary && (cache_cause == 0 || cache_cause > 2)) || - (compile_task_failure && compile_classpath_roots == 0) || - (jooq_wrapper_causes && - (jooq_wrapper_causes != 1 || jooq_codegen_roots != 1 || resolver_roots != 1 || - cache_cause != 1 || jooq_module == "" || jooq_root_module != jooq_module)) || - (!jooq_wrapper_causes && jooq_codegen_roots) || - !((transient && repository_requests) || (searched && repository_urls))) { - exit 1 - } - exit 0 - } - ' "$log_path" -} - -is_dependency_resolution_failure() { - local log_path="$1" - local body_path - local substantive_status=0 - - body_path="$(mktemp "${TEMP_DIR%/}/failure-body.XXXXXX")" || return 1 - if ! failure_body "$log_path" > "$body_path"; then - rm -f -- "$body_path" - return 1 - fi - if ! classify_failure_body "$body_path"; then - rm -f -- "$body_path" - return 1 - fi - - if grep -Fq 'DefaultJavaExecSpec_Decorated' "$body_path" && - grep -Fq ':generateJooq' "$body_path" && - grep -Eq '^> Task :[[:alnum:]][[:alnum:]-]*:generateJooq([[:space:]]|$)' "$log_path"; then - # A generateJooq task entry means Gradle started or reused generator work; - # only the classpath/configuration-cache failure before task execution retries. - rm -f -- "$body_path" - return 1 - fi - - has_substantive_failure "$log_path" || substantive_status=$? - rm -f -- "$body_path" - case "$substantive_status" in - 0) return 1 ;; - 1|2) return 0 ;; - *) return 1 ;; - esac -} - -retry_delay_seconds() { - local log_path="$1" - local retry_after - local delay - - retry_after="$(failure_body "$log_path" | sed -nE 's/^.*[Rr]etry-[Aa]fter:[[:space:]]*(.*)$/\1/p')" || return 1 - if [[ -z "$retry_after" ]]; then - if failure_body "$log_path" | grep -Eq 'Connection reset|Connection timed out|SocketTimeoutException|Received status code 429 from server|Received status code 5[0-9][0-9] from server'; then - printf '2\n' - else - printf '0\n' - fi - return 0 - fi - - # Reject date and malformed values; cap raw decimal length before arithmetic, - # strip leading zeroes, and force base ten so values such as 08 stay safe. - [[ "$retry_after" =~ ^[0-9]+$ ]] || return 1 - (( ${#retry_after} <= 16 )) || return 1 - local canonical="${retry_after#"${retry_after%%[!0]*}"}" - [[ -n "$canonical" ]] || canonical=0 - (( ${#canonical} <= 2 )) || return 1 - delay=$((10#$canonical)) - - if (( delay > 30 )); then - echo "Retry-After exceeds the bounded 30-second retry window; preserving original failure" >&2 - return 1 - fi - printf '%s\n' "$delay" -} - -run_gradle_check false "$NORMAL_LOG" -if [[ "$GRADLE_EXIT" -eq 0 ]]; then - exit 0 -fi - -if [[ "$GRADLE_EXIT" -ne 1 ]]; then - exit "$GRADLE_EXIT" -fi - -if ! is_dependency_resolution_failure "$NORMAL_LOG"; then - exit "$GRADLE_EXIT" -fi - -if ! RETRY_DELAY="$(retry_delay_seconds "$NORMAL_LOG")"; then - exit "$GRADLE_EXIT" -fi - -echo "Recognized Gradle dependency-resolution failure before compile/test execution; retrying the complete module check once with dependency metadata refresh after ${RETRY_DELAY}s." -sleep "$RETRY_DELAY" -run_gradle_check true "$REFRESH_LOG" -exit "$GRADLE_EXIT" diff --git a/design/architecture/system-architecture-cicd.md b/design/architecture/system-architecture-cicd.md index 732e53cd0b..283f17cee2 100644 --- a/design/architecture/system-architecture-cicd.md +++ b/design/architecture/system-architecture-cicd.md @@ -105,7 +105,7 @@ The main [`ci.yml`](../../.github/workflows/ci.yml) workflow: - Generates protobuf outputs to keep generated stubs aligned with the checked-in schemas. - Runs formatting and lint steps (Spotless, markdownlint, link checks). - On the complete CI path, executes a matrix of Gradle `check` tasks (one per microservice) with SpotBugs, Checkstyle, and tests enabled; lightweight documentation-only PR validation does not run these service checks. -- Each affected-module check first uses Gradle's restored dependency metadata without a forced refresh. Only a recognized repository-resolution failure before substantive module compilation or test execution receives one retry of the same full check with `--refresh-dependencies`; this preserves recovery from cached negative metadata without revalidating every dependency on every successful matrix job. Compiler and test failures, unrelated configuration errors, interrupted runs, and failures that cannot be classified retain their original failure. +- Affected-module checks and the source-built Compose boot-jar command first use Gradle's restored dependency metadata without a forced refresh. The shared runner gives a fully recognized repository-resolution failure one retry of the same complete Gradle command with `--refresh-dependencies`; successful commands do not revalidate every dependency. The existing pre-substantive compile/test boundary remains. jOOQ also permits only the exact matching `jooqCodegen` classpath-resolution failure, including Gradle's `generateJooq FAILED` task wrapper when the failure prevents the JavaExec generator from launching. The configuration-cache wrapper remains retryable only before `generateJooq` starts. Genuine JavaExec, code-generation, SQL, compiler, test, mixed, unknown, interrupted, or unrelated configuration failures retain their original failure. - On the complete CI path, generates one per-service JaCoCo report from unit and every available categorized integration/cross-service test execution, uploads that combined XML to Codecov using GitHub OIDC, and runs the Trivy scans. Modules without categorized tests retain their unit-only report; production classes remain in the report rather than being excluded to improve percentages. Lightweight documentation-only PR validation does not run these Trivy jobs. - Retains the Gradle JUnit XML results from each affected-module `check` run, including unit and integration outcomes, in an artifact named with the module, workflow SHA, and run attempt for 14 days. Including the attempt keeps partial workflow reruns from colliding with earlier artifacts. The load-testing matrix entry uses its `dev-tools/load-testing` output; missing XML is reported as a warning so artifact retention does not change the test gate. - Uses Node 24 to lint OpenAPI specs, run React linters, and execute an accessibility audit using headless Chrome. diff --git a/dev-tools/README.md b/dev-tools/README.md index 203045f522..1ac1ccad8e 100644 --- a/dev-tools/README.md +++ b/dev-tools/README.md @@ -15,6 +15,7 @@ Keep the root of `dev-tools/` small. Only canonical human-facing entrypoints and - `build-local-smoke-images.sh` – builds the pinned local base and service images for a 40-character commit tag after rebuilding the service boot jars. - `verify-compose-health.sh` – shared health gate used by the smoke entrypoints. - `validation/run-locked-gradle.sh` – canonical local Gradle wrapper that serializes heavy builds across worktrees, protects shared output trees, and bounds lock acquisition and cancellation start. Use it for local proof and service boot-jar builds; [Local Gradle execution](../design/developer-workflows/validation-and-runtime-proof.md#local-gradle-execution) owns configuration and cancellation limits. For example: `bash dev-tools/validation/run-locked-gradle.sh :account-service:test`. +- `validation/run-gradle-with-dependency-recovery.sh` – shared one-retry runner for the complete affected-module check and source-built boot-jar commands. It refreshes dependency metadata only after a recognized repository-resolution failure; each caller supplies its complete Gradle command and runner. - `validation/inspect-test-results.sh` – read-only JUnit XML summary helper for diagnosing quiet post-suite Gradle tails without guessing at process state. For example: `bash dev-tools/validation/inspect-test-results.sh account-service`. This is diagnostic evidence only and does not prove that the Gradle invocation completed cleanly. - `pr-review` – the sole review controller. Use `dev-tools/pr-review stack set ...` and `stack show` for the repository review stack, `status [--pr ]` for fail-closed live state, `run hosted|cli [--expect-pr ] [--force [--reason ]]` for a complete checkpoint, `evidence []` for anchored evidence, and `decide ...` for explicit judgments. `--force` records acknowledgment of a known candidate-quality warning with the attempt; it does not bypass PR/candidate identity or admission-time rechecks, provider ceilings or quota, active-request exclusion, channel caps, stopped/completed channels, or accepted-finding obligations. A completed result counts normally for its PR and channel. The complete review, status, checkpoint, and disposition policy is owned by [PR lifecycle: Review and Status](../design/developer-workflows/pr-lifecycle.md#review-and-status). Until an explicitly validated JSON-to-SQLite cutover, controller decisions remain in the locked private common-directory JSON state file; do not assume cutover has occurred. Live shared cutover waits until the controller change is merged and its version-matched tooling is installed. Select the trusted promoted `dev-tools/pr-review` entrypoint and inspect `dev-tools/pr-review --version` before migration or shared writes. Follow [PR-review SQLite operations](pr_review/README.md) for the atomic JSON migration and old-writer fence, separate records bootstrap, provider-checkpoint imports, curated manual/subagent batch imports, and read-only history/route queries. Existing controller-era routes remain available through `routes` and `status`; full provider captures remain separate audit evidence outside SQLite. Provider imports and independent records do not affect CodeRabbit taper. Live PR, CI, checkpoint, and review evidence is derived when requested. For hands-on acceptance, pass the paired global options `--acceptance-fixture ` and `--state-path `; these use synthetic fixture adapters in a dedicated private directory and never contact GitHub or consume review quota. The implementation and focused contracts live in `pr_review/` and `tests/pr-review-controller-contract.sh`. diff --git a/dev-tools/build-compose-service-jars.sh b/dev-tools/build-compose-service-jars.sh index 446dd515ba..b123b141a2 100644 --- a/dev-tools/build-compose-service-jars.sh +++ b/dev-tools/build-compose-service-jars.sh @@ -19,7 +19,8 @@ GRADLE_TASKS=( echo "Building current boot jars for source-built Docker compose services." # Bound compiler memory for this all-module image build and avoid protobuf task cache-serialization failures. -bash "$ROOT_DIR/dev-tools/validation/run-locked-gradle.sh" \ +bash "$ROOT_DIR/dev-tools/validation/run-gradle-with-dependency-recovery.sh" \ + --runner "$ROOT_DIR/dev-tools/validation/run-locked-gradle.sh" -- \ --no-configuration-cache \ --max-workers=1 \ --no-parallel \ diff --git a/dev-tools/tests/gradle-dependency-recovery-contract.sh b/dev-tools/tests/gradle-dependency-recovery-contract.sh index faf57d3e7c..a91aca3a84 100644 --- a/dev-tools/tests/gradle-dependency-recovery-contract.sh +++ b/dev-tools/tests/gradle-dependency-recovery-contract.sh @@ -2,25 +2,40 @@ set -euo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" -RUNNER="$ROOT_DIR/.github/scripts/run-gradle-module-checks.sh" +MODULE_RUNNER="$ROOT_DIR/.github/scripts/run-gradle-module-checks.sh" +RECOVERY_RUNNER="$ROOT_DIR/dev-tools/validation/run-gradle-with-dependency-recovery.sh" +COMPOSE_JARS="$ROOT_DIR/dev-tools/build-compose-service-jars.sh" TEMP_DIR="$(mktemp -d)" trap 'rm -rf -- "$TEMP_DIR"' EXIT fail() { echo "Gradle dependency-recovery contract: $*" >&2 + if [[ -f "${CASE_DIR:-}/output" ]]; then + tail -n 80 "$CASE_DIR/output" >&2 + fi exit 1 } new_case() { CASE_DIR="$TEMP_DIR/$1" - mkdir -p "$CASE_DIR/bin" - cp "$RUNNER" "$CASE_DIR/run-gradle-module-checks.sh" + mkdir -p "$CASE_DIR/bin" "$CASE_DIR/.github/scripts" "$CASE_DIR/dev-tools/validation" + cp "$MODULE_RUNNER" "$CASE_DIR/.github/scripts/run-gradle-module-checks.sh" + cp "$RECOVERY_RUNNER" "$CASE_DIR/dev-tools/validation/run-gradle-with-dependency-recovery.sh" + cp "$COMPOSE_JARS" "$CASE_DIR/dev-tools/build-compose-service-jars.sh" + cat > "$CASE_DIR/dev-tools/validation/run-locked-gradle.sh" <<'LOCKED' +#!/usr/bin/env bash +set -euo pipefail +printf '%s\n' "$*" >> "${FAKE_LOCK_CALL_LOG:?}" +exec ./gradlew "$@" +LOCKED + chmod +x "$CASE_DIR/dev-tools/validation/run-locked-gradle.sh" cat > "$CASE_DIR/bin/sleep" <<'SLEEP' #!/usr/bin/env bash printf '%s\n' "$*" >> "${FAKE_SLEEP_LOG:?}" SLEEP chmod +x "$CASE_DIR/bin/sleep" : > "$CASE_DIR/calls" + : > "$CASE_DIR/locked-calls" : > "$CASE_DIR/sleeps" } @@ -36,16 +51,19 @@ EOF_WRAPPER chmod +x "$CASE_DIR/gradlew" } +# shellcheck disable=SC2030,SC2031 run_case() { local module="$1" local expected_status="$2" local actual_status=0 if ( cd "$CASE_DIR" + export CASE_DIR export FAKE_CALL_LOG="$CASE_DIR/calls" + export FAKE_LOCK_CALL_LOG="$CASE_DIR/locked-calls" export FAKE_SLEEP_LOG="$CASE_DIR/sleeps" export PATH="$CASE_DIR/bin:$PATH" - bash ./run-gradle-module-checks.sh "$module" > "$CASE_DIR/output" 2>&1 + bash ./.github/scripts/run-gradle-module-checks.sh "$module" > "$CASE_DIR/output" 2>&1 ); then actual_status=0 else @@ -54,6 +72,26 @@ run_case() { [[ "$actual_status" -eq "$expected_status" ]] || fail "$CASE_DIR expected exit $expected_status, got $actual_status" } +# shellcheck disable=SC2030,SC2031 +run_compose_case() { + local expected_status="$1" + local actual_status=0 + if ( + cd "$CASE_DIR" + export CASE_DIR + export FAKE_CALL_LOG="$CASE_DIR/calls" + export FAKE_LOCK_CALL_LOG="$CASE_DIR/locked-calls" + export FAKE_SLEEP_LOG="$CASE_DIR/sleeps" + export PATH="$CASE_DIR/bin:$PATH" + bash ./dev-tools/build-compose-service-jars.sh > "$CASE_DIR/output" 2>&1 + ); then + actual_status=0 + else + actual_status=$? + fi + [[ "$actual_status" -eq "$expected_status" ]] || fail "$CASE_DIR expected compose exit $expected_status, got $actual_status" +} + assert_call_count() { local expected="$1" local actual @@ -305,6 +343,111 @@ assert_call 2 "--refresh-dependencies --max-workers=2 -Dorg.gradle.jvmargs=-Xmx2 assert_output_contains "Configuration cache state could not be cached: field \`classpath\` of \`org.gradle.process.internal.DefaultJavaExecSpec_Decorated\`" assert_output_contains "refreshed-captured-jooq-resolution" +# This retained runtime-image failure is a different narrow boundary: Gradle +# marks generateJooq failed because its jooqCodegen classpath is unresolved, +# before the JavaExec generator process can run. +write_runtime_jooq_captured_cause() { + cat > "$CASE_DIR/runtime-jooq-cause.log" <<'LOG' +> Task :buildSrc:checkKotlinGradlePluginConfigurationErrors SKIPPED +> Task :buildSrc:compileKotlin FROM-CACHE +> Task :buildSrc:compileJava NO-SOURCE +> Task :buildSrc:compileGroovy NO-SOURCE +> Task :buildSrc:pluginDescriptors +> Task :buildSrc:processResources +> Task :buildSrc:classes +> Task :buildSrc:jar +> Task :account-service:writeJooqConfig +> Task :account-service:generateJooq FAILED + +FAILURE: Build failed with an exception. + +* What went wrong: +Execution failed for task ':account-service:generateJooq' (registered by plugin 'net.firedevops.firemud.jooq-conventions'). +> Could not resolve all files for configuration ':account-service:jooqCodegen'. + > Could not find org.jooq:jooq-meta-extensions:3.21.9. + + Searched in the following locations: + - https://repo.maven.apache.org/maven2/org/jooq/jooq-meta-extensions/3.21.9/jooq-meta-extensions-3.21.9.pom + + Required by: + project ':account-service' + > Could not find org.postgresql:postgresql:42.7.14. + Searched in the following locations: + - https://repo.maven.apache.org/maven2/org/postgresql/postgresql/42.7.14/postgresql-42.7.14.pom + Required by: + project ':account-service' + > Could not find org.jooq:jooq-meta:3.21.9. + Searched in the following locations: + - https://repo.maven.apache.org/maven2/org/jooq/jooq-meta/3.21.9/jooq-meta-3.21.9.pom + Required by: + project ':account-service' > org.jooq:jooq-codegen:3.21.9 +> If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration. +* Try: +> Run with --stacktrace option to get the stack trace. +BUILD FAILED in 17s +LOG +} + +compose_expected="--no-configuration-cache --max-workers=1 --no-parallel -Dorg.gradle.jvmargs=-Xmx2560m -Dfile.encoding=UTF-8 -PincludeLoadTesting=false :account-service:bootJar :automation-scripting-service:bootJar :entity-management-service:bootJar :game-design-service:bootJar :game-logic-service:bootJar :game-session-service:bootJar :logging-admin-service:bootJar :social-groups-service:bootJar :spring-cloud-gateway:bootJar :tcp-proxy-service:bootJar :world-management-service:bootJar" +new_case runtime-jooq-classpath-resolution +write_runtime_jooq_captured_cause +# shellcheck disable=SC2016 +write_wrapper 'if [[ "$call_count" -eq 1 ]]; then + cat "$CASE_DIR/runtime-jooq-cause.log" + exit 1 +fi +echo refreshed-runtime-jooq-resolution +exit 0' +run_compose_case 0 +assert_call_count 2 +assert_call 1 "$compose_expected" +assert_call 2 "--refresh-dependencies $compose_expected" +[[ "$(wc -l < "$CASE_DIR/locked-calls")" -eq 2 ]] || fail "runtime refresh did not retain locked execution" +[[ "$(sed -n '1p' "$CASE_DIR/locked-calls")" == "$compose_expected" ]] || fail "initial runtime task list changed before lock wrapper" +[[ "$(sed -n '2p' "$CASE_DIR/locked-calls")" == "--refresh-dependencies $compose_expected" ]] || fail "refreshed runtime task list changed before lock wrapper" +[[ "$(cat "$CASE_DIR/sleeps")" == 0 ]] || fail "missing runtime artifact added a transient-error delay" +assert_output_contains "Could not resolve all files for configuration ':account-service:jooqCodegen'." +assert_output_contains "refreshed-runtime-jooq-resolution" + +# The exact resolution root is not enough when other generator, compile/test, +# or unknown failure work is present in the same complete command output. +new_case runtime-jooq-other-generator-progress +write_runtime_jooq_captured_cause +# shellcheck disable=SC2016 +write_wrapper 'if [[ "$call_count" -eq 1 ]]; then + echo "> Task :automation-scripting-service:generateJooq FROM-CACHE" + cat "$CASE_DIR/runtime-jooq-cause.log" + exit 1 +fi +echo unexpected-retry +exit 0' +run_compose_case 1 +assert_no_retry + +new_case runtime-jooq-compile-progress +write_runtime_jooq_captured_cause +# shellcheck disable=SC2016 +write_wrapper 'if [[ "$call_count" -eq 1 ]]; then + echo "> Task :account-service:compileJava" + cat "$CASE_DIR/runtime-jooq-cause.log" + exit 1 +fi +echo unexpected-retry +exit 0' +run_compose_case 1 +assert_no_retry + +new_case runtime-jooq-mixed-cause +write_runtime_jooq_captured_cause +awk '/^\* Try:$/ { print "Could not create task :account-service:check because of unsupported plugin configuration." } { print }' \ + "$CASE_DIR/runtime-jooq-cause.log" > "$CASE_DIR/runtime-jooq-mixed-cause.log" +mv "$CASE_DIR/runtime-jooq-mixed-cause.log" "$CASE_DIR/runtime-jooq-cause.log" +# shellcheck disable=SC2016 +write_wrapper 'cat "$CASE_DIR/runtime-jooq-cause.log" +exit 1' +run_compose_case 1 +assert_no_retry + # A real generator failure is not a dependency failure and must retain its # original result even though it came from the same JavaExec task. new_case jooq-codegen-execution-failure diff --git a/dev-tools/validation/run-gradle-with-dependency-recovery.sh b/dev-tools/validation/run-gradle-with-dependency-recovery.sh new file mode 100644 index 0000000000..5d6795384d --- /dev/null +++ b/dev-tools/validation/run-gradle-with-dependency-recovery.sh @@ -0,0 +1,432 @@ +#!/usr/bin/env bash +set -euo pipefail + +if [[ $# -lt 4 || "$1" != --runner || -z "$2" ]]; then + echo "usage: run-gradle-with-dependency-recovery.sh --runner -- " >&2 + exit 64 +fi +readonly GRADLE_RUNNER="$2" +shift 2 +if [[ "$1" != -- ]]; then + echo "expected -- before Gradle arguments" >&2 + exit 64 +fi +shift +if (($# == 0)); then + echo "at least one Gradle argument is required" >&2 + exit 64 +fi +readonly -a GRADLE_ARGS=("$@") + +readonly TEMP_ROOT="${RUNNER_TEMP:-${TMPDIR:-/tmp}}" +if ! TEMP_DIR="$(mktemp -d "${TEMP_ROOT%/}/firemud-gradle-check.XXXXXX")"; then + echo "unable to create Gradle recovery log directory" >&2 + exit 125 +fi +readonly TEMP_DIR +readonly NORMAL_LOG="$TEMP_DIR/normal.log" +readonly REFRESH_LOG="$TEMP_DIR/refresh.log" + +# Invoked indirectly by the EXIT trap below. +# shellcheck disable=SC2329 +cleanup() { + rm -f -- "$NORMAL_LOG" "$REFRESH_LOG" + rmdir -- "$TEMP_DIR" +} +trap cleanup EXIT +trap 'exit 130' INT +trap 'exit 143' TERM +trap 'exit 129' HUP + +GRADLE_EXIT=0 +run_gradle_check() { + local refresh="$1" + local log_path="$2" + local -a pipeline_status=() + + set +e + if [[ "$refresh" == true ]]; then + "$GRADLE_RUNNER" --refresh-dependencies "${GRADLE_ARGS[@]}" 2>&1 | tee "$log_path" + else + "$GRADLE_RUNNER" "${GRADLE_ARGS[@]}" 2>&1 | tee "$log_path" + fi + pipeline_status=("${PIPESTATUS[@]}") + set -e + + GRADLE_EXIT="${pipeline_status[0]:-125}" + if [[ "${pipeline_status[1]:-125}" -ne 0 ]]; then + echo "failed to capture complete Gradle output; refusing dependency retry" >&2 + exit 125 + fi +} + +has_substantive_failure() { + local log_path="$1" + + grep -Eq '(^|[[:space:]])(Compilation failed|Compilation error|error:|e: file:|There were failing tests)' "$log_path" && return 0 + + awk ' + /^> Task / { + task = $3 + outcome = $4 + name = task + sub(/^.*:/, "", name) + + is_compile = name ~ /^compile[A-Z][A-Za-z0-9]*$/ + is_test = !is_compile && name ~ /(^|[A-Za-z0-9])(test|Test)[A-Za-z0-9]*$/ + # buildSrc compiles the build logic during Gradle setup, not the target + # module sources whose successful execution must remain unretried. + is_build_logic = task ~ /^:buildSrc(:|$)/ + is_compile = !is_build_logic && is_compile + if (!is_test && !is_compile) { + next + } + + cached_or_skipped = outcome == "FROM-CACHE" || outcome == "UP-TO-DATE" || outcome == "NO-SOURCE" || outcome == "SKIPPED" + if (is_test && !cached_or_skipped) { + found = 1 + } else if (is_compile && outcome != "FAILED" && !cached_or_skipped) { + found = 1 + } + if (is_compile && outcome == "FAILED" && !cached_or_skipped) { + failed_compile = 1 + } + } + END { + if (found) { + exit 0 + } + if (failed_compile) { + exit 2 + } + exit 1 + } + ' "$log_path" + return $? +} + +failure_body() { + local log_path="$1" + + awk ' + /^FAILURE: Build failed with an exception\.$/ { + failures++ + in_failure = 1 + next + } + in_failure && /^\* What went wrong:$/ { + sections++ + in_body = 1 + next + } + in_body && /^\* Try:$/ { + in_body = 0 + ended = 1 + next + } + in_body { + print + } + END { + if (failures != 1 || sections != 1 || !ended || invalid) { + exit 1 + } + } + ' "$log_path" +} + +classify_failure_body() { + local log_path="$1" + + awk ' + BEGIN { quote = sprintf("%c", 39) } + function trim(s) { + sub(/^[[:space:]]+/, "", s) + sub(/[[:space:]]+$/, "", s) + return s + } + { + line = trim($0) + if (line == "" || line == "* What went wrong:") { + next + } + + if (line == "1 problem was found storing the configuration cache.") { + cache_summary++ + next + } + if (line ~ /^Configuration cache state could not be cached: field `classpath` of `org\.gradle\.process\.internal\.DefaultJavaExecSpec_Decorated` bean found in field `javaExecSpec` of task `:[^`]+:generateJooq` of type `org\.gradle\.api\.tasks\.JavaExec`: error writing value of type \047org\.gradle\.api\.internal\.file\.collections\.DefaultConfigurableFileCollection\047$/) { + if (match(line, /task `:[^`]+:generateJooq`/)) { + task_reference = substr(line, RSTART, RLENGTH) + sub(/^task `/, "", task_reference) + sub(/`$/, "", task_reference) + sub(/:generateJooq$/, "", task_reference) + if (jooq_module != "" && jooq_module != task_reference) { + invalid++ + } + jooq_module = task_reference + } else { + invalid++ + } + jooq_wrapper_causes++ + cache_cause++ + next + } + if (line ~ /^Execution failed for task \047:[[:alnum:]-]+:generateJooq\047 \(registered by plugin \047net\.firedevops\.firemud\.jooq-conventions\047\)\.$/) { + task_reference = line + sub(/^Execution failed for task \047/, "", task_reference) + sub(/\047 \(registered by plugin \047net\.firedevops\.firemud\.jooq-conventions\047\)\.$/, "", task_reference) + sub(/:generateJooq$/, "", task_reference) + if (jooq_execution_module != "" && jooq_execution_module != task_reference) { + invalid++ + } + jooq_execution_module = task_reference + jooq_execution_causes++ + next + } + if (line ~ /^Configuration cache state could not be cached: field `classpath` of task `:[^`]+:compile[A-Za-z0-9]+` of type .*JavaCompile.*: error writing value of type .*DefaultResolvableConfiguration/ || + line ~ /^- Task `:[^`]+:compile[A-Za-z0-9]+` of type .*JavaCompile.*: error writing value of type .*DefaultResolvableConfiguration/) { + if (match(line, /`:[^`]+:compile[A-Za-z0-9]+`/)) { + task_reference = substr(line, RSTART, RLENGTH) + if (cache_task != "" && cache_task != task_reference) { + invalid++ + } + cache_task = task_reference + } else { + invalid++ + } + cache_cause++ + next + } + if (line ~ /^See the complete report at file:.*configuration-cache\//) { + next + } + if (line ~ /^\[Incubating\] Problems report is available at: file:.*\/build\/reports\/problems\/problems-report\.html$/ || + line == ("> If the artifact you are trying to retrieve can be found in the repository but without metadata in " quote "Maven POM" quote " format, you need to adjust the " quote "metadataSources { ... }" quote " of the repository declaration.") || + line == "Deprecated Gradle features were used in this build, making it incompatible with Gradle 10." || + line == "You can use \047--warning-mode all\047 to show the individual deprecation warnings and determine if they come from your own scripts or plugins." || + line == "For more on this, please refer to https://docs.gradle.org/9.8.1/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation." || + line ~ /^[0-9]+ actionable tasks: [0-9]+ executed, [0-9]+ from cache$/) { + next + } + + if (line ~ /^> Could not resolve all (artifacts|files) for configuration .+\.$/) { + resolver_roots++ + if (line ~ /(compileClasspath|testCompileClasspath|integrationTestCompileClasspath|crossServiceTestCompileClasspath)/) { + compile_classpath_roots++ + } + configuration_name = line + sub(/^> Could not resolve all (artifacts|files) for configuration /, "", configuration_name) + sub(/[.]$/, "", configuration_name) + quote = sprintf("%c", 39) + if (substr(configuration_name, 1, 1) == quote) { + configuration_name = substr(configuration_name, 2, length(configuration_name) - 2) + } + if (configuration_name ~ /^:[[:alnum:]-]+:jooqCodegen$/) { + jooq_codegen_roots++ + root_module = configuration_name + sub(/:jooqCodegen$/, "", root_module) + if (jooq_module != "" && jooq_module != root_module) { + invalid++ + } + jooq_root_module = root_module + } + if ((jooq_wrapper_causes || jooq_execution_causes) && configuration_name !~ /^:[[:alnum:]-]+:jooqCodegen$/) { + invalid++ + } + next + } + if (line ~ /^> Could not (find|resolve) [[:alnum:]_.-]+:[[:alnum:]_.-]+:[0-9][[:alnum:]_.-]*\.$/ || + line ~ /^> Could not find [^[:space:]]+ \([[:alnum:]_.-]+:[[:alnum:]_.-]+:[0-9][[:alnum:]_.-]*\)\.$/) { + coordinates++ + next + } + if (line ~ /^> Could not (get resource|GET|HEAD) [\047\042]?https?:\/\// || + line ~ /^> Could not GET https?:\/\//) { + repository_requests++ + next + } + if (line ~ /^Execution failed for task / && line ~ /:compile[A-Za-z0-9]+[\047"][.]$/) { + compile_task_failure++ + next + } + if (line == "Searched in the following locations:" || line ~ /^https?:\/\// || line ~ /^- https?:\/\// || + line == "Required by:" || line ~ /^project / || + line ~ /^> Got socket exception during request\./ || + line ~ /^> Connection (reset|timed out)$/ || + line ~ /^> SocketTimeoutException/ || + line ~ /^Received status code (429|5[0-9][0-9]) from server/ || + line ~ /^Retry-After: .+$/ || + line ~ /^(> )?There are [0-9]+ more failures with identical causes\.$/) { + if (line ~ /^Received status code /) { + transient++ + } + if (line ~ /^> Connection / || line ~ /^> SocketTimeoutException/ || line ~ /^> Got socket exception/) { + transient++ + } + if (line ~ /^Searched in the following locations:/) { + searched++ + } + if (line ~ /^https?:\/\// || line ~ /^- https?:\/\//) { + repository_urls++ + } + next + } + + # Every other line inside the fatal cause body is an additional + # or unknown cause. Do not let matching dependency text elsewhere mask it. + invalid++ + } + END { + if (invalid || resolver_roots == 0 || coordinates == 0 || + (cache_summary && (cache_cause == 0 || cache_cause > 2)) || + (compile_task_failure && compile_classpath_roots == 0) || + (jooq_wrapper_causes && + (jooq_wrapper_causes != 1 || jooq_codegen_roots != 1 || resolver_roots != 1 || + cache_cause != 1 || jooq_execution_causes || jooq_module == "" || jooq_root_module != jooq_module)) || + (jooq_execution_causes && + (jooq_execution_causes != 1 || jooq_codegen_roots != 1 || resolver_roots != 1 || + cache_cause != 0 || jooq_execution_module == "" || jooq_root_module != jooq_execution_module)) || + (!jooq_wrapper_causes && !jooq_execution_causes && jooq_codegen_roots) || + !((transient && repository_requests) || (searched && repository_urls))) { + exit 1 + } + exit 0 + } + ' "$log_path" +} + +is_dependency_resolution_failure() { + local log_path="$1" + local body_path + local substantive_status=0 + + body_path="$(mktemp "${TEMP_DIR%/}/failure-body.XXXXXX")" || return 1 + if ! failure_body "$log_path" > "$body_path"; then + rm -f -- "$body_path" + return 1 + fi + if ! classify_failure_body "$body_path"; then + rm -f -- "$body_path" + return 1 + fi + + jooq_execution_module="$(awk ' + BEGIN { quote = sprintf("%c", 39) } + /^Execution failed for task / { + line = $0 + prefix = "Execution failed for task " quote + suffix = quote " (registered by plugin " quote "net.firedevops.firemud.jooq-conventions" quote ")." + if (index(line, prefix) != 1 || substr(line, length(line) - length(suffix) + 1) != suffix) { + invalid++ + next + } + line = substr(line, length(prefix) + 1) + line = substr(line, 1, length(line) - length(suffix)) + if (line !~ /^:[[:alnum:]-]+:generateJooq$/) { + invalid++ + next + } + sub(/:generateJooq$/, "", line) + module = line + count++ + } + END { + if (count != 1 || invalid) exit 1 + print module + } + ' "$body_path")" || jooq_execution_module="" + + if [[ -n "$jooq_execution_module" ]] && ! awk -v expected_module="$jooq_execution_module" ' + /^> Task / { + task = $3 + outcome = $4 + name = task + sub(/^.*:/, "", name) + if (name == "generateJooq") { + jooq_tasks++ + if (task != expected_module ":generateJooq" || outcome != "FAILED") invalid++ + } + is_compile = name ~ /^compile[A-Z][A-Za-z0-9]*$/ + is_test = !is_compile && name ~ /(^|[A-Za-z0-9])(test|Test)[A-Za-z0-9]*$/ + if (task ~ /^:buildSrc(:|$)/) is_compile = 0 + cached_or_skipped = outcome == "FROM-CACHE" || outcome == "UP-TO-DATE" || outcome == "NO-SOURCE" || outcome == "SKIPPED" + if ((is_compile || is_test) && !cached_or_skipped) invalid++ + } + END { + if (jooq_tasks != 1 || invalid) exit 1 + } + ' "$log_path"; then + rm -f -- "$body_path" + return 1 + fi + + if grep -Fq 'DefaultJavaExecSpec_Decorated' "$body_path" && + grep -Fq ':generateJooq' "$body_path" && + grep -Eq '^> Task :[[:alnum:]][[:alnum:]-]*:generateJooq([[:space:]]|$)' "$log_path"; then + # The configuration-cache wrapper retries only before the generator task starts. + rm -f -- "$body_path" + return 1 + fi + + has_substantive_failure "$log_path" || substantive_status=$? + rm -f -- "$body_path" + case "$substantive_status" in + 0) return 1 ;; + 1|2) return 0 ;; + *) return 1 ;; + esac +} + +retry_delay_seconds() { + local log_path="$1" + local retry_after + local delay + + retry_after="$(failure_body "$log_path" | sed -nE 's/^.*[Rr]etry-[Aa]fter:[[:space:]]*(.*)$/\1/p')" || return 1 + if [[ -z "$retry_after" ]]; then + if failure_body "$log_path" | grep -Eq 'Connection reset|Connection timed out|SocketTimeoutException|Received status code 429 from server|Received status code 5[0-9][0-9] from server'; then + printf '2\n' + else + printf '0\n' + fi + return 0 + fi + + # Reject date and malformed values; cap raw decimal length before arithmetic, + # strip leading zeroes, and force base ten so values such as 08 stay safe. + [[ "$retry_after" =~ ^[0-9]+$ ]] || return 1 + (( ${#retry_after} <= 16 )) || return 1 + local canonical="${retry_after#"${retry_after%%[!0]*}"}" + [[ -n "$canonical" ]] || canonical=0 + (( ${#canonical} <= 2 )) || return 1 + delay=$((10#$canonical)) + + if (( delay > 30 )); then + echo "Retry-After exceeds the bounded 30-second retry window; preserving original failure" >&2 + return 1 + fi + printf '%s\n' "$delay" +} + +run_gradle_check false "$NORMAL_LOG" +if [[ "$GRADLE_EXIT" -eq 0 ]]; then + exit 0 +fi + +if [[ "$GRADLE_EXIT" -ne 1 ]]; then + exit "$GRADLE_EXIT" +fi + +if ! is_dependency_resolution_failure "$NORMAL_LOG"; then + exit "$GRADLE_EXIT" +fi + +if ! RETRY_DELAY="$(retry_delay_seconds "$NORMAL_LOG")"; then + exit "$GRADLE_EXIT" +fi + +echo "Recognized Gradle dependency-resolution failure at the bounded pre-substantive boundary; retrying the complete Gradle command once with dependency metadata refresh after ${RETRY_DELAY}s." +sleep "$RETRY_DELAY" +run_gradle_check true "$REFRESH_LOG" +exit "$GRADLE_EXIT" From b66ff290a52bd67682823a7fab1e314fd76e960e Mon Sep 17 00:00:00 2001 From: Ben Hook <5009589+benhook1013@users.noreply.github.com> Date: Thu, 15 Oct 2026 18:36:58 +1300 Subject: [PATCH 3/3] Register shared Gradle recovery selectors --- .github/scripts/classify-change-scope.cjs | 1 + .github/scripts/classify-change-scope.test.cjs | 1 + .github/workflows/runtime-images.yml | 3 +++ .github/workflows/smoke.yml | 3 ++- dev-tools/hosted/preview/resolve-preview-image-tag.sh | 1 + dev-tools/tests/pr-retarget-workflow-contract.sh | 1 + dev-tools/tests/preview-image-tag-contract.sh | 1 + 7 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/scripts/classify-change-scope.cjs b/.github/scripts/classify-change-scope.cjs index 8f3aaa0e35..337dbdb2e9 100644 --- a/.github/scripts/classify-change-scope.cjs +++ b/.github/scripts/classify-change-scope.cjs @@ -66,6 +66,7 @@ const SHARED_FILES = new Set([ "gradle.properties", "gradlew", "gradlew.bat", + "dev-tools/validation/run-gradle-with-dependency-recovery.sh", "dev-tools/validation/run-locked-gradle.sh", "dev-tools/validation/gradle-run-supervisor.py", ]); diff --git a/.github/scripts/classify-change-scope.test.cjs b/.github/scripts/classify-change-scope.test.cjs index 0f10225ab1..227f9516e4 100644 --- a/.github/scripts/classify-change-scope.test.cjs +++ b/.github/scripts/classify-change-scope.test.cjs @@ -138,6 +138,7 @@ test("workflow and Gradle wrapper changes force all module validation", () => { ".github/scripts/classify-change-scope.cjs", "gradlew", "gradlew.bat", + "dev-tools/validation/run-gradle-with-dependency-recovery.sh", "dev-tools/validation/run-locked-gradle.sh", "dev-tools/validation/gradle-run-supervisor.py", ]) { diff --git a/.github/workflows/runtime-images.yml b/.github/workflows/runtime-images.yml index 5246ed9b19..0ed9f04aec 100644 --- a/.github/workflows/runtime-images.yml +++ b/.github/workflows/runtime-images.yml @@ -27,6 +27,7 @@ on: - 'config/python/smoke-requirements.txt' - 'config/python/smoke-requirements.in' - 'dev-tools/build-compose-service-jars.sh' + - 'dev-tools/validation/run-gradle-with-dependency-recovery.sh' - 'dev-tools/validation/run-locked-gradle.sh' - 'dev-tools/validation/gradle-run-supervisor.py' - 'dev-tools/build-local-smoke-images.sh' @@ -360,6 +361,7 @@ jobs: "config/python/smoke-requirements.txt", "config/python/smoke-requirements.in", "dev-tools/build-compose-service-jars.sh", + "dev-tools/validation/run-gradle-with-dependency-recovery.sh", "dev-tools/validation/run-locked-gradle.sh", "dev-tools/validation/gradle-run-supervisor.py", "dev-tools/build-local-smoke-images.sh", @@ -468,6 +470,7 @@ jobs: "config/python/smoke-requirements.txt", "config/python/smoke-requirements.in", "dev-tools/build-compose-service-jars.sh", + "dev-tools/validation/run-gradle-with-dependency-recovery.sh", "dev-tools/validation/run-locked-gradle.sh", "dev-tools/validation/gradle-run-supervisor.py", "dev-tools/build-local-smoke-images.sh", diff --git a/.github/workflows/smoke.yml b/.github/workflows/smoke.yml index 4751bf8645..2954b5b429 100644 --- a/.github/workflows/smoke.yml +++ b/.github/workflows/smoke.yml @@ -107,6 +107,7 @@ jobs: "config/python/smoke-requirements.txt", "config/python/smoke-requirements.in", "dev-tools/build-compose-service-jars.sh", + "dev-tools/validation/run-gradle-with-dependency-recovery.sh", "dev-tools/validation/run-locked-gradle.sh", "dev-tools/validation/gradle-run-supervisor.py", "dev-tools/build-local-smoke-images.sh", @@ -577,7 +578,7 @@ jobs: } // One canonical producer definition; the contract test reports fingerprint upkeep. - const canonicalRuntimeWorkflowSha256 = "c4bd569e46902970ce1844a68b127dfcc5f78f22648028799f8297e113d8ce7b"; + const canonicalRuntimeWorkflowSha256 = "8b49b5e26ac37a1b6c1d098ee0d8c9716d850eb0ea7e43491b6c6b6f191fca1a"; const canonicalSmokeJobName = "PR Full-Stack Smoke (runtime-required=true)"; const workflowPath = ".github/workflows/runtime-images.yml"; const repositoryName = `${owner}/${repo}`; diff --git a/dev-tools/hosted/preview/resolve-preview-image-tag.sh b/dev-tools/hosted/preview/resolve-preview-image-tag.sh index cc80087b29..45736497fb 100644 --- a/dev-tools/hosted/preview/resolve-preview-image-tag.sh +++ b/dev-tools/hosted/preview/resolve-preview-image-tag.sh @@ -42,6 +42,7 @@ runtime_relevant() { dev-tools/backups/pg-dump-s3-selection.shlib | \ dev-tools/backups/smoke-backup-verifier-image.sh | \ dev-tools/build-compose-service-jars.sh | \ + dev-tools/validation/run-gradle-with-dependency-recovery.sh | \ dev-tools/validation/run-locked-gradle.sh | \ dev-tools/validation/gradle-run-supervisor.py | \ dev-tools/build-local-smoke-images.sh | \ diff --git a/dev-tools/tests/pr-retarget-workflow-contract.sh b/dev-tools/tests/pr-retarget-workflow-contract.sh index 127d2a9b01..21e43575c7 100644 --- a/dev-tools/tests/pr-retarget-workflow-contract.sh +++ b/dev-tools/tests/pr-retarget-workflow-contract.sh @@ -2271,6 +2271,7 @@ runtime_paths = pull_request_paths(runtime_images, "runtime-images.yml") # Boot JARs use these helpers; each selector must retain both dependencies. build_dependencies = { + "dev-tools/validation/run-gradle-with-dependency-recovery.sh", "dev-tools/validation/run-locked-gradle.sh", "dev-tools/validation/gradle-run-supervisor.py", } diff --git a/dev-tools/tests/preview-image-tag-contract.sh b/dev-tools/tests/preview-image-tag-contract.sh index 2f5d0865f2..71d176d00c 100644 --- a/dev-tools/tests/preview-image-tag-contract.sh +++ b/dev-tools/tests/preview-image-tag-contract.sh @@ -557,6 +557,7 @@ run_resolver 'services/game-logic-service/src/main/Foo.kt' "$runtime_image_tag" run_resolver 'gradlew' "$runtime_image_tag" run_resolver 'gradlew.bat' "$runtime_image_tag" run_resolver 'dev-tools/validation/run-locked-gradle.sh' "$runtime_image_tag" +run_resolver 'dev-tools/validation/run-gradle-with-dependency-recovery.sh' "$runtime_image_tag" run_resolver 'dev-tools/validation/gradle-run-supervisor.py' "$runtime_image_tag" # A rename from a runtime-relevant path must keep the PR image selected even # when the current filename is no longer runtime-relevant.