1
0
Fork 0

Add fallback to gzip compression if cache not found

pull/1249/head
Sampark Sharma 2022-12-06 11:38:17 +00:00 committed by GitHub
parent 785599dd2e
commit 1dae855746
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 8 deletions

View File

@ -4,6 +4,8 @@ import * as utils from './internal/cacheUtils'
import * as cacheHttpClient from './internal/cacheHttpClient'
import {createTar, extractTar, listTar} from './internal/tar'
import {DownloadOptions, UploadOptions} from './options'
import {CompressionMethod} from './internal/constants'
import {ArtifactCacheEntry} from './internal/contracts'
export class ValidationError extends Error {
constructor(message: string) {
@ -85,17 +87,38 @@ export async function restoreCache(
checkKey(key)
}
const compressionMethod = await utils.getCompressionMethod()
let cacheEntry: ArtifactCacheEntry | null
let compressionMethod = await utils.getCompressionMethod()
let archivePath = ''
try {
// path are needed to compute version
const cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, {
compressionMethod
})
try {
// path are needed to compute version
cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, {
compressionMethod
})
if (!cacheEntry?.archiveLocation) {
// Cache not found
return undefined
if (!cacheEntry?.archiveLocation) {
// Cache not found
return undefined
}
} catch (error) {
if (
process.platform == 'win32' &&
compressionMethod != CompressionMethod.Gzip
) {
// On windows, we will try to download the cache entry with the same key
// but with different compression method. This is to support the old cache entry created
// by the old version of the cache action.
compressionMethod = CompressionMethod.Gzip
cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, {
compressionMethod
})
if (!cacheEntry?.archiveLocation) {
throw error
}
} else {
throw error
}
}
archivePath = path.join(