mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-11-22 09:02:50 +00:00
Merge pull request #854 from gradle/dd/existing-gradle-home
- Report the cache as disabled when Gradle User Home exists #434 - Allow cache restore over pre-existing Gradle User Home #480
This commit is contained in:
commit
9fb6114fb4
11 changed files with 132 additions and 20 deletions
22
.github/workflows/demo-job-summary.yml
vendored
22
.github/workflows/demo-job-summary.yml
vendored
|
@ -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
|
||||
|
|
|
@ -99,3 +99,40 @@ jobs:
|
|||
working-directory: .github/workflow-samples/groovy-dsl
|
||||
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
|
||||
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:
|
||||
description: Paths within Gradle User Home to cache.
|
||||
required: false
|
||||
|
|
20
dist/main/index.js
vendored
20
dist/main/index.js
vendored
|
@ -73467,6 +73467,7 @@ class CacheListener {
|
|||
this.cacheReadOnly = false;
|
||||
this.cacheWriteOnly = false;
|
||||
this.cacheDisabled = false;
|
||||
this.cacheDisabledReason = 'disabled';
|
||||
}
|
||||
get fullyRestored() {
|
||||
return this.cacheEntries.every(x => !x.wasRequestedButNotRestored());
|
||||
|
@ -73475,7 +73476,7 @@ class CacheListener {
|
|||
if (!cache.isFeatureAvailable())
|
||||
return 'not available';
|
||||
if (this.cacheDisabled)
|
||||
return 'disabled';
|
||||
return this.cacheDisabledReason;
|
||||
if (this.cacheWriteOnly)
|
||||
return 'write-only';
|
||||
if (this.cacheReadOnly)
|
||||
|
@ -73681,7 +73682,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.tryDelete = exports.handleCacheFailure = exports.cacheDebug = exports.saveCache = exports.restoreCache = exports.hashStrings = exports.hashFileNames = exports.getUniqueLabelForJobInstanceValues = exports.getUniqueLabelForJobInstance = exports.getCacheKeyForJob = exports.getCacheKeyPrefix = exports.generateCacheKey = exports.CacheKey = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
|
||||
exports.tryDelete = exports.handleCacheFailure = exports.cacheDebug = exports.saveCache = exports.restoreCache = exports.hashStrings = exports.hashFileNames = exports.getUniqueLabelForJobInstanceValues = exports.getUniqueLabelForJobInstance = exports.getCacheKeyForJob = exports.getCacheKeyPrefix = exports.generateCacheKey = exports.CacheKey = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheOverwriteExisting = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const cache = __importStar(__nccwpck_require__(7799));
|
||||
const github = __importStar(__nccwpck_require__(5438));
|
||||
|
@ -73713,6 +73714,10 @@ function isCacheWriteOnly() {
|
|||
return params.isCacheWriteOnly();
|
||||
}
|
||||
exports.isCacheWriteOnly = isCacheWriteOnly;
|
||||
function isCacheOverwriteExisting() {
|
||||
return params.isCacheOverwriteExisting();
|
||||
}
|
||||
exports.isCacheOverwriteExisting = isCacheOverwriteExisting;
|
||||
function isCacheDebuggingEnabled() {
|
||||
return params.isCacheDebuggingEnabled();
|
||||
}
|
||||
|
@ -73963,10 +73968,15 @@ function restore(gradleUserHome, cacheListener) {
|
|||
return;
|
||||
}
|
||||
if (gradleStateCache.cacheOutputExists()) {
|
||||
if (!(0, cache_utils_1.isCacheOverwriteExisting)()) {
|
||||
core.info('Gradle User Home already exists: will not restore from cache.');
|
||||
gradleStateCache.init();
|
||||
cacheListener.cacheDisabled = true;
|
||||
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();
|
||||
core.saveState(CACHE_RESTORED_VAR, true);
|
||||
if ((0, cache_utils_1.isCacheWriteOnly)()) {
|
||||
|
@ -74455,7 +74465,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.DependencyGraphOption = exports.getDependencyGraphOption = exports.isDependencyGraphEnabled = exports.isJobSummaryEnabled = exports.getGithubToken = exports.getJobMatrix = exports.getArguments = exports.getGradleExecutable = exports.getGradleVersion = exports.getBuildRootDirectory = exports.getCacheExcludes = exports.getCacheIncludes = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheStrictMatch = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
|
||||
exports.DependencyGraphOption = exports.getDependencyGraphOption = exports.isDependencyGraphEnabled = exports.isJobSummaryEnabled = exports.getGithubToken = exports.getJobMatrix = exports.getArguments = exports.getGradleExecutable = exports.getGradleVersion = exports.getBuildRootDirectory = exports.getCacheExcludes = exports.getCacheIncludes = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheStrictMatch = exports.isCacheOverwriteExisting = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const string_argv_1 = __nccwpck_require__(9663);
|
||||
function isCacheDisabled() {
|
||||
|
@ -74470,6 +74480,10 @@ function isCacheWriteOnly() {
|
|||
return getBooleanInput('cache-write-only');
|
||||
}
|
||||
exports.isCacheWriteOnly = isCacheWriteOnly;
|
||||
function isCacheOverwriteExisting() {
|
||||
return getBooleanInput('cache-overwrite-existing');
|
||||
}
|
||||
exports.isCacheOverwriteExisting = isCacheOverwriteExisting;
|
||||
function isCacheStrictMatch() {
|
||||
return getBooleanInput('gradle-home-cache-strict-match');
|
||||
}
|
||||
|
|
2
dist/main/index.js.map
vendored
2
dist/main/index.js.map
vendored
File diff suppressed because one or more lines are too long
20
dist/post/index.js
vendored
20
dist/post/index.js
vendored
|
@ -73467,6 +73467,7 @@ class CacheListener {
|
|||
this.cacheReadOnly = false;
|
||||
this.cacheWriteOnly = false;
|
||||
this.cacheDisabled = false;
|
||||
this.cacheDisabledReason = 'disabled';
|
||||
}
|
||||
get fullyRestored() {
|
||||
return this.cacheEntries.every(x => !x.wasRequestedButNotRestored());
|
||||
|
@ -73475,7 +73476,7 @@ class CacheListener {
|
|||
if (!cache.isFeatureAvailable())
|
||||
return 'not available';
|
||||
if (this.cacheDisabled)
|
||||
return 'disabled';
|
||||
return this.cacheDisabledReason;
|
||||
if (this.cacheWriteOnly)
|
||||
return 'write-only';
|
||||
if (this.cacheReadOnly)
|
||||
|
@ -73681,7 +73682,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.tryDelete = exports.handleCacheFailure = exports.cacheDebug = exports.saveCache = exports.restoreCache = exports.hashStrings = exports.hashFileNames = exports.getUniqueLabelForJobInstanceValues = exports.getUniqueLabelForJobInstance = exports.getCacheKeyForJob = exports.getCacheKeyPrefix = exports.generateCacheKey = exports.CacheKey = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
|
||||
exports.tryDelete = exports.handleCacheFailure = exports.cacheDebug = exports.saveCache = exports.restoreCache = exports.hashStrings = exports.hashFileNames = exports.getUniqueLabelForJobInstanceValues = exports.getUniqueLabelForJobInstance = exports.getCacheKeyForJob = exports.getCacheKeyPrefix = exports.generateCacheKey = exports.CacheKey = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheOverwriteExisting = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const cache = __importStar(__nccwpck_require__(7799));
|
||||
const github = __importStar(__nccwpck_require__(5438));
|
||||
|
@ -73713,6 +73714,10 @@ function isCacheWriteOnly() {
|
|||
return params.isCacheWriteOnly();
|
||||
}
|
||||
exports.isCacheWriteOnly = isCacheWriteOnly;
|
||||
function isCacheOverwriteExisting() {
|
||||
return params.isCacheOverwriteExisting();
|
||||
}
|
||||
exports.isCacheOverwriteExisting = isCacheOverwriteExisting;
|
||||
function isCacheDebuggingEnabled() {
|
||||
return params.isCacheDebuggingEnabled();
|
||||
}
|
||||
|
@ -73963,10 +73968,15 @@ function restore(gradleUserHome, cacheListener) {
|
|||
return;
|
||||
}
|
||||
if (gradleStateCache.cacheOutputExists()) {
|
||||
if (!(0, cache_utils_1.isCacheOverwriteExisting)()) {
|
||||
core.info('Gradle User Home already exists: will not restore from cache.');
|
||||
gradleStateCache.init();
|
||||
cacheListener.cacheDisabled = true;
|
||||
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();
|
||||
core.saveState(CACHE_RESTORED_VAR, true);
|
||||
if ((0, cache_utils_1.isCacheWriteOnly)()) {
|
||||
|
@ -74323,7 +74333,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.DependencyGraphOption = exports.getDependencyGraphOption = exports.isDependencyGraphEnabled = exports.isJobSummaryEnabled = exports.getGithubToken = exports.getJobMatrix = exports.getArguments = exports.getGradleExecutable = exports.getGradleVersion = exports.getBuildRootDirectory = exports.getCacheExcludes = exports.getCacheIncludes = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheStrictMatch = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
|
||||
exports.DependencyGraphOption = exports.getDependencyGraphOption = exports.isDependencyGraphEnabled = exports.isJobSummaryEnabled = exports.getGithubToken = exports.getJobMatrix = exports.getArguments = exports.getGradleExecutable = exports.getGradleVersion = exports.getBuildRootDirectory = exports.getCacheExcludes = exports.getCacheIncludes = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheStrictMatch = exports.isCacheOverwriteExisting = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const string_argv_1 = __nccwpck_require__(9663);
|
||||
function isCacheDisabled() {
|
||||
|
@ -74338,6 +74348,10 @@ function isCacheWriteOnly() {
|
|||
return getBooleanInput('cache-write-only');
|
||||
}
|
||||
exports.isCacheWriteOnly = isCacheWriteOnly;
|
||||
function isCacheOverwriteExisting() {
|
||||
return getBooleanInput('cache-overwrite-existing');
|
||||
}
|
||||
exports.isCacheOverwriteExisting = isCacheOverwriteExisting;
|
||||
function isCacheStrictMatch() {
|
||||
return getBooleanInput('gradle-home-cache-strict-match');
|
||||
}
|
||||
|
|
2
dist/post/index.js.map
vendored
2
dist/post/index.js.map
vendored
File diff suppressed because one or more lines are too long
|
@ -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'
|
||||
|
|
|
@ -37,6 +37,10 @@ export function isCacheWriteOnly(): boolean {
|
|||
return params.isCacheWriteOnly()
|
||||
}
|
||||
|
||||
export function isCacheOverwriteExisting(): boolean {
|
||||
return params.isCacheOverwriteExisting()
|
||||
}
|
||||
|
||||
export function isCacheDebuggingEnabled(): boolean {
|
||||
return params.isCacheDebuggingEnabled()
|
||||
}
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
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 {DaemonController} from './daemon-controller'
|
||||
import {GradleStateCache} from './cache-base'
|
||||
|
@ -26,11 +32,16 @@ export async function restore(gradleUserHome: string, cacheListener: CacheListen
|
|||
}
|
||||
|
||||
if (gradleStateCache.cacheOutputExists()) {
|
||||
if (!isCacheOverwriteExisting()) {
|
||||
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
|
||||
}
|
||||
core.info('Gradle User Home already exists: will overwrite with cached contents.')
|
||||
}
|
||||
|
||||
gradleStateCache.init()
|
||||
// Mark the state as restored so that post-action will perform save.
|
||||
|
|
|
@ -13,6 +13,10 @@ export function isCacheWriteOnly(): boolean {
|
|||
return getBooleanInput('cache-write-only')
|
||||
}
|
||||
|
||||
export function isCacheOverwriteExisting(): boolean {
|
||||
return getBooleanInput('cache-overwrite-existing')
|
||||
}
|
||||
|
||||
export function isCacheStrictMatch(): boolean {
|
||||
return getBooleanInput('gradle-home-cache-strict-match')
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue