Skip to content

Commit 0169818

Browse files
KaleabArgawedeandrea
authored andcommitted
ci: set up Spotless linting in CI (#351)
Signed-off-by: Kaleab Argaw <kaleruha16@gmail.com>
1 parent 0ba041c commit 0169818

5 files changed

Lines changed: 69 additions & 0 deletions

File tree

.github/workflows/build.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,38 @@ defaults:
1818
shell: bash
1919

2020
jobs:
21+
lint:
22+
runs-on: ubuntu-latest
23+
name: lint-java
24+
steps:
25+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
26+
with:
27+
fetch-depth: 0
28+
29+
- name: Reclaim disk space
30+
working-directory: .github/scripts
31+
shell: bash
32+
run: ./ci-reclaim-disk-space.sh
33+
34+
- name: Set up Java 17
35+
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
36+
with:
37+
java-version: 17
38+
distribution: temurin
39+
40+
- name: Setup Gradle
41+
uses: gradle/actions/setup-gradle@0723195856401067f7a2779048b490ace7a47d7c # v5.0.2
42+
43+
- name: spotless-apply
44+
run: ./gradlew --no-daemon -Pjava.version=17 spotlessApply
45+
46+
- name: Verify formatting is clean
47+
run: |
48+
git diff --exit-code || {
49+
echo "Formatting issues were fixed by Spotless. Run './gradlew --no-daemon spotlessApply' locally and commit the result."
50+
exit 1
51+
}
52+
2153
save-pr-info:
2254
runs-on: ubuntu-latest
2355
if: always() && (github.event_name == 'pull_request')

CONTRIBUTING.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,26 @@ If you have not done so on this machine, you need to:
101101

102102
The project has a `.editorconfig` file checked into the root. Please make sure the rules in there are adhered to by your IDE.
103103

104+
## Build
105+
106+
To run a full build locally:
107+
108+
```bash
109+
./gradlew --no-daemon build
110+
```
111+
112+
To run code linting locally:
113+
114+
```bash
115+
./gradlew --no-daemon spotlessCheck
116+
```
117+
118+
To automatically apply formatting fixes:
119+
120+
```bash
121+
./gradlew --no-daemon spotlessApply
122+
```
123+
104124
## The small print
105125

106126
This project is an open source project, please act responsibly, be nice, polite and enjoy!

buildSrc/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ repositories {
1010
dependencies {
1111
implementation("org.yaml:snakeyaml:2.5")
1212
implementation(libs.lombok.gradle)
13+
implementation(libs.spotless.gradle)
1314
}
1415

1516
// Read root gradle.properties

buildSrc/src/main/kotlin/docling-java-shared.gradle.kts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ plugins {
22
id("docling-shared")
33
`java-library`
44
`jacoco`
5+
id("com.diffplug.spotless")
56
}
67

78
repositories {
@@ -41,6 +42,19 @@ jacoco {
4142
toolVersion = libs.findVersion("jacoco").get().toString()
4243
}
4344

45+
spotless {
46+
// Roll out linting incrementally by checking only files changed from main.
47+
ratchetFrom("origin/main")
48+
49+
java {
50+
target("src/*/java/**/*.java")
51+
removeUnusedImports()
52+
formatAnnotations()
53+
trimTrailingWhitespace()
54+
endWithNewline()
55+
}
56+
}
57+
4458
tasks.withType<Test>().configureEach {
4559
// Use JUnit Platform for unit tests.
4660
useJUnitPlatform()

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ junit = "6.0.3"
99
lombok = "1.18.42"
1010
lombok-gradle = "9.2.0"
1111
module-info = "1.14"
12+
spotless = "7.2.1"
1213
semver4j = "6.0.0"
1314
slf4j = "2.0.17"
1415
testcontainers = "2.0.3"
@@ -26,6 +27,7 @@ awaitility = { group = "org.awaitility", name = "awaitility", version.ref = "awa
2627

2728
# lombok-gradle
2829
lombok-gradle = { group = "io.freefair.lombok", name = "io.freefair.lombok.gradle.plugin", version.ref = "lombok-gradle" }
30+
spotless-gradle = { group = "com.diffplug.spotless", name = "spotless-plugin-gradle", version.ref = "spotless" }
2931

3032
# Jackson
3133
jackson-annotations = { group = "com.fasterxml.jackson.core", name = "jackson-annotations" }

0 commit comments

Comments
 (0)