mirror of https://github.com/actions/toolkit
Address review comments
parent
d1094e1523
commit
d79a09bc0e
|
@ -174,7 +174,7 @@ test('restore with zstd as default but gzip compressed cache found on windows',
|
||||||
const getCacheMock = jest.spyOn(cacheHttpClient, 'getCacheEntry')
|
const getCacheMock = jest.spyOn(cacheHttpClient, 'getCacheEntry')
|
||||||
getCacheMock
|
getCacheMock
|
||||||
.mockImplementationOnce(async () => {
|
.mockImplementationOnce(async () => {
|
||||||
return Promise.resolve(<ArtifactCacheEntry>{})
|
throw new Error('Cache not found.')
|
||||||
})
|
})
|
||||||
.mockImplementationOnce(async () => {
|
.mockImplementationOnce(async () => {
|
||||||
return Promise.resolve(cacheEntry)
|
return Promise.resolve(cacheEntry)
|
||||||
|
|
|
@ -96,30 +96,19 @@ export async function restoreCache(
|
||||||
cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, {
|
cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, {
|
||||||
compressionMethod
|
compressionMethod
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!cacheEntry?.archiveLocation) {
|
|
||||||
// Cache not found
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (
|
cacheEntry = await cacheHttpClient.getCacheEntryForGzipFallbackOnWindows(
|
||||||
process.platform === 'win32' &&
|
keys,
|
||||||
compressionMethod !== CompressionMethod.Gzip
|
paths,
|
||||||
) {
|
compressionMethod,
|
||||||
// This is to support the old cache entry created
|
error
|
||||||
// by the old version of the cache action on windows.
|
)
|
||||||
compressionMethod = CompressionMethod.Gzip
|
|
||||||
cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, {
|
|
||||||
compressionMethod
|
|
||||||
})
|
|
||||||
if (!cacheEntry?.archiveLocation) {
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!cacheEntry?.archiveLocation) {
|
||||||
|
// Cache not found
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
archivePath = path.join(
|
archivePath = path.join(
|
||||||
await utils.createTempDirectory(),
|
await utils.createTempDirectory(),
|
||||||
utils.getCacheFileName(compressionMethod)
|
utils.getCacheFileName(compressionMethod)
|
||||||
|
|
|
@ -122,6 +122,32 @@ export async function getCacheEntry(
|
||||||
return cacheResult
|
return cacheResult
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is to support the old cache entry created
|
||||||
|
// by the old version of the cache action on windows.
|
||||||
|
export async function getCacheEntryForGzipFallbackOnWindows(
|
||||||
|
keys: string[],
|
||||||
|
paths: string[],
|
||||||
|
compressionMethod: CompressionMethod,
|
||||||
|
error: unknown
|
||||||
|
): Promise<ArtifactCacheEntry> {
|
||||||
|
let cacheEntry: ArtifactCacheEntry | null
|
||||||
|
if (
|
||||||
|
process.platform === 'win32' &&
|
||||||
|
compressionMethod !== CompressionMethod.Gzip
|
||||||
|
) {
|
||||||
|
compressionMethod = CompressionMethod.Gzip
|
||||||
|
cacheEntry = await getCacheEntry(keys, paths, {
|
||||||
|
compressionMethod
|
||||||
|
})
|
||||||
|
if (!cacheEntry?.archiveLocation) {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
return cacheEntry
|
||||||
|
}
|
||||||
|
|
||||||
export async function downloadCache(
|
export async function downloadCache(
|
||||||
archiveLocation: string,
|
archiveLocation: string,
|
||||||
archivePath: string,
|
archivePath: string,
|
||||||
|
|
Loading…
Reference in New Issue