From 53af4d4f57f1d7543f90c964e4c4987bf936a0b8 Mon Sep 17 00:00:00 2001 From: Daz DeBoer Date: Thu, 17 Mar 2022 11:15:38 -0600 Subject: [PATCH] Fix check for config-cache usage Now that environment variable reads are auto-detected by Gradle 7.4, we need a different mechanism to check that the configuration cache is being used successfully. --- .../integTest-caching-configuration-cache.yml | 23 ++++++++++++++----- __tests__/samples/groovy-dsl/build.gradle | 7 +++--- __tests__/samples/kotlin-dsl/build.gradle.kts | 7 +++--- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/.github/workflows/integTest-caching-configuration-cache.yml b/.github/workflows/integTest-caching-configuration-cache.yml index 654c8d8..300cf57 100644 --- a/.github/workflows/integTest-caching-configuration-cache.yml +++ b/.github/workflows/integTest-caching-configuration-cache.yml @@ -46,11 +46,16 @@ jobs: uses: ./ with: cache-read-only: true - - name: Execute Gradle build and verify cached configuration - env: - VERIFY_CACHED_CONFIGURATION: true + - name: Groovy build with configuration-cache enabled + id: execute working-directory: __tests__/samples/groovy-dsl run: ./gradlew test --configuration-cache + - name: Check that configuration-cache was used + if: ${{ steps.execute.outputs.task_configured == 'yes' }} + uses: actions/github-script@v5 + with: + script: | + core.setFailed('Configuration cache was not used - task was configured unexpectedly') # Check that the build can run when no extracted cache entries are restored no-extracted-cache-entries-restored: @@ -123,8 +128,14 @@ jobs: uses: ./ with: cache-read-only: true - - name: Execute 'test' again and verify cached configuration - env: - VERIFY_CACHED_CONFIGURATION: true + - name: Execute 'test' again with configuration-cache enabled + id: execute working-directory: __tests__/samples/kotlin-dsl run: ./gradlew test --configuration-cache + - name: Check that configuration-cache was used + if: ${{ steps.execute.outputs.task_configured == 'yes' }} + uses: actions/github-script@v5 + with: + script: | + core.setFailed('Configuration cache was not used - task was configured unexpectedly') + diff --git a/__tests__/samples/groovy-dsl/build.gradle b/__tests__/samples/groovy-dsl/build.gradle index 8ea4e76..dead78f 100644 --- a/__tests__/samples/groovy-dsl/build.gradle +++ b/__tests__/samples/groovy-dsl/build.gradle @@ -11,10 +11,9 @@ dependencies { } tasks.named("test").configure { - // Use an environment variable to bypass config-cache checks - if (System.getenv('VERIFY_CACHED_CONFIGURATION') != null) { - throw new RuntimeException("Configuration was not cached: unexpected configuration of test task") - } + // Echo an output value so we can detect configuration-cache usage + println "::set-output name=task_configured::yes" + doLast { if (System.properties.verifyCachedBuild) { throw new RuntimeException("Build was not cached: unexpected execution of test task") diff --git a/__tests__/samples/kotlin-dsl/build.gradle.kts b/__tests__/samples/kotlin-dsl/build.gradle.kts index 18b4420..22d1375 100644 --- a/__tests__/samples/kotlin-dsl/build.gradle.kts +++ b/__tests__/samples/kotlin-dsl/build.gradle.kts @@ -18,10 +18,9 @@ tasks.test { } tasks.named("test").configure { - // Use an environment variable to bypass config-cache checks - if (System.getenv("VERIFY_CACHED_CONFIGURATION") != null) { - throw RuntimeException("Configuration was not cached: unexpected configuration of test task") - } + // Echo an output value so we can detect configuration-cache usage + println("::set-output name=task_configured::yes") + doLast { if (System.getProperties().containsKey("verifyCachedBuild")) { throw RuntimeException("Build was not cached: unexpected execution of test task")