diff --git a/packages/cache/src/cache.ts b/packages/cache/src/cache.ts index f928a2b9..098d6226 100644 --- a/packages/cache/src/cache.ts +++ b/packages/cache/src/cache.ts @@ -61,6 +61,7 @@ export function isFeatureAvailable(): boolean { * @param paths a list of file paths to restore from 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 crossOsEnabled an optional boolean enabled to restore on windows any cache created on any platform * @param downloadOptions cache download options * @returns string returns the key for the cache hit, otherwise returns undefined */ @@ -68,6 +69,7 @@ export async function restoreCache( paths: string[], primaryKey: string, restoreKeys?: string[], + crossOsEnabled = false, options?: DownloadOptions ): Promise { checkPaths(paths) @@ -93,7 +95,8 @@ export async function restoreCache( try { // path are needed to compute version cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, { - compressionMethod + compressionMethod, + crossOsEnabled }) if (!cacheEntry?.archiveLocation) { // This is to support the old cache entry created by gzip on windows. @@ -171,12 +174,14 @@ 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 options cache upload options * @returns number returns cacheId if the cache was saved successfully and throws an error if save fails */ export async function saveCache( paths: string[], key: string, + crossOsEnabled = false, options?: UploadOptions ): Promise { checkPaths(paths) @@ -227,6 +232,7 @@ export async function saveCache( paths, { compressionMethod, + crossOsEnabled, cacheSize: archiveFileSize } ) diff --git a/packages/cache/src/internal/cacheHttpClient.ts b/packages/cache/src/internal/cacheHttpClient.ts index 8982b8de..46c09a4c 100644 --- a/packages/cache/src/internal/cacheHttpClient.ts +++ b/packages/cache/src/internal/cacheHttpClient.ts @@ -73,13 +73,18 @@ function createHttpClient(): HttpClient { export function getCacheVersion( paths: string[], - compressionMethod?: CompressionMethod + compressionMethod?: CompressionMethod, + crossOsEnabled = false ): string { - const components = paths.concat( - !compressionMethod || compressionMethod === CompressionMethod.Gzip - ? [] - : [compressionMethod] - ) + const components = paths + .concat( + !compressionMethod || compressionMethod === CompressionMethod.Gzip + ? [] + : [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 components.push(versionSalt) @@ -96,7 +101,11 @@ export async function getCacheEntry( options?: InternalCacheOptions ): Promise { const httpClient = createHttpClient() - const version = getCacheVersion(paths, options?.compressionMethod) + const version = getCacheVersion( + paths, + options?.compressionMethod, + options?.crossOsEnabled + ) const resource = `cache?keys=${encodeURIComponent( keys.join(',') )}&version=${version}` @@ -181,7 +190,11 @@ export async function reserveCache( options?: InternalCacheOptions ): Promise> { const httpClient = createHttpClient() - const version = getCacheVersion(paths, options?.compressionMethod) + const version = getCacheVersion( + paths, + options?.compressionMethod, + options?.crossOsEnabled + ) const reserveCacheRequest: ReserveCacheRequest = { key, diff --git a/packages/cache/src/internal/contracts.d.ts b/packages/cache/src/internal/contracts.d.ts index 0519ff0a..1d242b1c 100644 --- a/packages/cache/src/internal/contracts.d.ts +++ b/packages/cache/src/internal/contracts.d.ts @@ -34,8 +34,9 @@ export interface ReserveCacheResponse { } export interface InternalCacheOptions { - compressionMethod?: CompressionMethod cacheSize?: number + compressionMethod?: CompressionMethod + crossOsEnabled?: boolean } export interface ArchiveTool {