From 1acac841e442eabf76ef93c108f45edb0d69f4ca Mon Sep 17 00:00:00 2001 From: Andy Coates <8012398+big-andy-coates@users.noreply.github.com> Date: Tue, 16 Jan 2024 15:19:43 +0000 Subject: [PATCH] Update to latest conventions (#272) * Update to latest conventions * Fix build --- .../example-service/Dockerfile | 5 +--- .../example-service/build.gradle.kts | 2 +- .github/workflows/build.yml | 15 ++++++++--- .github/workflows/codeql.yml | 6 ++++- .github/workflows/dependabot-auto-merge.yml | 3 +-- .github/workflows/test-scripts.yml | 5 +++- .github/workflows/version.yml | 5 +++- buildSrc/settings.gradle.kts | 3 +++ .../main/kotlin/common-convention.gradle.kts | 25 +++++++++++++------ handle-occurrence-service/Dockerfile | 6 +---- handle-occurrence-service/build.gradle.kts | 2 +- 11 files changed, 50 insertions(+), 27 deletions(-) diff --git a/.creek/service_template/example-service/Dockerfile b/.creek/service_template/example-service/Dockerfile index 52b22b0..4577232 100644 --- a/.creek/service_template/example-service/Dockerfile +++ b/.creek/service_template/example-service/Dockerfile @@ -5,17 +5,14 @@ ENV VERSION=$APP_VERSION LABEL org.opencontainers.image.source=https://github.com/creek-service/basic-kafka-streams-demo/tree/main/example-service -RUN yum update -y -RUN yum install -y tar lsof RUN mkdir -p /opt/creek COPY bin /bin COPY log4j /log -COPY ${APP_NAME}-${APP_VERSION}.tar /opt/creek +COPY ${APP_NAME}-${APP_VERSION} /opt/creek/${APP_NAME}-${APP_VERSION} WORKDIR /opt/creek -RUN tar xf ${APP_NAME}-${APP_VERSION}.tar RUN ln -s ${APP_NAME}-${APP_VERSION} service ENTRYPOINT ["/bin/run.sh"] \ No newline at end of file diff --git a/.creek/service_template/example-service/build.gradle.kts b/.creek/service_template/example-service/build.gradle.kts index e9b281c..7e3c5f3 100644 --- a/.creek/service_template/example-service/build.gradle.kts +++ b/.creek/service_template/example-service/build.gradle.kts @@ -57,7 +57,7 @@ tasks.register("prepareDocker") { from( layout.projectDirectory.file("Dockerfile"), - layout.buildDirectory.file("distributions/${project.name}-${project.version}.tar"), + tarTree(layout.buildDirectory.file("distributions/${project.name}-${project.version}.tar")), layout.projectDirectory.dir("include"), ) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7dea4f3..9608196 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ permissions: contents: read jobs: - build: + build_linux: if: ${{ github.run_number != 1 }} runs-on: ubuntu-latest steps: @@ -24,7 +24,10 @@ jobs: with: java-version: '17' distribution: 'adopt' - cache: gradle + - name: Setup Gradle + uses: gradle/gradle-build-action@a4cf152f482c7ca97ef56ead29bf08bcd953284c # v2.7.0 + with: + gradle-home-cache-cleanup: true - name: Build env: COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} @@ -35,7 +38,7 @@ jobs: permissions: contents: write packages: write - needs: build + needs: build_linux runs-on: ubuntu-latest concurrency: group: "${{ github.repository }}-release" @@ -51,7 +54,11 @@ jobs: with: java-version: '17' distribution: 'adopt' - cache: gradle + + - name: Setup Gradle + uses: gradle/gradle-build-action@a4cf152f482c7ca97ef56ead29bf08bcd953284c # v2.7.0 + with: + gradle-home-cache-cleanup: true - name: Login to GitHub Container Registry uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 with: diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 96e211c..7fdb39b 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -37,7 +37,11 @@ jobs: with: java-version: '17' distribution: 'adopt' - cache: gradle + + - name: Setup Gradle + uses: gradle/gradle-build-action@a4cf152f482c7ca97ef56ead29bf08bcd953284c # v2.7.0 + with: + gradle-home-cache-cleanup: true - name: Build run: ./gradlew test diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml index 119f465..440bde5 100644 --- a/.github/workflows/dependabot-auto-merge.yml +++ b/.github/workflows/dependabot-auto-merge.yml @@ -3,8 +3,7 @@ name: Dependabot on: pull_request: - branches: - - main + branches: [ main ] permissions: contents: read diff --git a/.github/workflows/test-scripts.yml b/.github/workflows/test-scripts.yml index 44a30eb..9078c33 100644 --- a/.github/workflows/test-scripts.yml +++ b/.github/workflows/test-scripts.yml @@ -22,7 +22,10 @@ jobs: with: java-version: '17' distribution: 'adopt' - cache: gradle + - name: Setup Gradle + uses: gradle/gradle-build-action@a4cf152f482c7ca97ef56ead29bf08bcd953284c # v2.7.0 + with: + gradle-home-cache-cleanup: true - name: Run boostrap script shell: zsh {0} run: ./.creek/bootstrap.sh "some-User-name/a_Nother-REpo_name" "some-User-name" diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml index f195976..0db9728 100644 --- a/.github/workflows/version.yml +++ b/.github/workflows/version.yml @@ -30,7 +30,10 @@ jobs: with: java-version: '17' distribution: 'adopt' - cache: gradle + - name: Setup Gradle + uses: gradle/gradle-build-action@a4cf152f482c7ca97ef56ead29bf08bcd953284c # v2.7.0 + with: + gradle-home-cache-cleanup: true - name: Increment version if: contains(fromJson('["Major", "Minor", "Patch"]'), github.event.inputs.part) run: | diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts index defca0f..7a49d9d 100644 --- a/buildSrc/settings.gradle.kts +++ b/buildSrc/settings.gradle.kts @@ -14,3 +14,6 @@ * limitations under the License. */ +plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version "0.4.0" +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/common-convention.gradle.kts b/buildSrc/src/main/kotlin/common-convention.gradle.kts index 90b8fb7..0dfa89b 100644 --- a/buildSrc/src/main/kotlin/common-convention.gradle.kts +++ b/buildSrc/src/main/kotlin/common-convention.gradle.kts @@ -19,12 +19,14 @@ * *

Apply to all java modules, usually excluding the root project in multi-module sets. * - *

Version: 1.7 + *

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 * - 1.6: Remove GitHub packages for snapshots * - 1.5: Add filters to exclude generated sources * - 1.4: Add findsecbugs-plugin - * - 1.3: Fail on warnings for test code too. */ plugins { @@ -62,8 +64,8 @@ tasks.withType { tasks.test { useJUnitPlatform() - setForkEvery(1) - maxParallelForks = 4 + setForkEvery(5) + maxParallelForks = Runtime.getRuntime().availableProcessors() testLogging { showStandardStreams = true exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL @@ -75,7 +77,7 @@ tasks.test { spotless { java { - googleJavaFormat("1.15.0").aosp() + googleJavaFormat("1.15.0").aosp().reflowLongStrings() indentWithSpaces() importOrder() removeUnusedImports() @@ -109,17 +111,26 @@ if (rootProject.name != project.name) { } } -tasks.register("format") { +val format = tasks.register("format") { group = "creek" description = "Format the code" dependsOn("spotlessCheck", "spotlessApply") } -tasks.register("static") { +val static = tasks.register("static") { group = "creek" description = "Run static code analysis" dependsOn("checkstyleMain", "checkstyleTest", "spotbugsMain", "spotbugsTest") + + shouldRunAfter(format) } +tasks.test { + shouldRunAfter(static) +} + +// See: https://solidsoft.wordpress.com/2014/11/13/gradle-tricks-display-dependencies-for-all-subprojects-in-multi-project-build/ +tasks.register("allDeps") {} + diff --git a/handle-occurrence-service/Dockerfile b/handle-occurrence-service/Dockerfile index 7088c7c..38b9a63 100644 --- a/handle-occurrence-service/Dockerfile +++ b/handle-occurrence-service/Dockerfile @@ -5,17 +5,13 @@ ENV VERSION=$APP_VERSION LABEL org.opencontainers.image.source=https://github.com/creek-service/basic-kafka-streams-demo/tree/main/handle-occurrence-service -RUN yum update -y -RUN yum install -y tar lsof - RUN mkdir -p /opt/creek COPY bin /bin COPY log4j /log -COPY ${APP_NAME}-${APP_VERSION}.tar /opt/creek +COPY ${APP_NAME}-${APP_VERSION} /opt/creek/${APP_NAME}-${APP_VERSION} WORKDIR /opt/creek -RUN tar xf ${APP_NAME}-${APP_VERSION}.tar RUN ln -s ${APP_NAME}-${APP_VERSION} service ENTRYPOINT ["/bin/run.sh"] \ No newline at end of file diff --git a/handle-occurrence-service/build.gradle.kts b/handle-occurrence-service/build.gradle.kts index 4881321..ebbdf0f 100644 --- a/handle-occurrence-service/build.gradle.kts +++ b/handle-occurrence-service/build.gradle.kts @@ -41,7 +41,7 @@ tasks.register("prepareDocker") { from( layout.projectDirectory.file("Dockerfile"), - layout.buildDirectory.file("distributions/${project.name}-${project.version}.tar"), + tarTree(layout.buildDirectory.file("distributions/${project.name}-${project.version}.tar")), layout.projectDirectory.dir("include"), )