Loading src/cache-base.ts +3 −9 Changes for src/cache-base.ts: 3 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -130,16 +130,13 @@ export class GradleStateCache { restoreKeys:[${cacheKey.restoreKeys}]` ) const cacheResult = await restoreCache(this.getCachePath(), cacheKey.key, cacheKey.restoreKeys) entryListener.markRequested(cacheKey.key, cacheKey.restoreKeys) const cacheResult = await restoreCache(this.getCachePath(), cacheKey.key, cacheKey.restoreKeys, entryListener) if (!cacheResult) { core.info(`${this.cacheDescription} cache not found. Will initialize empty.`) return } core.saveState(this.cacheResultStateKey, cacheResult.key) entryListener.markRestored(cacheResult.key, cacheResult.size) core.info(`Restored ${this.cacheDescription} from cache key: ${cacheResult.key}`) Loading Loading @@ -186,11 +183,8 @@ export class GradleStateCache { core.info(`Caching ${this.cacheDescription} with cache key: ${cacheKeyFromRestore}`) const cachePath = this.getCachePath() const savedEntry = await saveCache(cachePath, cacheKeyFromRestore) if (savedEntry) { listener.entry(this.cacheDescription).markSaved(savedEntry.key, savedEntry.size) } const entryListener = listener.entry(this.cacheDescription) await saveCache(cachePath, cacheKeyFromRestore, entryListener) return } Loading src/cache-extract-entries.ts +2 −8 Changes for src/cache-extract-entries.ts: 2 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -118,12 +118,9 @@ abstract class AbstractEntryExtractor { pattern: string, listener: CacheEntryListener ): Promise<ExtractedCacheEntry> { listener.markRequested(cacheKey) const restoredEntry = await restoreCache([pattern], cacheKey) const restoredEntry = await restoreCache([pattern], cacheKey, [], listener) if (restoredEntry) { core.info(`Restored ${artifactType} with key ${cacheKey} to ${pattern}`) listener.markRestored(restoredEntry.key, restoredEntry.size) return new ExtractedCacheEntry(artifactType, pattern, cacheKey) } else { core.info(`Did not restore ${artifactType} with key ${cacheKey} to ${pattern}`) Loading Loading @@ -217,10 +214,7 @@ abstract class AbstractEntryExtractor { cacheDebug(`No change to previously restored ${artifactType}. Not saving.`) } else { core.info(`Caching ${artifactType} with path '${pattern}' and cache key: ${cacheKey}`) const savedEntry = await saveCache([pattern], cacheKey) if (savedEntry !== undefined) { entryListener.markSaved(savedEntry.key, savedEntry.size) } await saveCache([pattern], cacheKey, entryListener) } for (const file of matchingFiles) { Loading src/cache-reporting.ts +13 −1 Changes for src/cache-reporting.ts: 13 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -76,6 +76,12 @@ export class CacheEntryListener { this.savedSize = size return this } markAlreadyExists(key: string): CacheEntryListener { this.savedKey = key this.savedSize = 0 return this } } export function logCachingReport(listener: CacheListener): void { Loading Loading @@ -112,12 +118,18 @@ function getSum( cacheEntries: CacheEntryListener[], predicate: (value: CacheEntryListener) => number | undefined ): string { if (cacheEntries.length === 0) { return '0' } return formatSize(cacheEntries.map(e => predicate(e) ?? 0).reduce((p, v) => p + v, 0)) } function formatSize(bytes: number | undefined): string { if (bytes === undefined || bytes === 0) { if (bytes === undefined) { return '' } if (bytes === 0) { return '0 (Entry already exists)' } return `${Math.round(bytes / (1024 * 1024))} MB (${bytes} B)` } src/cache-utils.ts +16 −5 Changes for src/cache-utils.ts: 16 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -4,6 +4,8 @@ import * as crypto from 'crypto' import * as path from 'path' import * as fs from 'fs' import {CacheEntryListener} from './cache-reporting' const JOB_CONTEXT_PARAMETER = 'workflow-job-context' const CACHE_DISABLED_PARAMETER = 'cache-disabled' const CACHE_READONLY_PARAMETER = 'cache-read-only' Loading Loading @@ -49,23 +51,32 @@ export function hashStrings(values: string[]): string { export async function restoreCache( cachePath: string[], cacheKey: string, cacheRestoreKeys: string[] = [] cacheRestoreKeys: string[], listener: CacheEntryListener ): Promise<cache.CacheEntry | undefined> { listener.markRequested(cacheKey, cacheRestoreKeys) try { return await cache.restoreCache(cachePath, cacheKey, cacheRestoreKeys) const restoredEntry = await cache.restoreCache(cachePath, cacheKey, cacheRestoreKeys) if (restoredEntry !== undefined) { listener.markRestored(restoredEntry.key, restoredEntry.size) } return restoredEntry } catch (error) { handleCacheFailure(error, `Failed to restore ${cacheKey}`) return undefined } } export async function saveCache(cachePath: string[], cacheKey: string): Promise<cache.CacheEntry | undefined> { export async function saveCache(cachePath: string[], cacheKey: string, listener: CacheEntryListener): Promise<void> { try { return await cache.saveCache(cachePath, cacheKey) const savedEntry = await cache.saveCache(cachePath, cacheKey) listener.markSaved(savedEntry.key, savedEntry.size) } catch (error) { if (error instanceof cache.ReserveCacheError) { listener.markAlreadyExists(cacheKey) } handleCacheFailure(error, `Failed to save cache entry ${cacheKey}`) } return undefined } export function cacheDebug(message: string): void { Loading Loading
src/cache-base.ts +3 −9 Changes for src/cache-base.ts: 3 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -130,16 +130,13 @@ export class GradleStateCache { restoreKeys:[${cacheKey.restoreKeys}]` ) const cacheResult = await restoreCache(this.getCachePath(), cacheKey.key, cacheKey.restoreKeys) entryListener.markRequested(cacheKey.key, cacheKey.restoreKeys) const cacheResult = await restoreCache(this.getCachePath(), cacheKey.key, cacheKey.restoreKeys, entryListener) if (!cacheResult) { core.info(`${this.cacheDescription} cache not found. Will initialize empty.`) return } core.saveState(this.cacheResultStateKey, cacheResult.key) entryListener.markRestored(cacheResult.key, cacheResult.size) core.info(`Restored ${this.cacheDescription} from cache key: ${cacheResult.key}`) Loading Loading @@ -186,11 +183,8 @@ export class GradleStateCache { core.info(`Caching ${this.cacheDescription} with cache key: ${cacheKeyFromRestore}`) const cachePath = this.getCachePath() const savedEntry = await saveCache(cachePath, cacheKeyFromRestore) if (savedEntry) { listener.entry(this.cacheDescription).markSaved(savedEntry.key, savedEntry.size) } const entryListener = listener.entry(this.cacheDescription) await saveCache(cachePath, cacheKeyFromRestore, entryListener) return } Loading
src/cache-extract-entries.ts +2 −8 Changes for src/cache-extract-entries.ts: 2 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -118,12 +118,9 @@ abstract class AbstractEntryExtractor { pattern: string, listener: CacheEntryListener ): Promise<ExtractedCacheEntry> { listener.markRequested(cacheKey) const restoredEntry = await restoreCache([pattern], cacheKey) const restoredEntry = await restoreCache([pattern], cacheKey, [], listener) if (restoredEntry) { core.info(`Restored ${artifactType} with key ${cacheKey} to ${pattern}`) listener.markRestored(restoredEntry.key, restoredEntry.size) return new ExtractedCacheEntry(artifactType, pattern, cacheKey) } else { core.info(`Did not restore ${artifactType} with key ${cacheKey} to ${pattern}`) Loading Loading @@ -217,10 +214,7 @@ abstract class AbstractEntryExtractor { cacheDebug(`No change to previously restored ${artifactType}. Not saving.`) } else { core.info(`Caching ${artifactType} with path '${pattern}' and cache key: ${cacheKey}`) const savedEntry = await saveCache([pattern], cacheKey) if (savedEntry !== undefined) { entryListener.markSaved(savedEntry.key, savedEntry.size) } await saveCache([pattern], cacheKey, entryListener) } for (const file of matchingFiles) { Loading
src/cache-reporting.ts +13 −1 Changes for src/cache-reporting.ts: 13 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -76,6 +76,12 @@ export class CacheEntryListener { this.savedSize = size return this } markAlreadyExists(key: string): CacheEntryListener { this.savedKey = key this.savedSize = 0 return this } } export function logCachingReport(listener: CacheListener): void { Loading Loading @@ -112,12 +118,18 @@ function getSum( cacheEntries: CacheEntryListener[], predicate: (value: CacheEntryListener) => number | undefined ): string { if (cacheEntries.length === 0) { return '0' } return formatSize(cacheEntries.map(e => predicate(e) ?? 0).reduce((p, v) => p + v, 0)) } function formatSize(bytes: number | undefined): string { if (bytes === undefined || bytes === 0) { if (bytes === undefined) { return '' } if (bytes === 0) { return '0 (Entry already exists)' } return `${Math.round(bytes / (1024 * 1024))} MB (${bytes} B)` }
src/cache-utils.ts +16 −5 Changes for src/cache-utils.ts: 16 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -4,6 +4,8 @@ import * as crypto from 'crypto' import * as path from 'path' import * as fs from 'fs' import {CacheEntryListener} from './cache-reporting' const JOB_CONTEXT_PARAMETER = 'workflow-job-context' const CACHE_DISABLED_PARAMETER = 'cache-disabled' const CACHE_READONLY_PARAMETER = 'cache-read-only' Loading Loading @@ -49,23 +51,32 @@ export function hashStrings(values: string[]): string { export async function restoreCache( cachePath: string[], cacheKey: string, cacheRestoreKeys: string[] = [] cacheRestoreKeys: string[], listener: CacheEntryListener ): Promise<cache.CacheEntry | undefined> { listener.markRequested(cacheKey, cacheRestoreKeys) try { return await cache.restoreCache(cachePath, cacheKey, cacheRestoreKeys) const restoredEntry = await cache.restoreCache(cachePath, cacheKey, cacheRestoreKeys) if (restoredEntry !== undefined) { listener.markRestored(restoredEntry.key, restoredEntry.size) } return restoredEntry } catch (error) { handleCacheFailure(error, `Failed to restore ${cacheKey}`) return undefined } } export async function saveCache(cachePath: string[], cacheKey: string): Promise<cache.CacheEntry | undefined> { export async function saveCache(cachePath: string[], cacheKey: string, listener: CacheEntryListener): Promise<void> { try { return await cache.saveCache(cachePath, cacheKey) const savedEntry = await cache.saveCache(cachePath, cacheKey) listener.markSaved(savedEntry.key, savedEntry.size) } catch (error) { if (error instanceof cache.ReserveCacheError) { listener.markAlreadyExists(cacheKey) } handleCacheFailure(error, `Failed to save cache entry ${cacheKey}`) } return undefined } export function cacheDebug(message: string): void { Loading