Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix known issues for cache #1260

Merged
merged 11 commits into from
Dec 12, 2022
Merged
2 changes: 1 addition & 1 deletion packages/cache/__tests__/restoreCache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions packages/cache/__tests__/tar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ test('zstd extract tar with windows BSDtar', async () => {
expect(execMock).toHaveBeenCalledTimes(1)
expect(execMock).toHaveBeenCalledWith(
[
'cmd /c "',
'zstd -d --long=30 -o',
TarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
Expand All @@ -104,7 +105,8 @@ test('zstd extract tar with windows BSDtar', async () => {
TarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
'-P',
'-C',
workspace?.replace(/\\/g, '/')
workspace?.replace(/\\/g, '/'),
'"' // end cmd /c
].join(' ')
)
}
Expand Down Expand Up @@ -233,6 +235,7 @@ test('zstd create tar with windows BSDtar', async () => {
expect(execMock).toHaveBeenCalledTimes(1)
expect(execMock).toHaveBeenCalledWith(
[
'cmd /c "',
`"${tarPath}"`,
'--posix',
'-cf',
Expand All @@ -247,7 +250,8 @@ test('zstd create tar with windows BSDtar', async () => {
'&&',
'zstd -T0 --long=30 -o',
CacheFilename.Zstd.replace(/\\/g, '/'),
TarFilename.replace(/\\/g, '/')
TarFilename.replace(/\\/g, '/'),
'"' // end cmd /c
].join(' '),
undefined, // args
{
Expand Down Expand Up @@ -338,14 +342,16 @@ test('zstd list tar with windows BSDtar', async () => {
expect(execMock).toHaveBeenCalledTimes(1)
expect(execMock).toHaveBeenCalledWith(
[
'cmd /c "',
'zstd -d --long=30 -o',
TarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
'&&',
`"${tarPath}"`,
'-tf',
TarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
'-P'
'-P',
'"' // end cmd /c
].join(' ')
)
}
Expand Down
24 changes: 12 additions & 12 deletions packages/cache/src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,11 @@ export async function restoreCache(
let compressionMethod = await utils.getCompressionMethod()
let archivePath = ''
try {
try {
// path are needed to compute version
cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, {
compressionMethod
})
} catch (error) {
// path are needed to compute version
cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, {
compressionMethod
})
if (!cacheEntry?.archiveLocation) {
// This is to support the old cache entry created
// by the old version of the cache action on windows.
if (
Expand All @@ -108,17 +107,18 @@ export async function restoreCache(
compressionMethod
})
if (!cacheEntry?.archiveLocation) {
throw error
return undefined
}

core.debug(
"Couldn't find cache entry with zstd compression, falling back to gzip compression"
)
} else {
throw error
// Cache not found
return undefined
}
}

if (!cacheEntry?.archiveLocation) {
// Cache not found
return undefined
}
archivePath = path.join(
await utils.createTempDirectory(),
utils.getCacheFileName(compressionMethod)
Expand Down
13 changes: 11 additions & 2 deletions packages/cache/src/internal/tar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ async function getArgs(
type: string,
archivePath = ''
): Promise<string> {
let args: string

const tarPath = await getTarPath()
const tarArgs = await getTarArgs(
tarPath,
Expand All @@ -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 {
Expand Down