Skip to content

Commit

Permalink
Update to the latest build conventions (#407)
Browse files Browse the repository at this point in the history
* Update to the latest build conventions

- add windows build
- remove deprecated `capitalize` use.
- update spotbugs suppressions
  • Loading branch information
big-andy-coates authored Nov 21, 2023
1 parent 69e8ed7 commit 841360a
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 41 deletions.
22 changes: 20 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ permissions:
contents: read

jobs:
build:
build_linux:
permissions:
packages: write
runs-on: ubuntu-latest
Expand Down Expand Up @@ -75,9 +75,27 @@ jobs:
GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }}
run: |
./gradlew -Dgradle.publish.key="$GRADLE_PUBLISH_KEY" -Dgradle.publish.secret="$GRADLE_PUBLISH_SECRET" publishPlugins
build_windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: gradle/wrapper-validation-action@56b90f209b02bf6d1deae490e9ef18b21a389cd4 # v1.1.0
- name: Set up JDK
uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0
with:
java-version: '17'
distribution: 'adopt'
- name: Setup Gradle
uses: gradle/gradle-build-action@842c587ad8aa4c68eeba24c396e15af4c2e9f30a # v2.9.0
with:
gradle-home-cache-cleanup: true
- name: Build
run: ./gradlew.bat build -PexcludeContainerised

create-gh-release:
if: startsWith(github.ref, 'refs/tags/') && !endsWith(github.ref, '-alpha')
needs: build
needs: [build_linux, build_windows]
runs-on: ubuntu-latest
permissions:
contents: write
Expand Down
10 changes: 8 additions & 2 deletions buildSrc/src/main/kotlin/creek-common-convention.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
*
* <p>Apply to all java modules, usually excluding the root project in multi-module sets.
*
* <p>Version: 1.9
* <p>Versions:
* - 1.10: Add ability to exclude containerised tests
* - 1.9: Add `allDeps` task.
* - 1.8: Tweak test config to reduce build speed.
* - 1.7: Switch to setting Java version via toolchain
Expand Down Expand Up @@ -70,7 +71,12 @@ tasks.withType<JavaCompile> {
}

tasks.test {
useJUnitPlatform()
useJUnitPlatform() {
if (project.hasProperty("excludeContainerised")) {
excludeTags("ContainerisedTest")
}
}

setForkEvery(5)
maxParallelForks = Runtime.getRuntime().availableProcessors()
testLogging {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ publishing {
name.set("${project.group}:${artifactId}")

if (prependRootName) {
description.set("${rootProject.name.capitalize()} ${project.name} library".replace("-", " "))
description.set("${rootProject.name} ${project.name} library".replace("-", " "))
} else {
description.set("${project.name.capitalize()} library".replace("-", " "))
description.set("${project.name} library".replace("-", " "))
}

url.set("https://www.creekservice.org")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ publishing {
name.set("${project.group}:${artifactId}")

if (prependRootName) {
description.set("${rootProject.name.capitalize()} ${project.name} library".replace("-", " "))
description.set("${rootProject.name} ${project.name} library".replace("-", " "))
} else {
description.set("${project.name.capitalize()} library".replace("-", " "))
description.set("${project.name} library".replace("-", " "))
}

url.set("https://www.creekservice.org")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.creekservice.internal.kafka.extension.resource.ResourceRegistryFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
Expand All @@ -58,6 +59,7 @@
import org.testcontainers.utility.DockerImageName;

@Testcontainers
@Tag("ContainerisedTest")
@Execution(ExecutionMode.SAME_THREAD) // Due to static state
class ClientExtensionFunctionalTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.hamcrest.TypeSafeDiagnosingMatcher;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.parallel.Execution;
Expand All @@ -62,6 +63,7 @@
import org.testcontainers.utility.DockerImageName;

@Testcontainers
@Tag("ContainerisedTest")
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
@Execution(ExecutionMode.SAME_THREAD) // Due to static state
Expand Down
6 changes: 6 additions & 0 deletions config/spotbugs/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@
<!-- Exclude generated sources -->
<Source name="~.*[\\/]build[\\/]generated[\\/]source.*" />
</Match>

<Match>
<!-- Disable this check as it leads to longer names and harder to read code -->
<!-- Discussion: https://github.com/spotbugs/spotbugs/issues/2627 -->
<Bug pattern="PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES"/>
</Match>
</FindBugsFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
import org.creekservice.api.system.test.extension.test.model.TestExecutionResult;
import org.creekservice.api.system.test.extension.test.model.TestSuiteResult;
import org.creekservice.api.test.util.TestPaths;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

@Tag("ContainerisedTest")
class KafkaTestExtensionFunctionalTest {

private static final Path TESTCASES =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.creekservice.internal.kafka.streams.test.extension.handler;

import static java.lang.System.lineSeparator;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThrows;
Expand Down Expand Up @@ -134,15 +135,24 @@ void shouldThrowOnUnmatched() {
assertThat(
e.getMessage(),
is(
"1 expected record(s) not found.\n"
+ "Unmatched records: [\n"
+ "\tExpected: e-record\n"
+ "\tActual: [\n"
+ "\t\t(mismatch details) rec1\n"
+ "\t]\n"
+ "]\n"
+ "Matched records: [\n"
+ "\trec0\n"
"1 expected record(s) not found."
+ lineSeparator()
+ "Unmatched records: ["
+ lineSeparator()
+ "\tExpected: e-record"
+ lineSeparator()
+ "\tActual: ["
+ lineSeparator()
+ "\t\t(mismatch details) rec1"
+ lineSeparator()
+ "\t]"
+ lineSeparator()
+ "]"
+ lineSeparator()
+ "Matched records: ["
+ lineSeparator()
+ "\trec0"
+ lineSeparator()
+ "]"));
}

Expand All @@ -159,9 +169,12 @@ void shouldThrowOnExtra() {
assertThat(
e.getMessage(),
is(
"Additional records were produced.\n"
+ "Unmatched records: [\n"
+ "\textra\n"
"Additional records were produced."
+ lineSeparator()
+ "Unmatched records: ["
+ lineSeparator()
+ "\textra"
+ lineSeparator()
+ "]"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.creekservice.internal.kafka.streams.test.extension.model;

import static java.lang.System.lineSeparator;
import static org.creekservice.api.kafka.metadata.KafkaTopicDescriptor.DEFAULT_CLUSTER_NAME;
import static org.creekservice.internal.kafka.streams.test.extension.model.ModelUtil.createParser;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -149,9 +148,8 @@ void shouldThrowIfNothingDefinesTopicName() {
"Cannot construct instance of"
+ " `org.creekservice.internal.kafka.streams.test.extension.model.TopicExpectation`,"
+ " problem: Topic not set. Topic must be supplied either at the file"
+ " or record level. location: unknown"
+ lineSeparator()
+ " at [Source: (StringReader); line: 8, column: 13]"));
+ " or record level. location: unknown\n"
+ " at [Source: (StringReader); line: 8, column: 13]"));
}

@Test
Expand Down Expand Up @@ -254,9 +252,8 @@ void shouldThrowOnNoRecords() {
is(
"Cannot construct instance of"
+ " `org.creekservice.internal.kafka.streams.test.extension.model.TopicExpectation`,"
+ " problem: At least one record is required"
+ lineSeparator()
+ " at [Source: (StringReader); line: 4, column: 12]"));
+ " problem: At least one record is required\n"
+ " at [Source: (StringReader); line: 4, column: 12]"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.creekservice.internal.kafka.streams.test.extension.model;

import static java.lang.System.lineSeparator;
import static org.creekservice.api.kafka.metadata.KafkaTopicDescriptor.DEFAULT_CLUSTER_NAME;
import static org.creekservice.internal.kafka.streams.test.extension.model.ModelUtil.createParser;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -149,9 +148,8 @@ void shouldThrowIfNothingDefinesTopicName() {
"Cannot construct instance of"
+ " `org.creekservice.internal.kafka.streams.test.extension.model.TopicInput`,"
+ " problem: Topic not set. Topic must be supplied either at the file"
+ " or record level. location: unknown"
+ lineSeparator()
+ " at [Source: (StringReader); line: 8, column: 13]"));
+ " or record level. location: unknown\n"
+ " at [Source: (StringReader); line: 8, column: 13]"));
}

