Loading __tests__/cache-utils.test.ts +6 Changes for __tests__/cache-utils.test.ts: 6 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -11,5 +11,11 @@ describe('cacheUtils-utils', () => { const hash = cacheUtils.hashStrings(['foo', 'bar', 'baz']) expect(hash).toBe('6df23dc03f9b54cc38a0fc1483df6e21') }) it('normalized filenames', async () => { const fileNames = ['/foo/bar/baz.zip', '../boo.html'] const posixHash = cacheUtils.hashFileNames(fileNames) const windowsHash = cacheUtils.hashFileNames(fileNames) expect(posixHash).toBe(windowsHash) }) }) }) src/cache-gradle-user-home.ts +8 −6 Changes for src/cache-gradle-user-home.ts: 8 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ import * as core from '@actions/core' import * as glob from '@actions/glob' import * as exec from '@actions/exec' import {AbstractCache, hashStrings} from './cache-utils' import {AbstractCache, hashFileNames} from './cache-utils' // Which paths under Gradle User Home should be cached const CACHE_PATH = ['caches', 'notifications'] Loading Loading @@ -149,10 +149,7 @@ export class GradleUserHomeCache extends AbstractCache { const previouslyRestoredKey = fs.existsSync(cacheMetaFile) ? fs.readFileSync(cacheMetaFile, 'utf-8').trim() : '' const cacheKey = this.createCacheKey( bundle, hashStrings(commonArtifactFiles) ) const cacheKey = this.createCacheKey(bundle, commonArtifactFiles) if (previouslyRestoredKey === cacheKey) { this.debug( Loading @@ -171,8 +168,13 @@ export class GradleUserHomeCache extends AbstractCache { } } protected createCacheKey(bundle: string, key: string): string { protected createCacheKey(bundle: string, files: string[]): string { const cacheKeyPrefix = process.env['CACHE_KEY_PREFIX'] || '' const relativeFiles = files.map(x => path.relative(this.gradleUserHome, x) ) const key = hashFileNames(relativeFiles) return `${cacheKeyPrefix}${bundle}-${key}` } Loading src/cache-utils.ts +7 Changes for src/cache-utils.ts: 7 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ import * as core from '@actions/core' import * as cache from '@actions/cache' import * as github from '@actions/github' import * as crypto from 'crypto' import * as path from 'path' export function isCacheDisabled(): boolean { return core.getBooleanInput('cache-disabled') Loading Loading @@ -53,6 +54,12 @@ export function hashStrings(values: string[]): string { return hash.digest('hex') } export function hashFileNames(fileNames: string[]): string { return hashStrings( fileNames.map(x => x.replace(new RegExp(`\\${path.sep}`, 'g'), '/')) ) } class CacheKey { key: string restoreKeys: string[] Loading Loading
__tests__/cache-utils.test.ts +6 Changes for __tests__/cache-utils.test.ts: 6 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -11,5 +11,11 @@ describe('cacheUtils-utils', () => { const hash = cacheUtils.hashStrings(['foo', 'bar', 'baz']) expect(hash).toBe('6df23dc03f9b54cc38a0fc1483df6e21') }) it('normalized filenames', async () => { const fileNames = ['/foo/bar/baz.zip', '../boo.html'] const posixHash = cacheUtils.hashFileNames(fileNames) const windowsHash = cacheUtils.hashFileNames(fileNames) expect(posixHash).toBe(windowsHash) }) }) })
src/cache-gradle-user-home.ts +8 −6 Changes for src/cache-gradle-user-home.ts: 8 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ import * as core from '@actions/core' import * as glob from '@actions/glob' import * as exec from '@actions/exec' import {AbstractCache, hashStrings} from './cache-utils' import {AbstractCache, hashFileNames} from './cache-utils' // Which paths under Gradle User Home should be cached const CACHE_PATH = ['caches', 'notifications'] Loading Loading @@ -149,10 +149,7 @@ export class GradleUserHomeCache extends AbstractCache { const previouslyRestoredKey = fs.existsSync(cacheMetaFile) ? fs.readFileSync(cacheMetaFile, 'utf-8').trim() : '' const cacheKey = this.createCacheKey( bundle, hashStrings(commonArtifactFiles) ) const cacheKey = this.createCacheKey(bundle, commonArtifactFiles) if (previouslyRestoredKey === cacheKey) { this.debug( Loading @@ -171,8 +168,13 @@ export class GradleUserHomeCache extends AbstractCache { } } protected createCacheKey(bundle: string, key: string): string { protected createCacheKey(bundle: string, files: string[]): string { const cacheKeyPrefix = process.env['CACHE_KEY_PREFIX'] || '' const relativeFiles = files.map(x => path.relative(this.gradleUserHome, x) ) const key = hashFileNames(relativeFiles) return `${cacheKeyPrefix}${bundle}-${key}` } Loading
src/cache-utils.ts +7 Changes for src/cache-utils.ts: 7 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ import * as core from '@actions/core' import * as cache from '@actions/cache' import * as github from '@actions/github' import * as crypto from 'crypto' import * as path from 'path' export function isCacheDisabled(): boolean { return core.getBooleanInput('cache-disabled') Loading Loading @@ -53,6 +54,12 @@ export function hashStrings(values: string[]): string { return hash.digest('hex') } export function hashFileNames(fileNames: string[]): string { return hashStrings( fileNames.map(x => x.replace(new RegExp(`\\${path.sep}`, 'g'), '/')) ) } class CacheKey { key: string restoreKeys: string[] Loading