Unverified Commit e0c2736e authored by Daz DeBoer's avatar Daz DeBoer Committed by GitHub
Browse files

Include Gradle invocation arguments in cache keys (#69)

This permits a new cache entry to be persisted when a subsequent Gradle invocation does more work that an earlier invocation.

Fixes #68
parent a63892c2
Loading
Loading
Loading
Loading
+1 −1

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1

File changed.

Preview size limit exceeded, changes collapsed.

+10 −6
Changes for src/cache-configuration.ts: 10 added lines, 6 removed lines.
Original line number Diff line number Diff line
import path from 'path'
import fs from 'fs'
import * as path from 'path'
import * as fs from 'fs'

import * as core from '@actions/core'
import * as cache from '@actions/cache'
@@ -32,17 +32,21 @@ export async function restoreCachedConfiguration(
    core.saveState(CONFIGURATION_CACHE_PATH, cachePath)

    const inputCacheExact = core.getBooleanInput('configuration-cache-exact')
    const cacheKeyGlobs = inputCacheKeyGlobs('configuration-cache-key')
    const cacheKeyPrefix = 'configuration|'

    const args = core.getInput('arguments')
    const cacheKeyWithArgs = `${cacheKeyPrefix}${args}|`

    const cacheKeyGlobs = inputCacheKeyGlobs('configuration-cache-key')
    const hash = await crypto.hashFiles(rootDir, cacheKeyGlobs)
    const cacheKeyPrefix = 'configuration-'
    const cacheKey = `${cacheKeyPrefix}${hash}`
    const cacheKey = `${cacheKeyWithArgs}${hash}`

    core.saveState(CONFIGURATION_CACHE_KEY, cacheKey)

    const cacheResult = await cache.restoreCache(
        [cachePath],
        cacheKey,
        inputCacheExact ? [] : [cacheKeyPrefix]
        inputCacheExact ? [] : [cacheKeyWithArgs, cacheKeyPrefix]
    )

    if (!cacheResult) {
+8 −4
Changes for src/cache-dependencies.ts: 8 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -21,17 +21,21 @@ export async function restoreCachedDependencies(
    core.saveState(DEPENDENCIES_CACHE_PATH, cachePath)

    const inputCacheExact = core.getBooleanInput('dependencies-cache-exact')
    const cacheKeyGlobs = inputCacheKeyGlobs('dependencies-cache-key')
    const cacheKeyPrefix = 'dependencies|'

    const args = core.getInput('arguments')
    const cacheKeyWithArgs = `${cacheKeyPrefix}${args}|`

    const cacheKeyGlobs = inputCacheKeyGlobs('dependencies-cache-key')
    const hash = await crypto.hashFiles(rootDir, cacheKeyGlobs)
    const cacheKeyPrefix = 'dependencies-'
    const cacheKey = `${cacheKeyPrefix}${hash}`
    const cacheKey = `${cacheKeyWithArgs}${hash}`

    core.saveState(DEPENDENCIES_CACHE_KEY, cacheKey)

    const cacheResult = await cache.restoreCache(
        [cachePath],
        cacheKey,
        inputCacheExact ? [] : [cacheKeyPrefix]
        inputCacheExact ? [] : [cacheKeyWithArgs, cacheKeyPrefix]
    )

    if (!cacheResult) {