mirror of https://github.com/actions/toolkit
Add fallback to gzip compression if cache not found
parent
785599dd2e
commit
1dae855746
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue