mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-11-22 09:02:50 +00:00
parent
68e1dcdea4
commit
3d49588efc
5 changed files with 66 additions and 7 deletions
|
@ -99,3 +99,40 @@ jobs:
|
||||||
working-directory: .github/workflow-samples/groovy-dsl
|
working-directory: .github/workflow-samples/groovy-dsl
|
||||||
run: ./gradlew test
|
run: ./gradlew test
|
||||||
|
|
||||||
|
# Test that a pre-existing gradle-user-home can be overwritten by the restored cache
|
||||||
|
pre-existing-gradle-home:
|
||||||
|
needs: seed-build
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: ${{fromJSON(inputs.runner-os)}}
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout sources
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Download distribution if required
|
||||||
|
uses: ./.github/actions/download-dist
|
||||||
|
- name: Pre-create Gradle User Home
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.gradle/caches
|
||||||
|
touch ~/.gradle/gradle.properties
|
||||||
|
touch ~/.gradle/caches/dummy.txt
|
||||||
|
- name: Setup Gradle
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
cache-read-only: true
|
||||||
|
cache-overwrite-existing: true
|
||||||
|
- name: Check that pre-existing content still exists
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
if [ ! -e ~/.gradle/caches/dummy.txt ]; then
|
||||||
|
echo "::error ::Should find dummy.txt after cache restore"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [ ! -e ~/.gradle/gradle.properties ]; then
|
||||||
|
echo "::error ::Should find gradle.properties after cache restore"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
- name: Execute Gradle build with --offline
|
||||||
|
working-directory: .github/workflow-samples/groovy-dsl
|
||||||
|
run: ./gradlew test --offline
|
||||||
|
|
|
@ -35,6 +35,11 @@ inputs:
|
||||||
required: false
|
required: false
|
||||||
default: false
|
default: false
|
||||||
|
|
||||||
|
cache-overwrite-existing:
|
||||||
|
description: When 'true', a pre-existing Gradle User Home will not prevent the cache from being restored.
|
||||||
|
required: false
|
||||||
|
default: false
|
||||||
|
|
||||||
gradle-home-cache-includes:
|
gradle-home-cache-includes:
|
||||||
description: Paths within Gradle User Home to cache.
|
description: Paths within Gradle User Home to cache.
|
||||||
required: false
|
required: false
|
||||||
|
|
|
@ -37,6 +37,10 @@ export function isCacheWriteOnly(): boolean {
|
||||||
return params.isCacheWriteOnly()
|
return params.isCacheWriteOnly()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isCacheOverwriteExisting(): boolean {
|
||||||
|
return params.isCacheOverwriteExisting()
|
||||||
|
}
|
||||||
|
|
||||||
export function isCacheDebuggingEnabled(): boolean {
|
export function isCacheDebuggingEnabled(): boolean {
|
||||||
return params.isCacheDebuggingEnabled()
|
return params.isCacheDebuggingEnabled()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import {isCacheCleanupEnabled, isCacheDisabled, isCacheReadOnly, isCacheWriteOnly} from './cache-utils'
|
import {
|
||||||
|
isCacheCleanupEnabled,
|
||||||
|
isCacheDisabled,
|
||||||
|
isCacheReadOnly,
|
||||||
|
isCacheWriteOnly,
|
||||||
|
isCacheOverwriteExisting
|
||||||
|
} from './cache-utils'
|
||||||
import {CacheListener} from './cache-reporting'
|
import {CacheListener} from './cache-reporting'
|
||||||
import {DaemonController} from './daemon-controller'
|
import {DaemonController} from './daemon-controller'
|
||||||
import {GradleStateCache} from './cache-base'
|
import {GradleStateCache} from './cache-base'
|
||||||
|
@ -26,12 +32,15 @@ export async function restore(gradleUserHome: string, cacheListener: CacheListen
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gradleStateCache.cacheOutputExists()) {
|
if (gradleStateCache.cacheOutputExists()) {
|
||||||
core.info('Gradle User Home already exists: will not restore from cache.')
|
if (!isCacheOverwriteExisting()) {
|
||||||
// Initialize pre-existing Gradle User Home.
|
core.info('Gradle User Home already exists: will not restore from cache.')
|
||||||
gradleStateCache.init()
|
// Initialize pre-existing Gradle User Home.
|
||||||
cacheListener.cacheDisabled = true
|
gradleStateCache.init()
|
||||||
cacheListener.cacheDisabledReason = 'disabled due to pre-existing Gradle User Home'
|
cacheListener.cacheDisabled = true
|
||||||
return
|
cacheListener.cacheDisabledReason = 'disabled due to pre-existing Gradle User Home'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
core.info('Gradle User Home already exists: will overwrite with cached contents.')
|
||||||
}
|
}
|
||||||
|
|
||||||
gradleStateCache.init()
|
gradleStateCache.init()
|
||||||
|
|
|
@ -13,6 +13,10 @@ export function isCacheWriteOnly(): boolean {
|
||||||
return getBooleanInput('cache-write-only')
|
return getBooleanInput('cache-write-only')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isCacheOverwriteExisting(): boolean {
|
||||||
|
return getBooleanInput('cache-overwrite-existing')
|
||||||
|
}
|
||||||
|
|
||||||
export function isCacheStrictMatch(): boolean {
|
export function isCacheStrictMatch(): boolean {
|
||||||
return getBooleanInput('gradle-home-cache-strict-match')
|
return getBooleanInput('gradle-home-cache-strict-match')
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue