Commit 053762c1 authored by Paul Merlin's avatar Paul Merlin
Browse files

Add input to make the dependencies caching strict

parent 95e20daa
Loading
Loading
Loading
Loading
+3
Changes for action.yml: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -23,6 +23,9 @@ inputs:
  dependencies-cache-key:
    description: Globs of files to hash in the build root directory, separated by new lines, use best-effort if unset
    required: false
  dependencies-cache-exact:
    description: Wether to restore only if exact match, default to 'false'
    required: false

outputs:
  build-scan-url:
+1 −1

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1

File changed.

Preview size limit exceeded, changes collapsed.

+7 −3
Changes for src/cache-dependencies.ts: 7 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ export async function restoreCachedDependencies(
    const cachePath = path.resolve(os.homedir(), '.gradle/caches/modules-2')
    core.saveState(DEPENDENCIES_CACHE_PATH, cachePath)

    const inputCacheExact = github.inputBoolean('dependencies-cache-exact')

    const inputCacheKeyGlobs = github.inputArrayOrNull('dependencies-cache-key')
    const cacheKeyGlobs = inputCacheKeyGlobs
        ? inputCacheKeyGlobs
@@ -33,9 +35,11 @@ export async function restoreCachedDependencies(
    const cacheKey = `${cacheKeyPrefix}${hash}`
    core.saveState(DEPENDENCIES_CACHE_KEY, cacheKey)

    const cacheResult = await cache.restoreCache([cachePath], cacheKey, [
        cacheKeyPrefix
    ])
    const cacheResult = await cache.restoreCache(
        [cachePath],
        cacheKey,
        inputCacheExact ? [] : [cacheKeyPrefix]
    )
    core.saveState(DEPENDENCIES_CACHE_RESULT, cacheResult)
}

+6
Changes for src/github-utils.ts: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -16,3 +16,9 @@ export function inputArrayOrNull(name: string): string[] | null {
        .map(s => s.trim())
        .filter(s => s !== '')
}

export function inputBoolean(name: string, defaultValue = false): boolean {
    const string = inputOrNull(name)
    if (!string) return defaultValue
    return string === 'true'
}