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.
This commit is contained in:
Daz DeBoer 2022-03-17 11:15:38 -06:00
parent b10e7caf66
commit 53af4d4f57
No known key found for this signature in database
GPG key ID: DD6B9F0B06683D5D
3 changed files with 23 additions and 14 deletions

View file

@ -46,11 +46,16 @@ jobs:
uses: ./ uses: ./
with: with:
cache-read-only: true cache-read-only: true
- name: Execute Gradle build and verify cached configuration - name: Groovy build with configuration-cache enabled
env: id: execute
VERIFY_CACHED_CONFIGURATION: true
working-directory: __tests__/samples/groovy-dsl working-directory: __tests__/samples/groovy-dsl
run: ./gradlew test --configuration-cache 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 # Check that the build can run when no extracted cache entries are restored
no-extracted-cache-entries-restored: no-extracted-cache-entries-restored:
@ -123,8 +128,14 @@ jobs:
uses: ./ uses: ./
with: with:
cache-read-only: true cache-read-only: true
- name: Execute 'test' again and verify cached configuration - name: Execute 'test' again with configuration-cache enabled
env: id: execute
VERIFY_CACHED_CONFIGURATION: true
working-directory: __tests__/samples/kotlin-dsl working-directory: __tests__/samples/kotlin-dsl
run: ./gradlew test --configuration-cache 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')

View file

@ -11,10 +11,9 @@ dependencies {
} }
tasks.named("test").configure { tasks.named("test").configure {
// Use an environment variable to bypass config-cache checks // Echo an output value so we can detect configuration-cache usage
if (System.getenv('VERIFY_CACHED_CONFIGURATION') != null) { println "::set-output name=task_configured::yes"
throw new RuntimeException("Configuration was not cached: unexpected configuration of test task")
}
doLast { doLast {
if (System.properties.verifyCachedBuild) { if (System.properties.verifyCachedBuild) {
throw new RuntimeException("Build was not cached: unexpected execution of test task") throw new RuntimeException("Build was not cached: unexpected execution of test task")

View file

@ -18,10 +18,9 @@ tasks.test {
} }
tasks.named("test").configure { tasks.named("test").configure {
// Use an environment variable to bypass config-cache checks // Echo an output value so we can detect configuration-cache usage
if (System.getenv("VERIFY_CACHED_CONFIGURATION") != null) { println("::set-output name=task_configured::yes")
throw RuntimeException("Configuration was not cached: unexpected configuration of test task")
}
doLast { doLast {
if (System.getProperties().containsKey("verifyCachedBuild")) { if (System.getProperties().containsKey("verifyCachedBuild")) {
throw RuntimeException("Build was not cached: unexpected execution of test task") throw RuntimeException("Build was not cached: unexpected execution of test task")