From 8c7c769cdfd3848457e0a70de8518f08ad7053b4 Mon Sep 17 00:00:00 2001 From: Richard North Date: Sat, 16 May 2020 20:43:00 +0100 Subject: [PATCH] Dynamic CI jobs for examples (#2677) --- .../{ci-dind.yml => ci-docker-wormhole.yml} | 2 +- .github/workflows/ci-examples.yml | 73 +++++++++++++++++++ .github/workflows/ci.yml | 27 ------- examples/build.gradle | 5 ++ examples/settings.gradle | 36 +++++++++ gradle/ci-support.gradle | 6 +- settings.gradle | 38 +++++----- 7 files changed, 137 insertions(+), 50 deletions(-) rename .github/workflows/{ci-dind.yml => ci-docker-wormhole.yml} (96%) create mode 100644 .github/workflows/ci-examples.yml diff --git a/.github/workflows/ci-dind.yml b/.github/workflows/ci-docker-wormhole.yml similarity index 96% rename from .github/workflows/ci-dind.yml rename to .github/workflows/ci-docker-wormhole.yml index 15bd5ec76ee..3c6da54dc1f 100644 --- a/.github/workflows/ci-dind.yml +++ b/.github/workflows/ci-docker-wormhole.yml @@ -1,4 +1,4 @@ -name: in-container +name: CI-Docker-Wormhole on: pull_request: {} diff --git a/.github/workflows/ci-examples.yml b/.github/workflows/ci-examples.yml new file mode 100644 index 00000000000..bec794dc167 --- /dev/null +++ b/.github/workflows/ci-examples.yml @@ -0,0 +1,73 @@ +name: CI-Examples + +on: + pull_request: {} + push: { branches: [ master ] } + +env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + +jobs: + find_gradle_jobs: + runs-on: ubuntu-18.04 + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-java@v1 + with: + java-version: '1.8' + - name: Cache Gradle Home files + uses: actions/cache@v1 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-home-testmatrix-examples-${{ hashFiles('**/*.gradle') }} + restore-keys: | + ${{ runner.os }}-gradle-home-testmatrix-examples- + ${{ runner.os }}-gradle-home- + - id: set-matrix + working-directory: ./examples/ + env: + # Since we override the tests executor, + # we should not push empty results to the cache + READ_ONLY_REMOTE_GRADLE_CACHE: true + run: | + TASKS=$(./gradlew --no-daemon --parallel -q testMatrix) + echo $TASKS + echo "::set-output name=matrix::{\"gradle_args\":$TASKS}" + check: + needs: find_gradle_jobs + strategy: + fail-fast: false + matrix: ${{ fromJson(needs.find_gradle_jobs.outputs.matrix) }} + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-java@v1 + with: + java-version: '1.8' + - name: Cache Gradle Home files + uses: actions/cache@v1 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-home-examples-${{matrix.gradle_args}}_check-${{ hashFiles('**/*.gradle') }} + restore-keys: | + ${{ runner.os }}-gradle-home-examples-${{matrix.gradle_args}}_check- + ${{ runner.os }}-gradle-home-examples-${{matrix.gradle_args}}_check- + ${{ runner.os }}-gradle-home-examples- + - name: Clear existing docker image cache + run: docker image prune -af + - name: Build and test Examples with Gradle (${{matrix.gradle_args}}) + working-directory: ./examples/ + run: | + ./gradlew --no-daemon --continue --scan --info ${{matrix.gradle_args}} + - name: Aggregate Examples test reports with ciMate + if: always() + env: + CIMATE_PROJECT_ID: 2348n4vl + CIMATE_CI_KEY: "Examples / ${{ runner.os }} / ${{matrix.gradle_args}}" + run: | + wget -q https://get.cimate.io/release/linux/cimate + chmod +x cimate + ./cimate "**/TEST-*.xml" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a6baaf7e92d..90e64dde133 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,30 +69,3 @@ jobs: wget -q https://get.cimate.io/release/linux/cimate chmod +x cimate ./cimate "**/TEST-*.xml" - examples: - runs-on: ubuntu-18.04 - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-java@v1 - with: - java-version: '1.8' - - name: Cache Gradle Home files - uses: actions/cache@v1 - with: - path: ~/.gradle/caches - key: ${{ runner.os }}-gradle-home-examples-${{ hashFiles('**/*.gradle*') }} - restore-keys: | - ${{ runner.os }}-gradle-home-examples- - - name: Build and test Examples with Gradle - working-directory: ./examples/ - run: | - ./gradlew --no-daemon --scan --info check - - name: Aggregate test reports with ciMate - if: always() - env: - CIMATE_PROJECT_ID: 2348n4vl - CIMATE_CI_KEY: examples - run: | - wget -q https://get.cimate.io/release/linux/cimate - chmod +x cimate - ./cimate "**/TEST-*.xml" diff --git a/examples/build.gradle b/examples/build.gradle index b2ecf1b0be3..25b7c1fcf29 100644 --- a/examples/build.gradle +++ b/examples/build.gradle @@ -1 +1,6 @@ // empty build.gradle for dependabot +apply from: "$rootDir/../gradle/ci-support.gradle" + +subprojects { + apply plugin:"java" +} diff --git a/examples/settings.gradle b/examples/settings.gradle index ef47a61f807..25da14a0931 100644 --- a/examples/settings.gradle +++ b/examples/settings.gradle @@ -1,3 +1,18 @@ +buildscript { + repositories { + maven { + url "https://plugins.gradle.org/m2/" + } + } + dependencies { + classpath "gradle.plugin.ch.myniva.gradle:s3-build-cache:0.10.0" + classpath "com.gradle.enterprise:com.gradle.enterprise.gradle.plugin:3.2.1" + } +} + +apply plugin: 'ch.myniva.s3-build-cache' +apply plugin: 'com.gradle.enterprise' + rootProject.name = 'testcontainers-examples' includeBuild '..' @@ -15,3 +30,24 @@ include 'spring-boot' include 'cucumber' include 'spring-boot-kotlin-redis' include 'spock' + +ext.isMasterBuild = false || + (System.getenv("GITHUB_REF") == "refs/heads/master") || + (System.getenv("BUILD_SOURCEBRANCHNAME") == "master") + +buildCache { + local { + enabled = !isMasterBuild + } + + remote(ch.myniva.gradle.caching.s3.AwsS3BuildCache) { + endpoint = 'fra1.digitaloceanspaces.com' + region = 'fra1' + bucket = 'testcontainers' + path = 'cache' + push = isMasterBuild && !System.getenv("READ_ONLY_REMOTE_GRADLE_CACHE") + headers = [ + 'x-amz-acl': 'public-read' + ] + } +} diff --git a/gradle/ci-support.gradle b/gradle/ci-support.gradle index 7c3408068b3..e83c936f2f3 100644 --- a/gradle/ci-support.gradle +++ b/gradle/ci-support.gradle @@ -28,9 +28,9 @@ gradle.taskGraph.whenReady { subproject.tasks.withType(Test).all { testExecuter([execute: { spec, processor -> }, stopNow:{}] as org.gradle.api.internal.tasks.testing.TestExecuter) } - subproject.tasks.findByName("shadowJar").enabled = false - subproject.tasks.findByName("javadoc").enabled = false - subproject.tasks.findByName("delombok").enabled = false + subproject.tasks.findByName("shadowJar")?.enabled = false + subproject.tasks.findByName("javadoc")?.enabled = false + subproject.tasks.findByName("delombok")?.enabled = false subproject.tasks.findByName("japicmp")?.enabled = false } } diff --git a/settings.gradle b/settings.gradle index 150d79f89fe..2ea21599ceb 100644 --- a/settings.gradle +++ b/settings.gradle @@ -13,6 +13,25 @@ buildscript { apply plugin: 'ch.myniva.s3-build-cache' apply plugin: 'com.gradle.enterprise' +rootProject.name = 'testcontainers-java' + +include "bom" + +include "testcontainers" +project(':testcontainers').projectDir = "$rootDir/core" as File + +file('modules').eachDir { dir -> + include dir.name + project(":${dir.name}").projectDir = dir +} + +include ':docs:examples:junit4:generic' +include ':docs:examples:junit4:redis' +include ':docs:examples:junit5:redis' +include ':docs:examples:spock:redis' + +include 'test-support' + ext.isMasterBuild = false || (System.getenv("GITHUB_REF") == "refs/heads/master") || (System.getenv("BUILD_SOURCEBRANCHNAME") == "master") @@ -34,25 +53,6 @@ buildCache { } } -rootProject.name = 'testcontainers-java' - -include "bom" - -include "testcontainers" -project(':testcontainers').projectDir = "$rootDir/core" as File - -file('modules').eachDir { dir -> - include dir.name - project(":${dir.name}").projectDir = dir -} - -include ':docs:examples:junit4:generic' -include ':docs:examples:junit4:redis' -include ':docs:examples:junit5:redis' -include ':docs:examples:spock:redis' - -include 'test-support' - gradleEnterprise { buildScan { termsOfServiceUrl = 'https://gradle.com/terms-of-service'