@Test
Expand Down Expand Up @@ -254,9 +252,8 @@ void shouldThrowOnNoRecords() {
is(
"Cannot construct instance of"
+ " `org.creekservice.internal.kafka.streams.test.extension.model.TopicInput`,"
+ " problem: At least one record is required"
+ lineSeparator()
+ " at [Source: (StringReader); line: 4, column: 12]"));
+ " problem: At least one record is required\n"
+ " at [Source: (StringReader); line: 4, column: 12]"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.creekservice.internal.kafka.streams.test.extension.model;

import static java.lang.System.lineSeparator;
import static org.creekservice.api.kafka.metadata.KafkaTopicDescriptor.DEFAULT_CLUSTER_NAME;
import static org.creekservice.internal.kafka.streams.test.extension.model.ModelUtil.createParser;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -218,8 +217,7 @@ void shouldThrowOnUnknownProperty() {
assertThat(
e.getMessage(),
is(
"Unknown property: not_value"
+ lineSeparator()
"Unknown property: not_value\n"
+ " at [Source: (StringReader); line: 5, column: 10]"));
}

Expand All @@ -241,8 +239,7 @@ void shouldThrowOnEmptyTopicName() {
assertThat(
e.getMessage(),
is(
"Property can not be blank: topic"
+ lineSeparator()
"Property can not be blank: topic\n"
+ " at [Source: (StringReader); line: 2, column: 10]"));
}

Expand All @@ -264,8 +261,7 @@ void shouldThrowOnEmptyClusterName() {
assertThat(
e.getMessage(),
is(
"Property can not be blank: cluster"
+ lineSeparator()
"Property can not be blank: cluster\n"
+ " at [Source: (StringReader); line: 3, column: 13]"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs;
import org.testcontainers.DockerClientFactory;

@Tag("ContainerisedTest")
@Execution(ExecutionMode.SAME_THREAD) // Due to static state
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class StartKafkaTestListenerFunctionalTest {
Expand Down
5 changes: 5 additions & 0 deletions test-service/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ val buildAppImage = tasks.create("buildAppImage", DockerBuildImage::class) {
buildArgs.put("APP_NAME", project.name)
buildArgs.put("APP_VERSION", "${project.version}")
images.add("ghcr.io/creek-service/${rootProject.name}-${project.name}:latest")

onlyIf {
// Exclude the task if running on Windows (as images don't build on Windows)
!System.getProperty("os.name").lowercase().contains("win")
}
}

tasks.register<Copy>("prepareDocker") {
Expand Down

0 comments on commit 841360a

Please sign in to comment.