mirror of https://github.com/actions/toolkit
add 'None' compression type and add tests
parent
b7a00a3203
commit
85a278dd2f
|
@ -46,6 +46,40 @@ afterAll(async () => {
|
||||||
await jest.requireActual('@actions/io').rmRF(getTempDir())
|
await jest.requireActual('@actions/io').rmRF(getTempDir())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('extract tar', async () => {
|
||||||
|
const mkdirMock = jest.spyOn(io, 'mkdirP')
|
||||||
|
const execMock = jest.spyOn(exec, 'exec')
|
||||||
|
|
||||||
|
const archivePath = IS_WINDOWS
|
||||||
|
? `${process.env['windir']}\\fakepath\\cache.tar`
|
||||||
|
: 'cache.tar'
|
||||||
|
const workspace = process.env['GITHUB_WORKSPACE']
|
||||||
|
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
||||||
|
|
||||||
|
await tar.extractTar(archivePath, CompressionMethod.None)
|
||||||
|
|
||||||
|
expect(mkdirMock).toHaveBeenCalledWith(workspace)
|
||||||
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
|
[
|
||||||
|
`"${tarPath}"`,
|
||||||
|
'-xf',
|
||||||
|
IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath,
|
||||||
|
'-P',
|
||||||
|
'-C',
|
||||||
|
IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace
|
||||||
|
]
|
||||||
|
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
||||||
|
.concat(IS_MAC ? ['--delay-directory-restore'] : [])
|
||||||
|
.join(' '),
|
||||||
|
undefined,
|
||||||
|
{
|
||||||
|
cwd: undefined,
|
||||||
|
env: expect.objectContaining(defaultEnv)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
test('zstd extract tar', async () => {
|
test('zstd extract tar', async () => {
|
||||||
const mkdirMock = jest.spyOn(io, 'mkdirP')
|
const mkdirMock = jest.spyOn(io, 'mkdirP')
|
||||||
const execMock = jest.spyOn(exec, 'exec')
|
const execMock = jest.spyOn(exec, 'exec')
|
||||||
|
@ -201,6 +235,45 @@ test('gzip extract GNU tar on windows with GNUtar in path', async () => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('create tar', async () => {
|
||||||
|
const execMock = jest.spyOn(exec, 'exec')
|
||||||
|
|
||||||
|
const archiveFolder = getTempDir()
|
||||||
|
const workspace = process.env['GITHUB_WORKSPACE']
|
||||||
|
const sourceDirectories = ['~/.npm/cache', `${workspace}/dist`]
|
||||||
|
|
||||||
|
await fs.promises.mkdir(archiveFolder, {recursive: true})
|
||||||
|
|
||||||
|
await tar.createTar(archiveFolder, sourceDirectories, CompressionMethod.None)
|
||||||
|
|
||||||
|
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
||||||
|
|
||||||
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
|
[
|
||||||
|
`"${tarPath}"`,
|
||||||
|
'--posix',
|
||||||
|
'-cf',
|
||||||
|
IS_WINDOWS ? CacheFilename.None.replace(/\\/g, '/') : CacheFilename.None,
|
||||||
|
'--exclude',
|
||||||
|
IS_WINDOWS ? CacheFilename.None.replace(/\\/g, '/') : CacheFilename.None,
|
||||||
|
'-P',
|
||||||
|
'-C',
|
||||||
|
IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace,
|
||||||
|
'--files-from',
|
||||||
|
ManifestFilename
|
||||||
|
]
|
||||||
|
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
||||||
|
.concat(IS_MAC ? ['--delay-directory-restore'] : [])
|
||||||
|
.join(' '),
|
||||||
|
undefined, // args
|
||||||
|
{
|
||||||
|
cwd: archiveFolder,
|
||||||
|
env: expect.objectContaining(defaultEnv)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
test('zstd create tar', async () => {
|
test('zstd create tar', async () => {
|
||||||
const execMock = jest.spyOn(exec, 'exec')
|
const execMock = jest.spyOn(exec, 'exec')
|
||||||
|
|
||||||
|
@ -345,6 +418,35 @@ test('gzip create tar', async () => {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('list tar', async () => {
|
||||||
|
const execMock = jest.spyOn(exec, 'exec')
|
||||||
|
|
||||||
|
const archivePath = IS_WINDOWS
|
||||||
|
? `${process.env['windir']}\\fakepath\\cache.tar`
|
||||||
|
: 'cache.tar'
|
||||||
|
|
||||||
|
await tar.listTar(archivePath, CompressionMethod.None)
|
||||||
|
|
||||||
|
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
||||||
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
|
[
|
||||||
|
`"${tarPath}"`,
|
||||||
|
'-tf',
|
||||||
|
IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath,
|
||||||
|
'-P'
|
||||||
|
]
|
||||||
|
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
||||||
|
.concat(IS_MAC ? ['--delay-directory-restore'] : [])
|
||||||
|
.join(' '),
|
||||||
|
undefined,
|
||||||
|
{
|
||||||
|
cwd: undefined,
|
||||||
|
env: expect.objectContaining(defaultEnv)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
test('zstd list tar', async () => {
|
test('zstd list tar', async () => {
|
||||||
const execMock = jest.spyOn(exec, 'exec')
|
const execMock = jest.spyOn(exec, 'exec')
|
||||||
|
|
||||||
|
|
|
@ -112,9 +112,15 @@ export async function getCompressionMethod(): Promise<CompressionMethod> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCacheFileName(compressionMethod: CompressionMethod): string {
|
export function getCacheFileName(compressionMethod: CompressionMethod): string {
|
||||||
return compressionMethod === CompressionMethod.Gzip
|
switch (compressionMethod) {
|
||||||
? CacheFilename.Gzip
|
default:
|
||||||
: CacheFilename.Zstd
|
case CompressionMethod.Gzip:
|
||||||
|
return CacheFilename.Gzip
|
||||||
|
case CompressionMethod.Zstd:
|
||||||
|
return CacheFilename.Zstd
|
||||||
|
case CompressionMethod.None:
|
||||||
|
return CacheFilename.None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getGnuTarPathOnWindows(): Promise<string> {
|
export async function getGnuTarPathOnWindows(): Promise<string> {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
export enum CacheFilename {
|
export enum CacheFilename {
|
||||||
Gzip = 'cache.tgz',
|
Gzip = 'cache.tgz',
|
||||||
Zstd = 'cache.tzst'
|
Zstd = 'cache.tzst',
|
||||||
|
None = 'cache.tar'
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum CompressionMethod {
|
export enum CompressionMethod {
|
||||||
|
@ -8,7 +9,8 @@ export enum CompressionMethod {
|
||||||
// Long range mode was added to zstd in v1.3.2.
|
// Long range mode was added to zstd in v1.3.2.
|
||||||
// This enum is for earlier version of zstd that does not have --long support
|
// This enum is for earlier version of zstd that does not have --long support
|
||||||
ZstdWithoutLong = 'zstd-without-long',
|
ZstdWithoutLong = 'zstd-without-long',
|
||||||
Zstd = 'zstd'
|
Zstd = 'zstd',
|
||||||
|
None = 'none'
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum ArchiveToolType {
|
export enum ArchiveToolType {
|
||||||
|
|
|
@ -5,11 +5,11 @@ import * as path from 'path'
|
||||||
import * as utils from './cacheUtils'
|
import * as utils from './cacheUtils'
|
||||||
import {ArchiveTool} from './contracts'
|
import {ArchiveTool} from './contracts'
|
||||||
import {
|
import {
|
||||||
CompressionMethod,
|
|
||||||
SystemTarPathOnWindows,
|
|
||||||
ArchiveToolType,
|
ArchiveToolType,
|
||||||
TarFilename,
|
CompressionMethod,
|
||||||
ManifestFilename
|
ManifestFilename,
|
||||||
|
SystemTarPathOnWindows,
|
||||||
|
TarFilename
|
||||||
} from './constants'
|
} from './constants'
|
||||||
|
|
||||||
const IS_WINDOWS = process.platform === 'win32'
|
const IS_WINDOWS = process.platform === 'win32'
|
||||||
|
@ -65,6 +65,7 @@ async function getTarArgs(
|
||||||
const BSD_TAR_ZSTD =
|
const BSD_TAR_ZSTD =
|
||||||
tarPath.type === ArchiveToolType.BSD &&
|
tarPath.type === ArchiveToolType.BSD &&
|
||||||
compressionMethod !== CompressionMethod.Gzip &&
|
compressionMethod !== CompressionMethod.Gzip &&
|
||||||
|
compressionMethod !== CompressionMethod.None &&
|
||||||
IS_WINDOWS
|
IS_WINDOWS
|
||||||
|
|
||||||
// Method specific args
|
// Method specific args
|
||||||
|
@ -139,10 +140,16 @@ async function getCommands(
|
||||||
type,
|
type,
|
||||||
archivePath
|
archivePath
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (compressionMethod === CompressionMethod.None) {
|
||||||
|
return [tarArgs.join(' ')]
|
||||||
|
}
|
||||||
|
|
||||||
const compressionArgs =
|
const compressionArgs =
|
||||||
type !== 'create'
|
type !== 'create'
|
||||||
? await getDecompressionProgram(tarPath, compressionMethod, archivePath)
|
? await getDecompressionProgram(tarPath, compressionMethod, archivePath)
|
||||||
: await getCompressionProgram(tarPath, compressionMethod)
|
: await getCompressionProgram(tarPath, compressionMethod)
|
||||||
|
|
||||||
const BSD_TAR_ZSTD =
|
const BSD_TAR_ZSTD =
|
||||||
tarPath.type === ArchiveToolType.BSD &&
|
tarPath.type === ArchiveToolType.BSD &&
|
||||||
compressionMethod !== CompressionMethod.Gzip &&
|
compressionMethod !== CompressionMethod.Gzip &&
|
||||||
|
@ -178,6 +185,7 @@ async function getDecompressionProgram(
|
||||||
const BSD_TAR_ZSTD =
|
const BSD_TAR_ZSTD =
|
||||||
tarPath.type === ArchiveToolType.BSD &&
|
tarPath.type === ArchiveToolType.BSD &&
|
||||||
compressionMethod !== CompressionMethod.Gzip &&
|
compressionMethod !== CompressionMethod.Gzip &&
|
||||||
|
compressionMethod !== CompressionMethod.None &&
|
||||||
IS_WINDOWS
|
IS_WINDOWS
|
||||||
switch (compressionMethod) {
|
switch (compressionMethod) {
|
||||||
case CompressionMethod.Zstd:
|
case CompressionMethod.Zstd:
|
||||||
|
@ -199,7 +207,10 @@ async function getDecompressionProgram(
|
||||||
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/')
|
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/')
|
||||||
]
|
]
|
||||||
: ['--use-compress-program', IS_WINDOWS ? '"zstd -d"' : 'unzstd']
|
: ['--use-compress-program', IS_WINDOWS ? '"zstd -d"' : 'unzstd']
|
||||||
|
case CompressionMethod.None:
|
||||||
|
return []
|
||||||
default:
|
default:
|
||||||
|
case CompressionMethod.Gzip:
|
||||||
return ['-z']
|
return ['-z']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue