Skip to content

Commit

Permalink
Usability improvements:
Browse files Browse the repository at this point in the history
- Include bundle name in cache key
- Emit a few more messages at 'info'
  • Loading branch information
bigdaz committed Sep 15, 2021
1 parent 6084a4e commit bebb162
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 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/main/index.js.map

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions src/cache-gradle-user-home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class GradleUserHomeCache extends AbstractCache {
const cacheKey = fs.readFileSync(cacheMetaFile, 'utf-8').trim()
const restoreKey = await this.restoreCache([pattern], cacheKey)
if (restoreKey) {
this.debug(
core.info(
`Restored ${bundle} with key ${cacheKey} to ${pattern}`
)
} else {
Expand Down Expand Up @@ -149,14 +149,17 @@ export class GradleUserHomeCache extends AbstractCache {
const previouslyRestoredKey = fs.existsSync(cacheMetaFile)
? fs.readFileSync(cacheMetaFile, 'utf-8').trim()
: ''
const cacheKey = this.createCacheKey(hashStrings(commonArtifactFiles))
const cacheKey = this.createCacheKey(
bundle,
hashStrings(commonArtifactFiles)
)

if (previouslyRestoredKey === cacheKey) {
this.debug(
`No change to previously restored ${bundle}. Not caching.`
)
} else {
this.debug(`Caching ${bundle} with cache key: ${cacheKey}`)
core.info(`Caching ${bundle} with cache key: ${cacheKey}`)
await this.saveCache([pattern], cacheKey)

this.debug(`Writing cache metafile: ${cacheMetaFile}`)
Expand All @@ -168,9 +171,9 @@ export class GradleUserHomeCache extends AbstractCache {
}
}

protected createCacheKey(key: string): string {
protected createCacheKey(bundle: string, key: string): string {
const cacheKeyPrefix = process.env['CACHE_KEY_PREFIX'] || ''
return `${cacheKeyPrefix}${key}`
return `${cacheKeyPrefix}${bundle}-${key}`
}

protected getGradleUserHome(): string {
Expand Down
2 changes: 1 addition & 1 deletion src/cache-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export abstract class AbstractCache {
core.saveState(this.cacheResultStateKey, cacheResult)

core.info(
`${this.cacheDescription} restored from cache key: ${cacheResult}`
`Restored ${this.cacheDescription} from cache key: ${cacheResult}`
)

await this.afterRestore()
Expand Down

0 comments on commit bebb162

Please sign in to comment.