mirror of
https://git.mirrors.martin98.com/https://github.com/actions/toolkit
synced 2025-08-22 14:09:07 +08:00
Add fallback to gzip compression if cache not found
This commit is contained in:
parent
785599dd2e
commit
1dae855746
27
packages/cache/src/cache.ts
vendored
27
packages/cache/src/cache.ts
vendored
@ -4,6 +4,8 @@ import * as utils from './internal/cacheUtils'
|
|||||||
import * as cacheHttpClient from './internal/cacheHttpClient'
|
import * as cacheHttpClient from './internal/cacheHttpClient'
|
||||||
import {createTar, extractTar, listTar} from './internal/tar'
|
import {createTar, extractTar, listTar} from './internal/tar'
|
||||||
import {DownloadOptions, UploadOptions} from './options'
|
import {DownloadOptions, UploadOptions} from './options'
|
||||||
|
import {CompressionMethod} from './internal/constants'
|
||||||
|
import {ArtifactCacheEntry} from './internal/contracts'
|
||||||
|
|
||||||
export class ValidationError extends Error {
|
export class ValidationError extends Error {
|
||||||
constructor(message: string) {
|
constructor(message: string) {
|
||||||
@ -85,11 +87,13 @@ export async function restoreCache(
|
|||||||
checkKey(key)
|
checkKey(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
const compressionMethod = await utils.getCompressionMethod()
|
let cacheEntry: ArtifactCacheEntry | null
|
||||||
|
let compressionMethod = await utils.getCompressionMethod()
|
||||||
let archivePath = ''
|
let archivePath = ''
|
||||||
|
try {
|
||||||
try {
|
try {
|
||||||
// path are needed to compute version
|
// path are needed to compute version
|
||||||
const cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, {
|
cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, {
|
||||||
compressionMethod
|
compressionMethod
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -97,6 +101,25 @@ export async function restoreCache(
|
|||||||
// Cache not found
|
// Cache not found
|
||||||
return undefined
|
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(
|
archivePath = path.join(
|
||||||
await utils.createTempDirectory(),
|
await utils.createTempDirectory(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user