Support wildcards in cache-excludes

This commit is contained in:
daz 2023-12-20 10:05:25 -07:00
parent f053e6b7e7
commit 9d6738618d
No known key found for this signature in database
2 changed files with 18 additions and 6 deletions

View file

@ -38,7 +38,8 @@ jobs:
enterprise enterprise
# Exclude build-cache from main cache entry # Exclude build-cache from main cache entry
gradle-home-cache-excludes: | gradle-home-cache-excludes: |
caches/build-cache-1 caches/build-cache-*
caches/*/executionHistory/**
- name: Build using Gradle wrapper - name: Build using Gradle wrapper
working-directory: .github/workflow-samples/groovy-dsl working-directory: .github/workflow-samples/groovy-dsl
run: ./gradlew test run: ./gradlew test
@ -63,7 +64,8 @@ jobs:
caches caches
enterprise enterprise
gradle-home-cache-excludes: | gradle-home-cache-excludes: |
caches/build-cache-1 caches/build-cache-*
caches/*/executionHistory/**
cache-read-only: true cache-read-only: true
- name: Execute Gradle build with --offline - name: Execute Gradle build with --offline
working-directory: .github/workflow-samples/groovy-dsl working-directory: .github/workflow-samples/groovy-dsl

View file

@ -1,5 +1,7 @@
import * as core from '@actions/core' import * as core from '@actions/core'
import * as exec from '@actions/exec' import * as exec from '@actions/exec'
import * as glob from '@actions/glob'
import path from 'path' import path from 'path'
import fs from 'fs' import fs from 'fs'
import * as params from './input-params' import * as params from './input-params'
@ -127,7 +129,7 @@ export class GradleStateCache {
*/ */
async beforeSave(listener: CacheListener): Promise<void> { async beforeSave(listener: CacheListener): Promise<void> {
await this.debugReportGradleUserHomeSize('before saving common artifacts') await this.debugReportGradleUserHomeSize('before saving common artifacts')
this.deleteExcludedPaths() await this.deleteExcludedPaths()
await Promise.all([ await Promise.all([
new GradleHomeEntryExtractor(this.gradleUserHome).extract(listener) new GradleHomeEntryExtractor(this.gradleUserHome).extract(listener)
// new ConfigurationCacheEntryExtractor(this.gradleUserHome).extract(listener) // new ConfigurationCacheEntryExtractor(this.gradleUserHome).extract(listener)
@ -140,13 +142,21 @@ export class GradleStateCache {
/** /**
* Delete any file paths that are excluded by the `gradle-home-cache-excludes` parameter. * Delete any file paths that are excluded by the `gradle-home-cache-excludes` parameter.
*/ */
private deleteExcludedPaths(): void { private async deleteExcludedPaths(): Promise<void> {
const rawPaths: string[] = params.getCacheExcludes() const rawPaths: string[] = params.getCacheExcludes()
// rawPaths.push('caches/*/cc-keystore')
const resolvedPaths = rawPaths.map(x => path.resolve(this.gradleUserHome, x)) const resolvedPaths = rawPaths.map(x => path.resolve(this.gradleUserHome, x))
for (const p of resolvedPaths) { for (const p of resolvedPaths) {
cacheDebug(`Deleting excluded path: ${p}`) cacheDebug(`Removing excluded path: ${p}`)
tryDelete(p) const globber = await glob.create(p, {
implicitDescendants: false
})
for (const toDelete of await globber.glob()) {
cacheDebug(`Removing excluded file: ${toDelete}`)
await tryDelete(toDelete)
}
} }
} }