Skip to content

Commit

Permalink
Report the cache as disabled when Gradle User Home exists
Browse files Browse the repository at this point in the history
  • Loading branch information
bigdaz committed Aug 19, 2023
1 parent 8cade33 commit 68e1dcd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
22 changes: 22 additions & 0 deletions .github/workflows/demo-job-summary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion src/cache-reporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ export class CacheListener {
cacheReadOnly = false
cacheWriteOnly = false
cacheDisabled = false
cacheDisabledReason = 'disabled'

get fullyRestored(): boolean {
return this.cacheEntries.every(x => !x.wasRequestedButNotRestored())
}

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'
Expand Down
2 changes: 2 additions & 0 deletions src/caches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 68e1dcd

Please sign in to comment.