1
0
Fork 0

Address review comments

pull/1291/head
Sampark Sharma 2023-01-03 08:31:27 +00:00 committed by GitHub
parent da162e46a8
commit 0746965b72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 46 deletions

View File

@ -39,7 +39,7 @@ test('getCacheVersion with gzip compression does not change vesion', async () =>
) )
}) })
test('getCacheVersion with crossOsEnabled as false returns version on windows', async () => { test('getCacheVersion with enableCrossOsArchive as false returns version on windows', async () => {
if (process.platform === 'win32') { if (process.platform === 'win32') {
const paths = ['node_modules'] const paths = ['node_modules']
const result = getCacheVersion(paths) const result = getCacheVersion(paths)

View File

@ -143,7 +143,7 @@ test('restore with gzip compressed cache found', async () => {
expect(cacheKey).toBe(key) expect(cacheKey).toBe(key)
expect(getCacheMock).toHaveBeenCalledWith([key], paths, { expect(getCacheMock).toHaveBeenCalledWith([key], paths, {
compressionMethod: compression, compressionMethod: compression,
crossOsEnabled: false enableCrossOsArchive: false
}) })
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1) expect(createTempDirectoryMock).toHaveBeenCalledTimes(1)
expect(downloadCacheMock).toHaveBeenCalledWith( expect(downloadCacheMock).toHaveBeenCalledWith(
@ -212,7 +212,7 @@ test('restore with zstd as default but gzip compressed cache found on windows',
expect(cacheKey).toBe(key) expect(cacheKey).toBe(key)
expect(getCacheMock).toHaveBeenNthCalledWith(1, [key], paths, { expect(getCacheMock).toHaveBeenNthCalledWith(1, [key], paths, {
compressionMethod: compression, compressionMethod: compression,
crossOsEnabled: false enableCrossOsArchive: false
}) })
expect(getCacheMock).toHaveBeenNthCalledWith(2, [key], paths, { expect(getCacheMock).toHaveBeenNthCalledWith(2, [key], paths, {
compressionMethod: CompressionMethod.Gzip compressionMethod: CompressionMethod.Gzip
@ -279,7 +279,7 @@ test('restore with zstd compressed cache found', async () => {
expect(cacheKey).toBe(key) expect(cacheKey).toBe(key)
expect(getCacheMock).toHaveBeenCalledWith([key], paths, { expect(getCacheMock).toHaveBeenCalledWith([key], paths, {
compressionMethod: compression, compressionMethod: compression,
crossOsEnabled: false enableCrossOsArchive: false
}) })
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1) expect(createTempDirectoryMock).toHaveBeenCalledTimes(1)
expect(downloadCacheMock).toHaveBeenCalledWith( expect(downloadCacheMock).toHaveBeenCalledWith(
@ -337,7 +337,7 @@ test('restore with cache found for restore key', async () => {
expect(cacheKey).toBe(restoreKey) expect(cacheKey).toBe(restoreKey)
expect(getCacheMock).toHaveBeenCalledWith([key, restoreKey], paths, { expect(getCacheMock).toHaveBeenCalledWith([key, restoreKey], paths, {
compressionMethod: compression, compressionMethod: compression,
crossOsEnabled: false enableCrossOsArchive: false
}) })
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1) expect(createTempDirectoryMock).toHaveBeenCalledTimes(1)
expect(downloadCacheMock).toHaveBeenCalledWith( expect(downloadCacheMock).toHaveBeenCalledWith(

View File

@ -211,7 +211,7 @@ test('save with reserve cache failure should fail', async () => {
expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, paths, { expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, paths, {
cacheSize: undefined, cacheSize: undefined,
compressionMethod: compression, compressionMethod: compression,
crossOsEnabled: false enableCrossOsArchive: false
}) })
expect(createTarMock).toHaveBeenCalledTimes(1) expect(createTarMock).toHaveBeenCalledTimes(1)
expect(saveCacheMock).toHaveBeenCalledTimes(0) expect(saveCacheMock).toHaveBeenCalledTimes(0)
@ -257,7 +257,7 @@ test('save with server error should fail', async () => {
expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, [filePath], { expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, [filePath], {
cacheSize: undefined, cacheSize: undefined,
compressionMethod: compression, compressionMethod: compression,
crossOsEnabled: false enableCrossOsArchive: false
}) })
const archiveFolder = '/foo/bar' const archiveFolder = '/foo/bar'
const archiveFile = path.join(archiveFolder, CacheFilename.Zstd) const archiveFile = path.join(archiveFolder, CacheFilename.Zstd)
@ -302,7 +302,7 @@ test('save with valid inputs uploads a cache', async () => {
expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, [filePath], { expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, [filePath], {
cacheSize: undefined, cacheSize: undefined,
compressionMethod: compression, compressionMethod: compression,
crossOsEnabled: false enableCrossOsArchive: false
}) })
const archiveFolder = '/foo/bar' const archiveFolder = '/foo/bar'
const archiveFile = path.join(archiveFolder, CacheFilename.Zstd) const archiveFile = path.join(archiveFolder, CacheFilename.Zstd)

View File

@ -1,6 +1,6 @@
{ {
"name": "@actions/cache", "name": "@actions/cache",
"version": "3.1.0", "version": "3.1.2",
"preview": true, "preview": true,
"description": "Actions cache lib", "description": "Actions cache lib",
"keywords": [ "keywords": [

View File

@ -62,7 +62,7 @@ export function isFeatureAvailable(): boolean {
* @param primaryKey an explicit key for restoring the cache * @param primaryKey an explicit key for restoring the cache
* @param restoreKeys an optional ordered list of keys to use for restoring the cache if no cache hit occurred for key * @param restoreKeys an optional ordered list of keys to use for restoring the cache if no cache hit occurred for key
* @param downloadOptions cache download options * @param downloadOptions cache download options
* @param crossOsEnabled an optional boolean enabled to restore on windows any cache created on any platform * @param enableCrossOsArchive an optional boolean enabled to restore on windows any cache created on any platform
* @returns string returns the key for the cache hit, otherwise returns undefined * @returns string returns the key for the cache hit, otherwise returns undefined
*/ */
export async function restoreCache( export async function restoreCache(
@ -70,7 +70,7 @@ export async function restoreCache(
primaryKey: string, primaryKey: string,
restoreKeys?: string[], restoreKeys?: string[],
options?: DownloadOptions, options?: DownloadOptions,
crossOsEnabled = false enableCrossOsArchive = false
): Promise<string | undefined> { ): Promise<string | undefined> {
checkPaths(paths) checkPaths(paths)
@ -96,29 +96,11 @@ export async function restoreCache(
// path are needed to compute version // path are needed to compute version
cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, { cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, {
compressionMethod, compressionMethod,
crossOsEnabled enableCrossOsArchive
}) })
if (!cacheEntry?.archiveLocation) { if (!cacheEntry?.archiveLocation) {
// This is to support the old cache entry created by gzip on windows. // Cache not found
if ( return undefined
process.platform === 'win32' &&
compressionMethod !== CompressionMethod.Gzip
) {
compressionMethod = CompressionMethod.Gzip
cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, {
compressionMethod
})
if (!cacheEntry?.archiveLocation) {
return undefined
}
core.info(
"Couldn't find cache entry with zstd compression, falling back to gzip compression."
)
} else {
// Cache not found
return undefined
}
} }
archivePath = path.join( archivePath = path.join(
@ -174,7 +156,7 @@ export async function restoreCache(
* *
* @param paths a list of file paths to be cached * @param paths a list of file paths to be cached
* @param key an explicit key for restoring the cache * @param key an explicit key for restoring the cache
* @param crossOsEnabled an optional boolean enabled to save cache on windows which could be restored on any platform * @param enableCrossOsArchive an optional boolean enabled to save cache on windows which could be restored on any platform
* @param options cache upload options * @param options cache upload options
* @returns number returns cacheId if the cache was saved successfully and throws an error if save fails * @returns number returns cacheId if the cache was saved successfully and throws an error if save fails
*/ */
@ -182,7 +164,7 @@ export async function saveCache(
paths: string[], paths: string[],
key: string, key: string,
options?: UploadOptions, options?: UploadOptions,
crossOsEnabled = false enableCrossOsArchive = false
): Promise<number> { ): Promise<number> {
checkPaths(paths) checkPaths(paths)
checkKey(key) checkKey(key)
@ -232,7 +214,7 @@ export async function saveCache(
paths, paths,
{ {
compressionMethod, compressionMethod,
crossOsEnabled, enableCrossOsArchive,
cacheSize: archiveFileSize cacheSize: archiveFileSize
} }
) )

View File

@ -74,17 +74,13 @@ function createHttpClient(): HttpClient {
export function getCacheVersion( export function getCacheVersion(
paths: string[], paths: string[],
compressionMethod?: CompressionMethod, compressionMethod?: CompressionMethod,
crossOsEnabled = false enableCrossOsArchive = false
): string { ): string {
const components = paths const components = paths
.concat([!compressionMethod ? '' : compressionMethod])
.concat( .concat(
!compressionMethod || compressionMethod === CompressionMethod.Gzip process.platform !== 'win32' || enableCrossOsArchive ? [] : ['windows-only']
? [] ) // Only check for windows platforms if enableCrossOsArchive is false
: [compressionMethod]
)
.concat(
process.platform !== 'win32' || crossOsEnabled ? [] : ['windows-only']
) // Only check for windows platforms if crossOsEnabled is false
// Add salt to cache version to support breaking changes in cache entry // Add salt to cache version to support breaking changes in cache entry
components.push(versionSalt) components.push(versionSalt)
@ -104,7 +100,7 @@ export async function getCacheEntry(
const version = getCacheVersion( const version = getCacheVersion(
paths, paths,
options?.compressionMethod, options?.compressionMethod,
options?.crossOsEnabled options?.enableCrossOsArchive
) )
const resource = `cache?keys=${encodeURIComponent( const resource = `cache?keys=${encodeURIComponent(
keys.join(',') keys.join(',')
@ -193,7 +189,7 @@ export async function reserveCache(
const version = getCacheVersion( const version = getCacheVersion(
paths, paths,
options?.compressionMethod, options?.compressionMethod,
options?.crossOsEnabled options?.enableCrossOsArchive
) )
const reserveCacheRequest: ReserveCacheRequest = { const reserveCacheRequest: ReserveCacheRequest = {

View File

@ -35,7 +35,7 @@ export interface ReserveCacheResponse {
export interface InternalCacheOptions { export interface InternalCacheOptions {
compressionMethod?: CompressionMethod compressionMethod?: CompressionMethod
crossOsEnabled?: boolean enableCrossOsArchive?: boolean
cacheSize?: number cacheSize?: number
} }