Skip to content

Commit e0c2736

Browse files
authored
Include Gradle invocation arguments in cache keys (gradle#69)
This permits a new cache entry to be persisted when a subsequent Gradle invocation does more work that an earlier invocation. Fixes gradle#68
1 parent a63892c commit e0c2736

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

dist/main/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/post/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cache-configuration.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import path from 'path'
2-
import fs from 'fs'
1+
import * as path from 'path'
2+
import * as fs from 'fs'
33

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

3434
const inputCacheExact = core.getBooleanInput('configuration-cache-exact')
35-
const cacheKeyGlobs = inputCacheKeyGlobs('configuration-cache-key')
35+
const cacheKeyPrefix = 'configuration|'
36+
37+
const args = core.getInput('arguments')
38+
const cacheKeyWithArgs = `${cacheKeyPrefix}${args}|`
3639

40+
const cacheKeyGlobs = inputCacheKeyGlobs('configuration-cache-key')
3741
const hash = await crypto.hashFiles(rootDir, cacheKeyGlobs)
38-
const cacheKeyPrefix = 'configuration-'
39-
const cacheKey = `${cacheKeyPrefix}${hash}`
42+
const cacheKey = `${cacheKeyWithArgs}${hash}`
43+
4044
core.saveState(CONFIGURATION_CACHE_KEY, cacheKey)
4145

4246
const cacheResult = await cache.restoreCache(
4347
[cachePath],
4448
cacheKey,
45-
inputCacheExact ? [] : [cacheKeyPrefix]
49+
inputCacheExact ? [] : [cacheKeyWithArgs, cacheKeyPrefix]
4650
)
4751

4852
if (!cacheResult) {

src/cache-dependencies.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,21 @@ export async function restoreCachedDependencies(
2121
core.saveState(DEPENDENCIES_CACHE_PATH, cachePath)
2222

2323
const inputCacheExact = core.getBooleanInput('dependencies-cache-exact')
24-
const cacheKeyGlobs = inputCacheKeyGlobs('dependencies-cache-key')
24+
const cacheKeyPrefix = 'dependencies|'
25+
26+
const args = core.getInput('arguments')
27+
const cacheKeyWithArgs = `${cacheKeyPrefix}${args}|`
2528

29+
const cacheKeyGlobs = inputCacheKeyGlobs('dependencies-cache-key')
2630
const hash = await crypto.hashFiles(rootDir, cacheKeyGlobs)
27-
const cacheKeyPrefix = 'dependencies-'
28-
const cacheKey = `${cacheKeyPrefix}${hash}`
31+
const cacheKey = `${cacheKeyWithArgs}${hash}`
32+
2933
core.saveState(DEPENDENCIES_CACHE_KEY, cacheKey)
3034

3135
const cacheResult = await cache.restoreCache(
3236
[cachePath],
3337
cacheKey,
34-
inputCacheExact ? [] : [cacheKeyPrefix]
38+
inputCacheExact ? [] : [cacheKeyWithArgs, cacheKeyPrefix]
3539
)
3640

3741
if (!cacheResult) {

0 commit comments

Comments
 (0)