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

Limit files extracted by restoreCache to those in paths option. #1927

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/cache/__tests__/restoreCache.test.ts
Original file line number Diff line number Diff line change
@@ -154,7 +154,7 @@ test('restore with gzip compressed cache found', async () => {
expect(getArchiveFileSizeInBytesMock).toHaveBeenCalledWith(archivePath)

expect(extractTarMock).toHaveBeenCalledTimes(1)
expect(extractTarMock).toHaveBeenCalledWith(archivePath, compression)
expect(extractTarMock).toHaveBeenCalledWith(archivePath, compression, paths)

expect(unlinkFileMock).toHaveBeenCalledTimes(1)
expect(unlinkFileMock).toHaveBeenCalledWith(archivePath)
@@ -215,7 +215,7 @@ test('restore with zstd compressed cache found', async () => {
expect(infoMock).toHaveBeenCalledWith(`Cache Size: ~60 MB (62915000 B)`)

expect(extractTarMock).toHaveBeenCalledTimes(1)
expect(extractTarMock).toHaveBeenCalledWith(archivePath, compression)
expect(extractTarMock).toHaveBeenCalledWith(archivePath, compression, paths)
expect(getCompressionMock).toHaveBeenCalledTimes(1)
})

@@ -273,7 +273,7 @@ test('restore with cache found for restore key', async () => {
expect(infoMock).toHaveBeenCalledWith(`Cache Size: ~0 MB (142 B)`)

expect(extractTarMock).toHaveBeenCalledTimes(1)
expect(extractTarMock).toHaveBeenCalledWith(archivePath, compression)
expect(extractTarMock).toHaveBeenCalledWith(archivePath, compression, paths)
expect(getCompressionMock).toHaveBeenCalledTimes(1)
})

6 changes: 3 additions & 3 deletions packages/cache/__tests__/restoreCacheV2.test.ts
Original file line number Diff line number Diff line change
@@ -203,7 +203,7 @@ test('restore with gzip compressed cache found', async () => {
expect(logInfoMock).toHaveBeenCalledWith(`Cache Size: ~0 MB (142 B)`)

expect(extractTarMock).toHaveBeenCalledTimes(1)
expect(extractTarMock).toHaveBeenCalledWith(archivePath, compressionMethod)
expect(extractTarMock).toHaveBeenCalledWith(archivePath, compressionMethod, paths)

expect(unlinkFileMock).toHaveBeenCalledTimes(1)
expect(unlinkFileMock).toHaveBeenCalledWith(archivePath)
@@ -279,7 +279,7 @@ test('restore with zstd compressed cache found', async () => {
expect(logInfoMock).toHaveBeenCalledWith(`Cache Size: ~60 MB (62915000 B)`)

expect(extractTarMock).toHaveBeenCalledTimes(1)
expect(extractTarMock).toHaveBeenCalledWith(archivePath, compressionMethod)
expect(extractTarMock).toHaveBeenCalledWith(archivePath, compressionMethod, paths)

expect(unlinkFileMock).toHaveBeenCalledTimes(1)
expect(unlinkFileMock).toHaveBeenCalledWith(archivePath)
@@ -356,7 +356,7 @@ test('restore with cache found for restore key', async () => {
expect(logInfoMock).toHaveBeenCalledWith(`Cache Size: ~0 MB (142 B)`)

expect(extractTarMock).toHaveBeenCalledTimes(1)
expect(extractTarMock).toHaveBeenCalledWith(archivePath, compressionMethod)
expect(extractTarMock).toHaveBeenCalledWith(archivePath, compressionMethod, paths)

expect(unlinkFileMock).toHaveBeenCalledTimes(1)
expect(unlinkFileMock).toHaveBeenCalledWith(archivePath)
4 changes: 2 additions & 2 deletions packages/cache/src/cache.ts
Original file line number Diff line number Diff line change
@@ -177,7 +177,7 @@ async function restoreCacheV1(
)} MB (${archiveFileSize} B)`
)

await extractTar(archivePath, compressionMethod)
await extractTar(archivePath, compressionMethod, paths)
core.info('Cache restored successfully')

return cacheEntry.cacheKey
@@ -291,7 +291,7 @@ async function restoreCacheV2(
await listTar(archivePath, compressionMethod)
}

await extractTar(archivePath, compressionMethod)
await extractTar(archivePath, compressionMethod, paths)
core.info('Cache restored successfully')

return response.matchedKey
17 changes: 11 additions & 6 deletions packages/cache/src/internal/tar.ts
Original file line number Diff line number Diff line change
@@ -55,7 +55,8 @@ async function getTarArgs(
tarPath: ArchiveTool,
compressionMethod: CompressionMethod,
type: string,
archivePath = ''
archivePath = '',
paths: string[] = [],
): Promise<string[]> {
const args = [`"${tarPath.path}"`]
const cacheFileName = utils.getCacheFileName(compressionMethod)
@@ -95,7 +96,8 @@ async function getTarArgs(
: archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
'-P',
'-C',
workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/')
workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
...paths,
)
break
case 'list':
@@ -128,7 +130,8 @@ async function getTarArgs(
async function getCommands(
compressionMethod: CompressionMethod,
type: string,
archivePath = ''
archivePath = '',
paths: string[] = [],
): Promise<string[]> {
let args

@@ -137,7 +140,8 @@ async function getCommands(
tarPath,
compressionMethod,
type,
archivePath
archivePath,
paths,
)
const compressionArgs =
type !== 'create'
@@ -272,12 +276,13 @@ export async function listTar(
// Extract a tar
export async function extractTar(
archivePath: string,
compressionMethod: CompressionMethod
compressionMethod: CompressionMethod,
paths?: string[],
): Promise<void> {
// Create directory to extract tar into
const workingDirectory = getWorkingDirectory()
await io.mkdirP(workingDirectory)
const commands = await getCommands(compressionMethod, 'extract', archivePath)
const commands = await getCommands(compressionMethod, 'extract', archivePath, paths)
await execCommands(commands)
}