Skip to content

Commit 4f8c89c

Browse files
kiviewdhruv9bclaude
authored
Fix CI matrix generation with the Spotless upgrade (#12087)
Spotless 6.22.0 fails with current npm. Spotless 8 printed greclipse output into the testMatrix JSON, so testMatrix no longer runs the check tasks and writes its output to a file. greclipse is now only configured in projects with Groovy sources. Fixes #11997. Supersedes #12003. Co-authored-by: Dhruv_G_123 <9bdhruv@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent a8be77b commit 4f8c89c

7 files changed

Lines changed: 55 additions & 33 deletions

File tree

‎.github/dependabot.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ updates:
1919
directory: "/"
2020
allow:
2121
- dependency-name: "com.gradle*"
22+
- dependency-name: "com.diffplug.spotless"
2223
registries:
2324
- gradle-plugin-portal
2425
patterns:
2526
- "com.gradle*"
27+
- "com.diffplug.spotless"
2628
multi-ecosystem-group: dependencies
2729
cooldown:
2830
default-days: 7

‎.github/workflows/ci.yml‎

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,18 @@ jobs:
9696
# we should not push empty results to the cache
9797
READ_ONLY_REMOTE_GRADLE_CACHE: true
9898
run: |
99-
set -o pipefail
100-
TASKS=$(./gradlew --no-daemon --parallel -q testMatrix | jq 'del(.[] | select(. == ":testcontainers:check" or startswith(":docs:")))' --compact-output)
101-
echo $TASKS
102-
echo "matrix={\"gradle_args\":$TASKS}" >> $GITHUB_OUTPUT
99+
set -euo pipefail
100+
MATRIX_FILE="$RUNNER_TEMP/test-matrix.json"
101+
./gradlew --no-daemon --parallel -q testMatrix -PtestMatrixOutput="$MATRIX_FILE"
102+
TASKS=$(jq --compact-output --exit-status '
103+
if type == "array" and length > 0 and all(.[]; type == "string" and startswith(":"))
104+
then map(select(. != ":testcontainers:check" and (startswith(":docs:") | not)))
105+
else error("testMatrix output must be a non-empty array of Gradle task paths")
106+
end
107+
| if length > 0 then . else error("testMatrix produced no core Gradle tasks") end
108+
' "$MATRIX_FILE")
109+
echo "$TASKS"
110+
printf 'matrix={"gradle_args":%s}\n' "$TASKS" >> "$GITHUB_OUTPUT"
103111
check:
104112
needs: [find_gradle_jobs]
105113
strategy:
@@ -131,9 +139,17 @@ jobs:
131139
# we should not push empty results to the cache
132140
READ_ONLY_REMOTE_GRADLE_CACHE: true
133141
run: |
134-
TASKS=$(./gradlew --no-daemon --parallel -q testMatrix)
135-
echo $TASKS
136-
echo "matrix={\"gradle_args\":$TASKS}" >> $GITHUB_OUTPUT
142+
set -euo pipefail
143+
MATRIX_FILE="$RUNNER_TEMP/examples-test-matrix.json"
144+
./gradlew --no-daemon --parallel -q testMatrix -PtestMatrixOutput="$MATRIX_FILE"
145+
TASKS=$(jq --compact-output --exit-status '
146+
if type == "array" and length > 0 and all(.[]; type == "string" and startswith(":"))
147+
then .
148+
else error("testMatrix output must be a non-empty array of Gradle task paths")
149+
end
150+
' "$MATRIX_FILE")
151+
echo "$TASKS"
152+
printf 'matrix={"gradle_args":%s}\n' "$TASKS" >> "$GITHUB_OUTPUT"
137153
check_examples:
138154
needs: [find_examples_jobs]
139155
strategy:
@@ -165,10 +181,18 @@ jobs:
165181
# we should not push empty results to the cache
166182
READ_ONLY_REMOTE_GRADLE_CACHE: true
167183
run: |
168-
set -o pipefail
169-
TASKS=$(./gradlew --no-daemon --parallel -q testMatrix | jq 'map(select(startswith(":docs:")))' --compact-output)
170-
echo $TASKS
171-
echo "matrix={\"gradle_args\":$TASKS}" >> $GITHUB_OUTPUT
184+
set -euo pipefail
185+
MATRIX_FILE="$RUNNER_TEMP/docs-test-matrix.json"
186+
./gradlew --no-daemon --parallel -q testMatrix -PtestMatrixOutput="$MATRIX_FILE"
187+
TASKS=$(jq --compact-output --exit-status '
188+
if type == "array" and length > 0 and all(.[]; type == "string" and startswith(":"))
189+
then map(select(startswith(":docs:")))
190+
else error("testMatrix output must be a non-empty array of Gradle task paths")
191+
end
192+
| if length > 0 then . else error("testMatrix produced no docs Gradle tasks") end
193+
' "$MATRIX_FILE")
194+
echo "$TASKS"
195+
printf 'matrix={"gradle_args":%s}\n' "$TASKS" >> "$GITHUB_OUTPUT"
172196
check_docs_examples:
173197
needs: [find_docs_examples_jobs]
174198
strategy:

‎build.gradle‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ plugins {
1414
id 'io.franzbecker.gradle-lombok' version '5.0.0'
1515
id 'com.gradleup.shadow' version '8.3.9'
1616
id 'me.champeau.gradle.japicmp' version '0.4.3' apply false
17-
id 'com.diffplug.spotless' version '6.22.0' apply false
17+
id 'com.diffplug.spotless' version '8.10.1' apply false
1818
id 'org.jreleaser' version '1.20.0' apply false
1919
}
2020

‎examples/build.gradle‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// empty build.gradle for dependabot
22
plugins {
3-
id 'com.diffplug.spotless' version '6.22.0' apply false
3+
id 'com.diffplug.spotless' version '8.10.1' apply false
44
}
55

66
apply from: "$rootDir/../gradle/ci-support.gradle"

‎gradle/ci-support.gradle‎

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,20 @@ task testMatrix {
77
it.tasks.findByName("check")
88
}.findAll { it != null }
99

10-
dependsOn(checkTasks)
1110
doLast {
1211
def checkTaskPaths = checkTasks
1312
.collect { it.path }
1413

15-
println(JsonOutput.toJson(checkTaskPaths))
16-
}
17-
}
18-
}
14+
def json = JsonOutput.toJson(checkTaskPaths)
15+
def outputPath = providers.gradleProperty("testMatrixOutput").getOrNull()
1916

20-
// If we're executing the `testMatrix` task, disable tests and other slow tasks
21-
// so that we can get a result quickly.
22-
gradle.taskGraph.whenReady {
23-
if (it.hasTask(tasks.testMatrix)) {
24-
for (subproject in subprojects) {
25-
subproject.tasks.withType(Test).all {
26-
testExecuter([execute: { spec, processor -> }, stopNow:{}] as org.gradle.api.internal.tasks.testing.TestExecuter)
17+
if (outputPath != null) {
18+
def outputFile = file(outputPath)
19+
outputFile.parentFile.mkdirs()
20+
outputFile.text = json + System.lineSeparator()
21+
} else {
22+
println(json)
2723
}
28-
subproject.tasks.findByName("shadowJar")?.enabled = false
29-
subproject.tasks.findByName("javadoc")?.enabled = false
30-
subproject.tasks.findByName("delombok")?.enabled = false
31-
subproject.tasks.findByName("japicmp")?.enabled = false
3224
}
3325
}
3426
}

‎gradle/spotless.gradle‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ spotless {
1616

1717
importOrder('', 'java', 'javax', '\\#')
1818
}
19-
groovyGradle {
20-
target '**/*.groovy'
21-
greclipse('4.19')
19+
// greclipse downloads its Eclipse dependencies even when nothing matches the target,
20+
// so only configure it in projects that actually contain Groovy sources.
21+
if (!fileTree('src') { include '**/*.groovy' }.isEmpty()) {
22+
groovyGradle {
23+
target '**/*.groovy'
24+
greclipse('4.19')
25+
}
2226
}
2327
}

‎smoke-test/build.gradle‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// empty build.gradle for dependabot
22
plugins {
3-
id 'com.diffplug.spotless' version '6.22.0' apply false
3+
id 'com.diffplug.spotless' version '8.10.1' apply false
44
}
55

66
apply from: "$rootDir/../gradle/ci-support.gradle"

0 commit comments

Comments
 (0)