Skip to content

Commit 6beb7fd

Browse files
authored
ci: fast Java formatting check using google-java-format native binary (#1984)
1 parent 5ce2b57 commit 6beb7fd

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

.github/renovate-tracked-deps.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@
136136
"lychee",
137137
"node",
138138
"npm:renovate",
139-
"protoc"
139+
"protoc",
140+
"ubi:google/google-java-format"
140141
],
141142
"regex": ["ghcr.io/super-linter/super-linter", "grafana/flint"]
142143
},

mise.toml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ lychee = "0.23.0"
66
node = "24.14.0"
77
"npm:renovate" = "43.45.1"
88
protoc = "34.0"
9+
"ubi:google/google-java-format" = "1.34.1"
910

1011
[env]
1112
RENOVATE_TRACKED_DEPS_EXCLUDE="github-actions,github-runners"
@@ -66,23 +67,29 @@ file = "https://raw.githubusercontent.com/grafana/flint/8a39d96e17327c54974623b2
6667
description = "Install native lint tools matching the pinned super-linter version"
6768
file = "https://raw.githubusercontent.com/grafana/flint/8a39d96e17327c54974623b252eb5260d67ed68a/tasks/setup/native-lint-tools.sh" # v0.9.1
6869

69-
[tasks."lint:spotless"]
70-
description = "Check Java formatting with Spotless"
71-
# examples don't have the spotless plugin, so we exclude them via the profile.
72-
# integration-tests are covered by the CI build task.
73-
run = "./mvnw com.diffplug.spotless:spotless-maven-plugin:check -P '!examples-and-integration-tests' -q"
70+
[tasks."lint:java"]
71+
description = "Check Java formatting (changed files only)"
72+
run = """
73+
files=$(git diff --name-only --diff-filter=d origin/main...HEAD -- '*.java')
74+
[ -z "$files" ] && exit 0
75+
google-java-format --dry-run --set-exit-if-changed $files
76+
"""
7477

7578
[tasks."lint:fast"]
7679
description = "Run fast lints (no Renovate)"
77-
depends = ["lint:super-linter", "lint:links", "lint:bom", "lint:example-poms", "lint:spotless"]
80+
depends = ["lint:super-linter", "lint:links", "lint:bom", "lint:example-poms", "lint:java"]
7881

7982
[tasks."lint"]
8083
description = "Run all lints"
8184
depends = ["lint:fast", "lint:renovate-deps"]
8285

8386
[tasks.fix]
8487
description = "Auto-fix lint issues"
85-
run = "AUTOFIX=true mise run lint"
88+
run = """
89+
files=$(git diff --name-only --diff-filter=d origin/main...HEAD -- '*.java')
90+
[ -n "$files" ] && google-java-format -i $files
91+
AUTOFIX=true mise run lint
92+
"""
8693

8794
[tasks.native-lint]
8895
description = "Run lints natively (no container)"

0 commit comments

Comments
 (0)