Skip to content

Commit

Permalink
Include Gradle invocation arguments in cache keys (#69)
Browse files Browse the repository at this point in the history
This permits a new cache entry to be persisted when a subsequent Gradle invocation does more work that an earlier invocation.

Fixes #68
  • Loading branch information
bigdaz committed Aug 22, 2021
1 parent a63892c commit e0c2736
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dist/main/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/post/index.js

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions src/cache-configuration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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'
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 8 additions & 4 deletions src/cache-dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit e0c2736

Please sign in to comment.