1
0
Fork 0

Reconfigure catch block

pull/1260/head
Sampark Sharma 2022-12-09 09:33:59 +00:00 committed by GitHub
parent d31c2dd88d
commit 7a532d03f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 24 deletions

View File

@ -174,7 +174,7 @@ test('restore with zstd as default but gzip compressed cache found on windows',
const getCacheMock = jest.spyOn(cacheHttpClient, 'getCacheEntry')
getCacheMock
.mockImplementationOnce(async () => {
throw new Error('Cache not found.')
return Promise.resolve(null)
})
.mockImplementationOnce(async () => {
return Promise.resolve(cacheEntry)

View File

@ -91,18 +91,13 @@ export async function restoreCache(
let compressionMethod = await utils.getCompressionMethod()
let archivePath = ''
try {
try {
console.log('before first get cache entry')
// path are needed to compute version
cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, {
compressionMethod
})
console.log('after first get cache entry')
console.log(cacheEntry)
} catch (error) {
if (!cacheEntry?.archiveLocation) {
// This is to support the old cache entry created
// by the old version of the cache action on windows.
console.log('in first catch block')
if (
process.platform === 'win32' &&
compressionMethod !== CompressionMethod.Gzip
@ -114,19 +109,15 @@ export async function restoreCache(
cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, {
compressionMethod
})
console.log(cacheEntry)
if (!cacheEntry?.archiveLocation) {
throw error
return undefined
}
} else {
throw error
}
}
if (!cacheEntry?.archiveLocation) {
// Cache not found
return undefined
}
}
archivePath = path.join(
await utils.createTempDirectory(),
utils.getCacheFileName(compressionMethod)
@ -156,8 +147,6 @@ export async function restoreCache(
return cacheEntry.cacheKey
} catch (error) {
console.log('In second catch block')
console.log(error)
const typedError = error as Error
if (typedError.name === ValidationError.name) {
throw error
@ -193,8 +182,7 @@ export async function saveCache(
checkPaths(paths)
checkKey(key)
// const compressionMethod = await utils.getCompressionMethod()
const compressionMethod = CompressionMethod.Gzip
const compressionMethod = await utils.getCompressionMethod()
let cacheId = -1
const cachePaths = await utils.resolvePaths(paths)

View File

@ -127,6 +127,8 @@ async function getArgs(
type: string,
archivePath = ''
): Promise<string> {
let args: string
const tarPath = await getTarPath()
const tarArgs = await getTarArgs(
tarPath,
@ -142,11 +144,18 @@ async function getArgs(
tarPath.type === ArchiveToolType.BSD &&
compressionMethod !== CompressionMethod.Gzip &&
IS_WINDOWS
if (BSD_TAR_ZSTD && type !== 'create') {
return [...compressionArgs, ...tarArgs].join(' ')
args = [...compressionArgs, ...tarArgs].join(' ')
} else {
return [...tarArgs, ...compressionArgs].join(' ')
args = [...tarArgs, ...compressionArgs].join(' ')
}
if (BSD_TAR_ZSTD) {
args = ['cmd /c "', args, '"'].join(' ')
}
return args
}
function getWorkingDirectory(): string {