Address review comments

This commit is contained in:
Sampark Sharma
2023-01-03 08:31:27 +00:00
committed by GitHub
parent da162e46a8
commit 0746965b72
7 changed files with 24 additions and 46 deletions

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,29 +96,11 @@ 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
}
// Cache not found
return undefined
}
archivePath = path.join(
@@ -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
}