From 68e1dcdea428097ba709a787c15f7b1b5aa599bd Mon Sep 17 00:00:00 2001 From: daz Date: Sat, 19 Aug 2023 12:37:50 -0600 Subject: [PATCH] Report the cache as disabled when Gradle User Home exists Fixes #434 --- .github/workflows/demo-job-summary.yml | 22 ++++++++++++++++++++++ src/cache-reporting.ts | 3 ++- src/caches.ts | 2 ++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/.github/workflows/demo-job-summary.yml b/.github/workflows/demo-job-summary.yml index 6150e20..5dce83b 100644 --- a/.github/workflows/demo-job-summary.yml +++ b/.github/workflows/demo-job-summary.yml @@ -41,3 +41,25 @@ jobs: working-directory: .github/workflow-samples/groovy-dsl continue-on-error: true run: ./gradlew not-a-real-task + + pre-existing-gradle-home: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v3 + - name: Build distribution + shell: bash + run: | + npm install + npm run build + - name: Pre-create Gradle User Home + shell: bash + run: | + mkdir ~/.gradle + mkdir ~/.gradle/caches + touch ~/.gradle/caches/dummy.txt + - name: Setup Gradle + uses: ./ + - name: Run build + working-directory: .github/workflow-samples/groovy-dsl + run: ./gradlew assemble diff --git a/src/cache-reporting.ts b/src/cache-reporting.ts index 12a0b50..11d5fd2 100644 --- a/src/cache-reporting.ts +++ b/src/cache-reporting.ts @@ -10,6 +10,7 @@ export class CacheListener { cacheReadOnly = false cacheWriteOnly = false cacheDisabled = false + cacheDisabledReason = 'disabled' get fullyRestored(): boolean { return this.cacheEntries.every(x => !x.wasRequestedButNotRestored()) @@ -17,7 +18,7 @@ export class CacheListener { get cacheStatus(): string { if (!cache.isFeatureAvailable()) return 'not available' - if (this.cacheDisabled) return 'disabled' + if (this.cacheDisabled) return this.cacheDisabledReason if (this.cacheWriteOnly) return 'write-only' if (this.cacheReadOnly) return 'read-only' return 'enabled' diff --git a/src/caches.ts b/src/caches.ts index bdebf8d..4de55db 100644 --- a/src/caches.ts +++ b/src/caches.ts @@ -29,6 +29,8 @@ export async function restore(gradleUserHome: string, cacheListener: CacheListen core.info('Gradle User Home already exists: will not restore from cache.') // Initialize pre-existing Gradle User Home. gradleStateCache.init() + cacheListener.cacheDisabled = true + cacheListener.cacheDisabledReason = 'disabled due to pre-existing Gradle User Home' return }