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') {
const paths = ['node_modules']
const result = getCacheVersion(paths)

View File

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

View File

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

View File

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

View File

@ -62,7 +62,7 @@ export function isFeatureAvailable(): boolean {
* @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 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
*/
export async function restoreCache(
@ -70,7 +70,7 @@ export async function restoreCache(
primaryKey: string,
restoreKeys?: string[],
options?: DownloadOptions,
crossOsEnabled = false
enableCrossOsArchive = false
): Promise<string | undefined> {
checkPaths(paths)
@ -96,30 +96,12 @@ export async function restoreCache(
// path are needed to compute version
cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, {
compressionMethod,
crossOsEnabled
enableCrossOsArchive
})
if (!cacheEntry?.archiveLocation) {
// This is to support the old cache entry created by gzip on windows.
if (
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(
await utils.createTempDirectory(),
@ -174,7 +156,7 @@ export async function restoreCache(
*
* @param paths a list of file paths to be cached
* @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
* @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[],
key: string,
options?: UploadOptions,
crossOsEnabled = false
enableCrossOsArchive = false
): Promise<number> {
checkPaths(paths)
checkKey(key)
@ -232,7 +214,7 @@ export async function saveCache(
paths,
{
compressionMethod,
crossOsEnabled,
enableCrossOsArchive,
cacheSize: archiveFileSize
}
)

View File

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

View File

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