mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-11-23 01:22:50 +00:00
Allow cache-exclude-paths to be configured for action
All excluded paths are deleted prior to caching the Gradle User Home.
This commit is contained in:
parent
9c95294209
commit
1113cb87cb
2 changed files with 32 additions and 5 deletions
14
action.yml
14
action.yml
|
@ -7,19 +7,24 @@ inputs:
|
||||||
gradle-executable:
|
gradle-executable:
|
||||||
description: Path to the Gradle executable
|
description: Path to the Gradle executable
|
||||||
required: false
|
required: false
|
||||||
|
|
||||||
gradle-version:
|
gradle-version:
|
||||||
description: Gradle version to use
|
description: Gradle version to use
|
||||||
required: false
|
required: false
|
||||||
|
|
||||||
build-root-directory:
|
build-root-directory:
|
||||||
description: Path to the root directory of the build
|
description: Path to the root directory of the build
|
||||||
required: false
|
required: false
|
||||||
|
|
||||||
arguments:
|
arguments:
|
||||||
description: Gradle command line arguments (supports multi-line input)
|
description: Gradle command line arguments (supports multi-line input)
|
||||||
required: false
|
required: false
|
||||||
|
|
||||||
cache-disabled:
|
cache-disabled:
|
||||||
description: When 'true', all caching is disabled. No entries will be written to or read from the cache.
|
description: When 'true', all caching is disabled. No entries will be written to or read from the cache.
|
||||||
required: false
|
required: false
|
||||||
default: false
|
default: false
|
||||||
|
|
||||||
cache-read-only:
|
cache-read-only:
|
||||||
description: When 'true', existing entries will be read from the cache but no entries will be written
|
description: When 'true', existing entries will be read from the cache but no entries will be written
|
||||||
required: false
|
required: false
|
||||||
|
@ -35,11 +40,20 @@ inputs:
|
||||||
description: Used to uniquely identify the current job invocation. Defaults to the matrix values for this job; this should not be overridden by users (INTERNAL).
|
description: Used to uniquely identify the current job invocation. Defaults to the matrix values for this job; this should not be overridden by users (INTERNAL).
|
||||||
required: false
|
required: false
|
||||||
default: ${{ toJSON(matrix) }}
|
default: ${{ toJSON(matrix) }}
|
||||||
|
|
||||||
cache-paths:
|
cache-paths:
|
||||||
description: Paths in Gradle User Home to cache. (EXPERIMENTAL - may be changed/removed without notice)
|
description: Paths in Gradle User Home to cache. (EXPERIMENTAL - may be changed/removed without notice)
|
||||||
required: false
|
required: false
|
||||||
default: |
|
default: |
|
||||||
["caches", "notifications"]
|
["caches", "notifications"]
|
||||||
|
|
||||||
|
cache-exclude-paths:
|
||||||
|
description: Paths in Gradle User Home to exclude from cache. (EXPERIMENTAL - may be changed/removed without notice)
|
||||||
|
required: false
|
||||||
|
# eg ["caches/build-cache-1"] will prevent the local build cache from being saved/restored.
|
||||||
|
default: |
|
||||||
|
[]
|
||||||
|
|
||||||
cache-artifact-bundles:
|
cache-artifact-bundles:
|
||||||
description: Names and patterns of artifact bundles to cache separately. (EXPERIMENTAL - may be changed/removed without notice)
|
description: Names and patterns of artifact bundles to cache separately. (EXPERIMENTAL - may be changed/removed without notice)
|
||||||
required: false
|
required: false
|
||||||
|
|
|
@ -74,12 +74,27 @@ export class GradleUserHomeCache extends AbstractCache {
|
||||||
|
|
||||||
async beforeSave(): Promise<void> {
|
async beforeSave(): Promise<void> {
|
||||||
await this.reportGradleUserHomeSize('before saving common artifacts')
|
await this.reportGradleUserHomeSize('before saving common artifacts')
|
||||||
|
this.removeExcludedPaths()
|
||||||
await this.saveArtifactBundles()
|
await this.saveArtifactBundles()
|
||||||
await this.reportGradleUserHomeSize(
|
await this.reportGradleUserHomeSize(
|
||||||
'after saving common artifacts (./wrapper dir is not cached)'
|
"after saving common artifacts (only 'caches' and 'notifications' will be stored)"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private removeExcludedPaths(): void {
|
||||||
|
const rawPaths: string[] = JSON.parse(
|
||||||
|
core.getInput('cache-exclude-paths')
|
||||||
|
)
|
||||||
|
const resolvedPaths = rawPaths.map(x =>
|
||||||
|
path.resolve(this.gradleUserHome, x)
|
||||||
|
)
|
||||||
|
|
||||||
|
for (const p of resolvedPaths) {
|
||||||
|
this.debug(`Deleting excluded path: ${p}`)
|
||||||
|
tryDelete(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async saveArtifactBundles(): Promise<void> {
|
private async saveArtifactBundles(): Promise<void> {
|
||||||
const processes: Promise<void>[] = []
|
const processes: Promise<void>[] = []
|
||||||
for (const [bundle, pattern] of this.getArtifactBundles()) {
|
for (const [bundle, pattern] of this.getArtifactBundles()) {
|
||||||
|
@ -177,9 +192,7 @@ export class GradleUserHomeCache extends AbstractCache {
|
||||||
private resolveCachePath(rawPath: string): string {
|
private resolveCachePath(rawPath: string): string {
|
||||||
if (rawPath.startsWith('!')) {
|
if (rawPath.startsWith('!')) {
|
||||||
const resolved = this.resolveCachePath(rawPath.substring(1))
|
const resolved = this.resolveCachePath(rawPath.substring(1))
|
||||||
const negated = `!${resolved}`
|
return `!${resolved}`
|
||||||
this.debug(`Negate cache path: ${negated}`)
|
|
||||||
return negated
|
|
||||||
}
|
}
|
||||||
return path.resolve(this.gradleUserHome, rawPath)
|
return path.resolve(this.gradleUserHome, rawPath)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue