Skip to content

Commit 4d31047

Browse files
authored
feat(ci,java): add formatting verification for bdd and examples (#2647)
- add linting for java examples and bdd tests - remove checkstyle from example - create helper action for setting up java and gradle - disable cache for java jobs to respect the 10GB limit
1 parent 2405199 commit 4d31047

File tree

9 files changed

+155
-93
lines changed

9 files changed

+155
-93
lines changed

.github/actions/java-gradle/post-merge/action.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ runs:
3535
with:
3636
distribution: "temurin"
3737
java-version: "17"
38-
cache: "gradle"
3938

4039
- name: Setup Gradle
4140
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
@@ -44,23 +43,25 @@ runs:
4443

4544
- name: Build for publishing
4645
shell: bash
46+
working-directory: foreign/java
4747
run: |
4848
echo "📦 Building Java SDK for publishing..."
49-
foreign/java/dev-support/checks/build.sh build -x test -x checkstyleMain -x checkstyleTest
49+
gradle build -x test -x checkstyleMain -x checkstyleTest
5050
BUILD_EXIT_CODE=$?
5151
5252
# List artifacts only if build succeeded
5353
if [ $BUILD_EXIT_CODE -eq 0 ]; then
5454
echo ""
5555
echo "Build artifacts:"
56-
find foreign/java -path "*/build/libs/*.jar" -type f 2>/dev/null | head -20 || echo "No jar artifacts found in build/libs directories"
56+
find . -path "*/build/libs/*.jar" -type f 2>/dev/null | head -20 || echo "No jar artifacts found in build/libs directories"
5757
else
5858
echo "❌ Build failed with exit code $BUILD_EXIT_CODE"
5959
exit $BUILD_EXIT_CODE
6060
fi
6161
6262
- name: Publish to Maven Nexus
6363
shell: bash
64+
working-directory: foreign/java
6465
env:
6566
NEXUS_USER: ${{ env.NEXUS_USER }}
6667
NEXUS_PW: ${{ env.NEXUS_PW }}
@@ -72,7 +73,7 @@ runs:
7273
echo ""
7374
7475
# Extract version from build.gradle.kts
75-
gradle_version=$(gradle -p foreign/java/java-sdk properties -q | grep "version:" | cut -d: -f2 | tr -d ' ')
76+
gradle_version=$(gradle -p java-sdk properties -q | grep "version:" | cut -d: -f2 | tr -d ' ')
7677
echo "Version from gradle: $gradle_version"
7778
echo "Input version: ${{ inputs.version }}"
7879
@@ -92,7 +93,7 @@ runs:
9293
# Show what would be published
9394
echo ""
9495
echo "Artifacts that would be published:"
95-
find foreign/java -path "*/build/libs/*.jar" -type f 2>/dev/null | while read jar; do
96+
find . -path "*/build/libs/*.jar" -type f 2>/dev/null | while read jar; do
9697
echo " - $(basename $jar)"
9798
done
9899
else
@@ -106,7 +107,7 @@ runs:
106107
echo ""
107108
108109
# Run the publish task
109-
foreign/java/dev-support/checks/build.sh build -x test -x checkstyleMain -x checkstyleTest sign publish
110+
gradle build -x test -x checkstyleMain -x checkstyleTest sign publish
110111
PUBLISH_EXIT_CODE=$?
111112
112113
if [ $PUBLISH_EXIT_CODE -eq 0 ]; then

.github/actions/java-gradle/pre-merge/action.yml

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,51 @@ inputs:
2626
runs:
2727
using: "composite"
2828
steps:
29-
- name: Setup Java
30-
uses: actions/setup-java@v4
29+
- name: Setup Java with cache
30+
uses: ./.github/actions/utils/setup-java-with-cache
3131
with:
32-
distribution: "temurin"
33-
java-version: "17"
34-
cache: "gradle"
32+
gradle-cache-disabled: "true"
3533

36-
- name: Setup Gradle
37-
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
38-
with:
39-
gradle-version: '9.2.1'
34+
- name: Lint SDK
35+
if: inputs.task == 'lint'
36+
shell: bash
37+
working-directory: foreign/java
38+
run: |
39+
echo "::group::Linting foreign/java"
40+
gradle check -x test
41+
echo "::endgroup::"
4042
41-
- name: Lint
43+
- name: Lint examples
4244
if: inputs.task == 'lint'
4345
shell: bash
46+
working-directory: examples/java
4447
run: |
45-
foreign/java/dev-support/checks/build.sh check -x test
48+
echo "::group::Linting examples/java"
49+
gradle check -x test
50+
echo "::endgroup::"
51+
52+
- name: Lint BDD
53+
if: inputs.task == 'lint'
54+
shell: bash
55+
working-directory: bdd/java
56+
run: |
57+
echo "::group::Linting bdd/java"
58+
gradle check -x test
59+
echo "::endgroup::"
4660
4761
- name: Build
4862
shell: bash
4963
if: inputs.task == 'build'
64+
working-directory: foreign/java
5065
run: |
51-
foreign/java/dev-support/checks/build.sh build -x test -x checkstyleMain -x checkstyleTest -x spotlessCheck
66+
gradle build -x test -x checkstyleMain -x checkstyleTest -x spotlessCheck
5267
BUILD_EXIT_CODE=$?
5368
5469
# List artifacts only if build succeeded
5570
if [ $BUILD_EXIT_CODE -eq 0 ]; then
5671
echo ""
5772
echo "Build artifacts:"
58-
find foreign/java -path "*/build/libs/*.jar" -type f 2>/dev/null | head -20 || echo "No jar artifacts found in build/libs directories"
73+
find . -path "*/build/libs/*.jar" -type f 2>/dev/null | head -20 || echo "No jar artifacts found in build/libs directories"
5974
fi
6075
6176
# Exit with build exit code
@@ -76,10 +91,10 @@ runs:
7691
- name: Test
7792
if: inputs.task == 'test'
7893
shell: bash
94+
working-directory: foreign/java
7995
env:
8096
USE_EXTERNAL_SERVER: true
81-
run: |
82-
foreign/java/dev-support/checks/build.sh test
97+
run: gradle test
8398

8499
- name: Copy test reports
85100
if: ${{ !cancelled() && inputs.task == 'test' }}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
# NOTE: this action sets up the Java toolchain + Gradle with caching,
19+
# it is a convenience wrapper, so that we can use it in all workflows.
20+
21+
name: setup-java-with-cache
22+
description: Setup Java toolchain and Gradle with caching
23+
inputs:
24+
java-version:
25+
description: "Java version to use"
26+
required: false
27+
default: "17"
28+
java-distribution:
29+
description: "Java distribution to use"
30+
required: false
31+
default: "temurin"
32+
gradle-version:
33+
description: "Gradle version to use"
34+
required: false
35+
default: "9.2.1"
36+
gradle-cache-disabled:
37+
description: "Whether to disable Gradle caching"
38+
required: false
39+
default: "false"
40+
41+
runs:
42+
using: "composite"
43+
steps:
44+
- name: Setup Java (with cache)
45+
if: inputs.gradle-cache-disabled != 'true'
46+
uses: actions/setup-java@v4
47+
with:
48+
distribution: ${{ inputs.java-distribution }}
49+
java-version: ${{ inputs.java-version }}
50+
cache: gradle
51+
52+
- name: Setup Java (no cache)
53+
if: inputs.gradle-cache-disabled == 'true'
54+
uses: actions/setup-java@v4
55+
with:
56+
distribution: ${{ inputs.java-distribution }}
57+
java-version: ${{ inputs.java-version }}
58+
59+
- name: Setup Gradle
60+
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
61+
with:
62+
gradle-version: ${{ inputs.gradle-version }}
63+
cache-disabled: ${{ inputs.gradle-cache-disabled }}
64+
65+
- name: Verify Java installation
66+
run: |
67+
echo "Java setup complete"
68+
java --version
69+
gradle --version
70+
shell: bash

.github/workflows/_test_examples.yml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,11 @@ jobs:
7171
path: ~/.cache/pip
7272
key: pip-${{ runner.os }}-${{ hashFiles('foreign/python/pyproject.toml') }}
7373

74-
- name: Setup Java
74+
- name: Setup Java with cache for examples
7575
if: inputs.component == 'examples-suite' && inputs.task == 'examples-java'
76-
uses: actions/setup-java@v4
76+
uses: ./.github/actions/utils/setup-java-with-cache
7777
with:
78-
distribution: "temurin"
79-
java-version: "17"
80-
cache: "gradle"
81-
82-
- name: Setup Gradle
83-
if: inputs.component == 'examples-suite' && inputs.task == 'examples-java'
84-
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
85-
with:
86-
gradle-version: "9.2.1"
78+
gradle-cache-disabled: "true"
8779

8880
- name: Setup Go with cache for examples
8981
if: inputs.component == 'examples-suite' && inputs.task == 'examples-go'

bdd/java/build.gradle.kts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
plugins {
2121
java
22+
id("com.diffplug.spotless") version "8.1.0"
2223
}
2324

2425
repositories {
@@ -33,6 +34,18 @@ dependencies {
3334
testImplementation("org.junit.platform:junit-platform-suite:1.11.0")
3435
}
3536

37+
spotless {
38+
java {
39+
palantirJavaFormat()
40+
endWithNewline()
41+
trimTrailingWhitespace()
42+
importOrder("", "\n", "javax|java", "\n", "\\#")
43+
removeUnusedImports()
44+
forbidWildcardImports()
45+
formatAnnotations()
46+
}
47+
}
48+
3649
tasks.test {
3750
useJUnitPlatform()
3851
}

bdd/java/src/test/java/org/apache/iggy/bdd/BasicMessagingSteps.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,8 @@ public void runningServer() {
5454
context.serverAddr = getenvOrDefault("IGGY_TCP_ADDRESS", "127.0.0.1:8090");
5555
HostPort hostPort = HostPort.parse(context.serverAddr);
5656

57-
IggyTcpClient client = IggyTcpClient.builder()
58-
.host(hostPort.host)
59-
.port(hostPort.port)
60-
.build();
57+
IggyTcpClient client =
58+
IggyTcpClient.builder().host(hostPort.host).port(hostPort.port).build();
6159

6260
client.connect();
6361
client.system().ping();
@@ -99,14 +97,16 @@ public void streamHasName(String streamName) {
9997

10098
@When("I create a topic with name {string} in stream {int} with {int} partitions")
10199
public void createTopic(String topicName, int streamId, int partitions) {
102-
TopicDetails topic = getClient().topics().createTopic(
103-
(long) streamId,
104-
(long) partitions,
105-
CompressionAlgorithm.None,
106-
BigInteger.ZERO,
107-
BigInteger.ZERO,
108-
Optional.empty(),
109-
topicName);
100+
TopicDetails topic = getClient()
101+
.topics()
102+
.createTopic(
103+
(long) streamId,
104+
(long) partitions,
105+
CompressionAlgorithm.None,
106+
BigInteger.ZERO,
107+
BigInteger.ZERO,
108+
Optional.empty(),
109+
topicName);
110110

111111
context.lastTopicId = topic.id();
112112
context.lastTopicName = topic.name();
@@ -136,11 +136,9 @@ public void sendMessages(int messageCount, int streamId, int topicId, int partit
136136
messages.add(Message.of(content));
137137
}
138138

139-
getClient().messages().sendMessages(
140-
(long) streamId,
141-
(long) topicId,
142-
Partitioning.partitionId((long) partitionId),
143-
messages);
139+
getClient()
140+
.messages()
141+
.sendMessages((long) streamId, (long) topicId, Partitioning.partitionId((long) partitionId), messages);
144142

145143
if (!messages.isEmpty()) {
146144
context.lastSentMessage = "test message " + (messageCount - 1);
@@ -154,14 +152,16 @@ public void messagesSentSuccessfully() {
154152

155153
@When("I poll messages from stream {int}, topic {int}, partition {int} starting from offset {int}")
156154
public void pollMessages(int streamId, int topicId, int partitionId, int startOffset) {
157-
context.lastPolledMessages = getClient().messages().pollMessages(
158-
(long) streamId,
159-
(long) topicId,
160-
Optional.of((long) partitionId),
161-
0L,
162-
PollingStrategy.offset(BigInteger.valueOf(startOffset)),
163-
100L,
164-
true);
155+
context.lastPolledMessages = getClient()
156+
.messages()
157+
.pollMessages(
158+
(long) streamId,
159+
(long) topicId,
160+
Optional.of((long) partitionId),
161+
0L,
162+
PollingStrategy.offset(BigInteger.valueOf(startOffset)),
163+
100L,
164+
true);
165165
}
166166

167167
@Then("I should receive {int} messages")

examples/java/build.gradle.kts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
plugins {
2121
java
2222
id("com.diffplug.spotless") version "8.1.0"
23-
checkstyle
2423
}
2524

2625
repositories {
@@ -36,19 +35,16 @@ dependencies {
3635
spotless {
3736
java {
3837
palantirJavaFormat()
39-
removeUnusedImports()
40-
trimTrailingWhitespace()
4138
endWithNewline()
42-
formatAnnotations()
39+
trimTrailingWhitespace()
4340
importOrder("", "\n", "javax|java", "\n", "\\#")
41+
removeUnusedImports()
42+
forbidWildcardImports()
43+
formatAnnotations()
4444
toggleOffOn()
4545
}
4646
}
4747

48-
checkstyle {
49-
toolVersion = "12.2.0"
50-
}
51-
5248
tasks.withType<JavaCompile> {
5349
dependsOn("spotlessApply")
5450
}

foreign/java/dev-support/checks/build.sh

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)