1
0
Fork 0

Address review comments

pull/1237/head
Sampark Sharma 2022-11-29 10:35:22 +00:00 committed by GitHub
parent 0fd856d0a0
commit 34f0143be2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 47 deletions

View File

@ -5,7 +5,9 @@ import {
CacheFilename, CacheFilename,
CompressionMethod, CompressionMethod,
GnuTarPathOnWindows, GnuTarPathOnWindows,
SystemTarPathOnWindows ManifestFilename,
SystemTarPathOnWindows,
TarFilename
} from '../src/internal/constants' } from '../src/internal/constants'
import * as tar from '../src/internal/tar' import * as tar from '../src/internal/tar'
import * as utils from '../src/internal/cacheUtils' import * as utils from '../src/internal/cacheUtils'
@ -57,8 +59,8 @@ test('zstd extract tar', async () => {
expect(mkdirMock).toHaveBeenCalledWith(workspace) expect(mkdirMock).toHaveBeenCalledWith(workspace)
expect(execMock).toHaveBeenCalledTimes(1) expect(execMock).toHaveBeenCalledTimes(1)
expect(execMock).toHaveBeenCalledWith( expect(execMock).toHaveBeenCalledWith(
`"${tarPath}"`,
[ [
`"${tarPath}"`,
'-xf', '-xf',
IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath,
'-P', '-P',
@ -70,7 +72,8 @@ test('zstd extract tar', async () => {
.concat([ .concat([
'--use-compress-program', '--use-compress-program',
IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30' IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30'
]), ])
.join(' '),
{cwd: undefined} {cwd: undefined}
) )
}) })
@ -86,25 +89,24 @@ test('zstd extract tar with windows BSDtar', async () => {
const archivePath = `${process.env['windir']}\\fakepath\\cache.tar` const archivePath = `${process.env['windir']}\\fakepath\\cache.tar`
const workspace = process.env['GITHUB_WORKSPACE'] const workspace = process.env['GITHUB_WORKSPACE']
const tarPath = SystemTarPathOnWindows const tarPath = SystemTarPathOnWindows
const tarFilename = 'cache.tar'
await tar.extractTar(archivePath, CompressionMethod.Zstd) await tar.extractTar(archivePath, CompressionMethod.Zstd)
expect(mkdirMock).toHaveBeenCalledWith(workspace) expect(mkdirMock).toHaveBeenCalledWith(workspace)
expect(execMock).toHaveBeenCalledTimes(1) expect(execMock).toHaveBeenCalledTimes(1)
expect(execMock).toHaveBeenCalledWith( expect(execMock).toHaveBeenCalledWith(
'zstd -d --long=30 -o',
[ [
tarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), 'zstd -d --long=30 -o',
TarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
'&&', '&&',
`${tarPath}`, `${tarPath}`,
'-xf', '-xf',
tarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), TarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
'-P', '-P',
'-C', '-C',
workspace?.replace(/\\/g, '/') workspace?.replace(/\\/g, '/')
], ].join(' '),
{cwd: undefined} {cwd: undefined}
) )
} }
@ -124,8 +126,8 @@ test('gzip extract tar', async () => {
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
expect(execMock).toHaveBeenCalledTimes(1) expect(execMock).toHaveBeenCalledTimes(1)
expect(execMock).toHaveBeenCalledWith( expect(execMock).toHaveBeenCalledWith(
`"${tarPath}"`,
[ [
`"${tarPath}"`,
'-xf', '-xf',
IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath,
'-P', '-P',
@ -134,7 +136,8 @@ test('gzip extract tar', async () => {
] ]
.concat(IS_WINDOWS ? ['--force-local'] : []) .concat(IS_WINDOWS ? ['--force-local'] : [])
.concat(IS_MAC ? ['--delay-directory-restore'] : []) .concat(IS_MAC ? ['--delay-directory-restore'] : [])
.concat(['-z']), .concat(['-z'])
.join(' '),
{cwd: undefined} {cwd: undefined}
) )
}) })
@ -153,8 +156,8 @@ test('gzip extract GNU tar on windows with GNUtar in path', async () => {
expect(execMock).toHaveBeenCalledTimes(1) expect(execMock).toHaveBeenCalledTimes(1)
expect(execMock).toHaveBeenCalledWith( expect(execMock).toHaveBeenCalledWith(
`"tar"`,
[ [
`"tar"`,
'-xf', '-xf',
archivePath.replace(/\\/g, '/'), archivePath.replace(/\\/g, '/'),
'-P', '-P',
@ -162,7 +165,7 @@ test('gzip extract GNU tar on windows with GNUtar in path', async () => {
workspace?.replace(/\\/g, '/'), workspace?.replace(/\\/g, '/'),
'--force-local', '--force-local',
'-z' '-z'
], ].join(' '),
{cwd: undefined} {cwd: undefined}
) )
} }
@ -183,8 +186,8 @@ test('zstd create tar', async () => {
expect(execMock).toHaveBeenCalledTimes(1) expect(execMock).toHaveBeenCalledTimes(1)
expect(execMock).toHaveBeenCalledWith( expect(execMock).toHaveBeenCalledWith(
`"${tarPath}"`,
[ [
`"${tarPath}"`,
'--posix', '--posix',
'-cf', '-cf',
IS_WINDOWS ? CacheFilename.Zstd.replace(/\\/g, '/') : CacheFilename.Zstd, IS_WINDOWS ? CacheFilename.Zstd.replace(/\\/g, '/') : CacheFilename.Zstd,
@ -194,14 +197,15 @@ test('zstd create tar', async () => {
'-C', '-C',
IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace, IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace,
'--files-from', '--files-from',
'manifest.txt' ManifestFilename
] ]
.concat(IS_WINDOWS ? ['--force-local'] : []) .concat(IS_WINDOWS ? ['--force-local'] : [])
.concat(IS_MAC ? ['--delay-directory-restore'] : []) .concat(IS_MAC ? ['--delay-directory-restore'] : [])
.concat([ .concat([
'--use-compress-program', '--use-compress-program',
IS_WINDOWS ? 'zstd -T0 --long=30' : 'zstdmt --long=30' IS_WINDOWS ? 'zstd -T0 --long=30' : 'zstdmt --long=30'
]), ])
.join(' '),
{ {
cwd: archiveFolder cwd: archiveFolder
} }
@ -218,7 +222,6 @@ test('zstd create tar with windows BSDtar', async () => {
const archiveFolder = getTempDir() const archiveFolder = getTempDir()
const workspace = process.env['GITHUB_WORKSPACE'] const workspace = process.env['GITHUB_WORKSPACE']
const sourceDirectories = ['~/.npm/cache', `${workspace}/dist`] const sourceDirectories = ['~/.npm/cache', `${workspace}/dist`]
const tarFilename = 'cache.tar'
await fs.promises.mkdir(archiveFolder, {recursive: true}) await fs.promises.mkdir(archiveFolder, {recursive: true})
@ -232,23 +235,23 @@ test('zstd create tar with windows BSDtar', async () => {
expect(execMock).toHaveBeenCalledTimes(1) expect(execMock).toHaveBeenCalledTimes(1)
expect(execMock).toHaveBeenCalledWith( expect(execMock).toHaveBeenCalledWith(
`"${tarPath}"`,
[ [
`"${tarPath}"`,
'--posix', '--posix',
'-cf', '-cf',
tarFilename.replace(/\\/g, '/'), TarFilename.replace(/\\/g, '/'),
'--exclude', '--exclude',
tarFilename.replace(/\\/g, '/'), TarFilename.replace(/\\/g, '/'),
'-P', '-P',
'-C', '-C',
workspace?.replace(/\\/g, '/'), workspace?.replace(/\\/g, '/'),
'--files-from', '--files-from',
'manifest.txt', ManifestFilename,
'&&', '&&',
'zstd -T0 --long=30 -o', 'zstd -T0 --long=30 -o',
CacheFilename.Zstd.replace(/\\/g, '/'), CacheFilename.Zstd.replace(/\\/g, '/'),
tarFilename.replace(/\\/g, '/') TarFilename.replace(/\\/g, '/')
], ].join(' '),
{ {
cwd: archiveFolder cwd: archiveFolder
} }
@ -282,11 +285,12 @@ test('gzip create tar', async () => {
'-C', '-C',
IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace, IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace,
'--files-from', '--files-from',
'manifest.txt' ManifestFilename
] ]
.concat(IS_WINDOWS ? ['--force-local'] : []) .concat(IS_WINDOWS ? ['--force-local'] : [])
.concat(IS_MAC ? ['--delay-directory-restore'] : []) .concat(IS_MAC ? ['--delay-directory-restore'] : [])
.concat(['-z']), .concat(['-z'])
.join(' '),
{ {
cwd: archiveFolder cwd: archiveFolder
} }
@ -305,14 +309,14 @@ test('zstd list tar', async () => {
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
expect(execMock).toHaveBeenCalledTimes(1) expect(execMock).toHaveBeenCalledTimes(1)
expect(execMock).toHaveBeenCalledWith( expect(execMock).toHaveBeenCalledWith(
`"${tarPath}"`, [`"${tarPath}"`, '-tf', IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, '-P']
['-tf', IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, '-P']
.concat(IS_WINDOWS ? ['--force-local'] : []) .concat(IS_WINDOWS ? ['--force-local'] : [])
.concat(IS_MAC ? ['--delay-directory-restore'] : []) .concat(IS_MAC ? ['--delay-directory-restore'] : [])
.concat([ .concat([
'--use-compress-program', '--use-compress-program',
IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30' IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30'
]), ])
.join(' '),
{cwd: undefined} {cwd: undefined}
) )
}) })
@ -327,20 +331,19 @@ test('zstd list tar with windows BSDtar', async () => {
await tar.listTar(archivePath, CompressionMethod.Zstd) await tar.listTar(archivePath, CompressionMethod.Zstd)
const tarFilename = 'cache.tar'
const tarPath = SystemTarPathOnWindows const tarPath = SystemTarPathOnWindows
expect(execMock).toHaveBeenCalledTimes(1) expect(execMock).toHaveBeenCalledTimes(1)
expect(execMock).toHaveBeenCalledWith( expect(execMock).toHaveBeenCalledWith(
'zstd -d --long=30 -o',
[ [
tarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), 'zstd -d --long=30 -o',
TarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
'&&', '&&',
`${tarPath}`, `${tarPath}`,
'-tf', '-tf',
tarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), TarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
'-P' '-P'
], ].join(' '),
{cwd: undefined} {cwd: undefined}
) )
} }
@ -358,11 +361,11 @@ test('zstdWithoutLong list tar', async () => {
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
expect(execMock).toHaveBeenCalledTimes(1) expect(execMock).toHaveBeenCalledTimes(1)
expect(execMock).toHaveBeenCalledWith( expect(execMock).toHaveBeenCalledWith(
`"${tarPath}"`, [`"${tarPath}"`, '-tf', IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, '-P']
['-tf', IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, '-P']
.concat(IS_WINDOWS ? ['--force-local'] : []) .concat(IS_WINDOWS ? ['--force-local'] : [])
.concat(IS_MAC ? ['--delay-directory-restore'] : []) .concat(IS_MAC ? ['--delay-directory-restore'] : [])
.concat(['--use-compress-program', IS_WINDOWS ? 'zstd -d' : 'unzstd']), .concat(['--use-compress-program', IS_WINDOWS ? 'zstd -d' : 'unzstd'])
.join(' '),
{cwd: undefined} {cwd: undefined}
) )
}) })
@ -378,11 +381,11 @@ test('gzip list tar', async () => {
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
expect(execMock).toHaveBeenCalledTimes(1) expect(execMock).toHaveBeenCalledTimes(1)
expect(execMock).toHaveBeenCalledWith( expect(execMock).toHaveBeenCalledWith(
`"${tarPath}"`, [`"${tarPath}"`, '-tf', IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, '-P']
['-tf', IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, '-P']
.concat(IS_WINDOWS ? ['--force-local'] : []) .concat(IS_WINDOWS ? ['--force-local'] : [])
.concat(IS_MAC ? ['--delay-directory-restore'] : []) .concat(IS_MAC ? ['--delay-directory-restore'] : [])
.concat(['-z']), .concat(['-z'])
.join(' '),
{cwd: undefined} {cwd: undefined}
) )
}) })

View File

@ -30,4 +30,9 @@ export const SocketTimeout = 5000
// The default path of GNUtar on hosted Windows runners // The default path of GNUtar on hosted Windows runners
export const GnuTarPathOnWindows = `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe` export const GnuTarPathOnWindows = `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe`
// The default path of BSDtar on hosted Windows runners
export const SystemTarPathOnWindows = `${process.env['SYSTEMDRIVE']}\\Windows\\System32\\tar.exe` export const SystemTarPathOnWindows = `${process.env['SYSTEMDRIVE']}\\Windows\\System32\\tar.exe`
export const TarFilename = 'cache.tar'
export const ManifestFilename = 'manifest.txt'

View File

@ -7,7 +7,9 @@ import {ArchiveTool} from './contracts'
import { import {
CompressionMethod, CompressionMethod,
SystemTarPathOnWindows, SystemTarPathOnWindows,
ArchiveToolType ArchiveToolType,
TarFilename,
ManifestFilename
} from './constants' } from './constants'
const IS_WINDOWS = process.platform === 'win32' const IS_WINDOWS = process.platform === 'win32'
@ -55,7 +57,6 @@ async function getTarArgs(
archivePath = '' archivePath = ''
): Promise<string[]> { ): Promise<string[]> {
const args = [tarPath.path] const args = [tarPath.path]
const manifestFilename = 'manifest.txt'
const cacheFileName = utils.getCacheFileName(compressionMethod) const cacheFileName = utils.getCacheFileName(compressionMethod)
const tarFile = 'cache.tar' const tarFile = 'cache.tar'
const workingDirectory = getWorkingDirectory() const workingDirectory = getWorkingDirectory()
@ -81,7 +82,7 @@ async function getTarArgs(
'-C', '-C',
workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
'--files-from', '--files-from',
manifestFilename ManifestFilename
) )
break break
case 'extract': case 'extract':
@ -162,7 +163,6 @@ async function getDecompressionProgram(
// unzstd is equivalent to 'zstd -d' // unzstd is equivalent to 'zstd -d'
// --long=#: Enables long distance matching with # bits. Maximum is 30 (1GB) on 32-bit OS and 31 (2GB) on 64-bit. // --long=#: Enables long distance matching with # bits. Maximum is 30 (1GB) on 32-bit OS and 31 (2GB) on 64-bit.
// Using 30 here because we also support 32-bit self-hosted runners. // Using 30 here because we also support 32-bit self-hosted runners.
const tarFile = 'cache.tar'
const BSD_TAR_ZSTD = const BSD_TAR_ZSTD =
tarPath.type === ArchiveToolType.BSD && tarPath.type === ArchiveToolType.BSD &&
compressionMethod !== CompressionMethod.Gzip && compressionMethod !== CompressionMethod.Gzip &&
@ -172,7 +172,7 @@ async function getDecompressionProgram(
return BSD_TAR_ZSTD return BSD_TAR_ZSTD
? [ ? [
'zstd -d --long=30 -o', 'zstd -d --long=30 -o',
tarFile, TarFilename,
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
'&&' '&&'
] ]
@ -184,7 +184,7 @@ async function getDecompressionProgram(
return BSD_TAR_ZSTD return BSD_TAR_ZSTD
? [ ? [
'zstd -d -o', 'zstd -d -o',
tarFile, TarFilename,
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
'&&' '&&'
] ]
@ -204,7 +204,6 @@ async function getCompressionProgram(
compressionMethod: CompressionMethod compressionMethod: CompressionMethod
): Promise<string[]> { ): Promise<string[]> {
const cacheFileName = utils.getCacheFileName(compressionMethod) const cacheFileName = utils.getCacheFileName(compressionMethod)
const tarFile = 'cache.tar'
const BSD_TAR_ZSTD = const BSD_TAR_ZSTD =
tarPath.type === ArchiveToolType.BSD && tarPath.type === ArchiveToolType.BSD &&
compressionMethod !== CompressionMethod.Gzip && compressionMethod !== CompressionMethod.Gzip &&
@ -216,7 +215,7 @@ async function getCompressionProgram(
'&&', '&&',
'zstd -T0 --long=30 -o', 'zstd -T0 --long=30 -o',
cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
tarFile TarFilename
] ]
: [ : [
'--use-compress-program', '--use-compress-program',
@ -228,7 +227,7 @@ async function getCompressionProgram(
'&&', '&&',
'zstd -T0 -o', 'zstd -T0 -o',
cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
tarFile TarFilename
] ]
: ['--use-compress-program', IS_WINDOWS ? 'zstd -T0' : 'zstdmt'] : ['--use-compress-program', IS_WINDOWS ? 'zstd -T0' : 'zstdmt']
default: default: