mirror of https://github.com/actions/toolkit
Merge pull request #1238 from actions/revert-1232-phantsure/gnutar_windows
Revert "Add GNUtar as default in windows"pull/1241/head
commit
819157bf87
|
@ -1,11 +1,7 @@
|
||||||
import * as exec from '@actions/exec'
|
import * as exec from '@actions/exec'
|
||||||
import * as io from '@actions/io'
|
import * as io from '@actions/io'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import {
|
import {CacheFilename, CompressionMethod} from '../src/internal/constants'
|
||||||
CacheFilename,
|
|
||||||
CompressionMethod,
|
|
||||||
GnuTarPathOnWindows
|
|
||||||
} 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'
|
||||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||||
|
@ -32,10 +28,6 @@ beforeAll(async () => {
|
||||||
await jest.requireActual('@actions/io').rmRF(getTempDir())
|
await jest.requireActual('@actions/io').rmRF(getTempDir())
|
||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
jest.restoreAllMocks()
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
delete process.env['GITHUB_WORKSPACE']
|
delete process.env['GITHUB_WORKSPACE']
|
||||||
await jest.requireActual('@actions/io').rmRF(getTempDir())
|
await jest.requireActual('@actions/io').rmRF(getTempDir())
|
||||||
|
@ -49,14 +41,13 @@ test('zstd extract tar', async () => {
|
||||||
? `${process.env['windir']}\\fakepath\\cache.tar`
|
? `${process.env['windir']}\\fakepath\\cache.tar`
|
||||||
: 'cache.tar'
|
: 'cache.tar'
|
||||||
const workspace = process.env['GITHUB_WORKSPACE']
|
const workspace = process.env['GITHUB_WORKSPACE']
|
||||||
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
|
||||||
|
|
||||||
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(
|
||||||
`"${tarPath}"`,
|
`"${defaultTarPath}"`,
|
||||||
[
|
[
|
||||||
'--use-compress-program',
|
'--use-compress-program',
|
||||||
IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30',
|
IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30',
|
||||||
|
@ -83,7 +74,9 @@ test('gzip extract tar', async () => {
|
||||||
await tar.extractTar(archivePath, CompressionMethod.Gzip)
|
await tar.extractTar(archivePath, CompressionMethod.Gzip)
|
||||||
|
|
||||||
expect(mkdirMock).toHaveBeenCalledWith(workspace)
|
expect(mkdirMock).toHaveBeenCalledWith(workspace)
|
||||||
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
const tarPath = IS_WINDOWS
|
||||||
|
? `${process.env['windir']}\\System32\\tar.exe`
|
||||||
|
: defaultTarPath
|
||||||
expect(execMock).toHaveBeenCalledTimes(1)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
expect(execMock).toHaveBeenCalledWith(
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
`"${tarPath}"`,
|
`"${tarPath}"`,
|
||||||
|
@ -94,19 +87,18 @@ test('gzip extract tar', async () => {
|
||||||
'-P',
|
'-P',
|
||||||
'-C',
|
'-C',
|
||||||
IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace
|
IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace
|
||||||
]
|
].concat(IS_MAC ? ['--delay-directory-restore'] : []),
|
||||||
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
|
||||||
.concat(IS_MAC ? ['--delay-directory-restore'] : []),
|
|
||||||
{cwd: undefined}
|
{cwd: undefined}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('gzip extract GNU tar on windows with GNUtar in path', async () => {
|
test('gzip extract GNU tar on windows', async () => {
|
||||||
if (IS_WINDOWS) {
|
if (IS_WINDOWS) {
|
||||||
// GNU tar present in path but not at default location
|
jest.spyOn(fs, 'existsSync').mockReturnValueOnce(false)
|
||||||
|
|
||||||
const isGnuMock = jest
|
const isGnuMock = jest
|
||||||
.spyOn(utils, 'getGnuTarPathOnWindows')
|
.spyOn(utils, 'isGnuTarInstalled')
|
||||||
.mockReturnValue(Promise.resolve('tar'))
|
.mockReturnValue(Promise.resolve(true))
|
||||||
const execMock = jest.spyOn(exec, 'exec')
|
const execMock = jest.spyOn(exec, 'exec')
|
||||||
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']
|
||||||
|
@ -142,11 +134,9 @@ test('zstd create tar', async () => {
|
||||||
|
|
||||||
await tar.createTar(archiveFolder, sourceDirectories, CompressionMethod.Zstd)
|
await tar.createTar(archiveFolder, sourceDirectories, CompressionMethod.Zstd)
|
||||||
|
|
||||||
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
|
||||||
|
|
||||||
expect(execMock).toHaveBeenCalledTimes(1)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
expect(execMock).toHaveBeenCalledWith(
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
`"${tarPath}"`,
|
`"${defaultTarPath}"`,
|
||||||
[
|
[
|
||||||
'--posix',
|
'--posix',
|
||||||
'--use-compress-program',
|
'--use-compress-program',
|
||||||
|
@ -180,7 +170,9 @@ test('gzip create tar', async () => {
|
||||||
|
|
||||||
await tar.createTar(archiveFolder, sourceDirectories, CompressionMethod.Gzip)
|
await tar.createTar(archiveFolder, sourceDirectories, CompressionMethod.Gzip)
|
||||||
|
|
||||||
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
const tarPath = IS_WINDOWS
|
||||||
|
? `${process.env['windir']}\\System32\\tar.exe`
|
||||||
|
: defaultTarPath
|
||||||
|
|
||||||
expect(execMock).toHaveBeenCalledTimes(1)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
expect(execMock).toHaveBeenCalledWith(
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
|
@ -197,9 +189,7 @@ test('gzip create tar', async () => {
|
||||||
IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace,
|
IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace,
|
||||||
'--files-from',
|
'--files-from',
|
||||||
'manifest.txt'
|
'manifest.txt'
|
||||||
]
|
].concat(IS_MAC ? ['--delay-directory-restore'] : []),
|
||||||
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
|
||||||
.concat(IS_MAC ? ['--delay-directory-restore'] : []),
|
|
||||||
{
|
{
|
||||||
cwd: archiveFolder
|
cwd: archiveFolder
|
||||||
}
|
}
|
||||||
|
@ -215,10 +205,9 @@ test('zstd list tar', async () => {
|
||||||
|
|
||||||
await tar.listTar(archivePath, CompressionMethod.Zstd)
|
await tar.listTar(archivePath, CompressionMethod.Zstd)
|
||||||
|
|
||||||
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
|
||||||
expect(execMock).toHaveBeenCalledTimes(1)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
expect(execMock).toHaveBeenCalledWith(
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
`"${tarPath}"`,
|
`"${defaultTarPath}"`,
|
||||||
[
|
[
|
||||||
'--use-compress-program',
|
'--use-compress-program',
|
||||||
IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30',
|
IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30',
|
||||||
|
@ -241,10 +230,9 @@ test('zstdWithoutLong list tar', async () => {
|
||||||
|
|
||||||
await tar.listTar(archivePath, CompressionMethod.ZstdWithoutLong)
|
await tar.listTar(archivePath, CompressionMethod.ZstdWithoutLong)
|
||||||
|
|
||||||
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
|
||||||
expect(execMock).toHaveBeenCalledTimes(1)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
expect(execMock).toHaveBeenCalledWith(
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
`"${tarPath}"`,
|
`"${defaultTarPath}"`,
|
||||||
[
|
[
|
||||||
'--use-compress-program',
|
'--use-compress-program',
|
||||||
IS_WINDOWS ? 'zstd -d' : 'unzstd',
|
IS_WINDOWS ? 'zstd -d' : 'unzstd',
|
||||||
|
@ -266,7 +254,9 @@ test('gzip list tar', async () => {
|
||||||
|
|
||||||
await tar.listTar(archivePath, CompressionMethod.Gzip)
|
await tar.listTar(archivePath, CompressionMethod.Gzip)
|
||||||
|
|
||||||
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
const tarPath = IS_WINDOWS
|
||||||
|
? `${process.env['windir']}\\System32\\tar.exe`
|
||||||
|
: defaultTarPath
|
||||||
expect(execMock).toHaveBeenCalledTimes(1)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
expect(execMock).toHaveBeenCalledWith(
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
`"${tarPath}"`,
|
`"${tarPath}"`,
|
||||||
|
@ -275,9 +265,7 @@ test('gzip list tar', async () => {
|
||||||
'-tf',
|
'-tf',
|
||||||
IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath,
|
IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath,
|
||||||
'-P'
|
'-P'
|
||||||
]
|
].concat(IS_MAC ? ['--delay-directory-restore'] : []),
|
||||||
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
|
||||||
.concat(IS_MAC ? ['--delay-directory-restore'] : []),
|
|
||||||
{cwd: undefined}
|
{cwd: undefined}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
@ -7,11 +7,7 @@ import * as path from 'path'
|
||||||
import * as semver from 'semver'
|
import * as semver from 'semver'
|
||||||
import * as util from 'util'
|
import * as util from 'util'
|
||||||
import {v4 as uuidV4} from 'uuid'
|
import {v4 as uuidV4} from 'uuid'
|
||||||
import {
|
import {CacheFilename, CompressionMethod} from './constants'
|
||||||
CacheFilename,
|
|
||||||
CompressionMethod,
|
|
||||||
GnuTarPathOnWindows
|
|
||||||
} from './constants'
|
|
||||||
|
|
||||||
// From https://github.com/actions/toolkit/blob/main/packages/tool-cache/src/tool-cache.ts#L23
|
// From https://github.com/actions/toolkit/blob/main/packages/tool-cache/src/tool-cache.ts#L23
|
||||||
export async function createTempDirectory(): Promise<string> {
|
export async function createTempDirectory(): Promise<string> {
|
||||||
|
@ -94,7 +90,7 @@ async function getVersion(app: string): Promise<string> {
|
||||||
|
|
||||||
// Use zstandard if possible to maximize cache performance
|
// Use zstandard if possible to maximize cache performance
|
||||||
export async function getCompressionMethod(): Promise<CompressionMethod> {
|
export async function getCompressionMethod(): Promise<CompressionMethod> {
|
||||||
if (process.platform === 'win32' && !(await getGnuTarPathOnWindows())) {
|
if (process.platform === 'win32' && !(await isGnuTarInstalled())) {
|
||||||
// Disable zstd due to bug https://github.com/actions/cache/issues/301
|
// Disable zstd due to bug https://github.com/actions/cache/issues/301
|
||||||
return CompressionMethod.Gzip
|
return CompressionMethod.Gzip
|
||||||
}
|
}
|
||||||
|
@ -120,12 +116,9 @@ export function getCacheFileName(compressionMethod: CompressionMethod): string {
|
||||||
: CacheFilename.Zstd
|
: CacheFilename.Zstd
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getGnuTarPathOnWindows(): Promise<string> {
|
export async function isGnuTarInstalled(): Promise<boolean> {
|
||||||
if (fs.existsSync(GnuTarPathOnWindows)) {
|
|
||||||
return GnuTarPathOnWindows
|
|
||||||
}
|
|
||||||
const versionOutput = await getVersion('tar')
|
const versionOutput = await getVersion('tar')
|
||||||
return versionOutput.toLowerCase().includes('gnu tar') ? io.which('tar') : ''
|
return versionOutput.toLowerCase().includes('gnu tar')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function assertDefined<T>(name: string, value?: T): T {
|
export function assertDefined<T>(name: string, value?: T): T {
|
||||||
|
|
|
@ -21,6 +21,3 @@ export const DefaultRetryDelay = 5000
|
||||||
// over the socket during this period, the socket is destroyed and the download
|
// over the socket during this period, the socket is destroyed and the download
|
||||||
// is aborted.
|
// is aborted.
|
||||||
export const SocketTimeout = 5000
|
export const SocketTimeout = 5000
|
||||||
|
|
||||||
// The default path of GNUtar on hosted Windows runners
|
|
||||||
export const GnuTarPathOnWindows = `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe`
|
|
||||||
|
|
|
@ -7,17 +7,21 @@ import {CompressionMethod} from './constants'
|
||||||
|
|
||||||
const IS_WINDOWS = process.platform === 'win32'
|
const IS_WINDOWS = process.platform === 'win32'
|
||||||
|
|
||||||
async function getTarPath(args: string[]): Promise<string> {
|
async function getTarPath(
|
||||||
|
args: string[],
|
||||||
|
compressionMethod: CompressionMethod
|
||||||
|
): Promise<string> {
|
||||||
switch (process.platform) {
|
switch (process.platform) {
|
||||||
case 'win32': {
|
case 'win32': {
|
||||||
const gnuTar = await utils.getGnuTarPathOnWindows()
|
|
||||||
const systemTar = `${process.env['windir']}\\System32\\tar.exe`
|
const systemTar = `${process.env['windir']}\\System32\\tar.exe`
|
||||||
if (gnuTar) {
|
if (compressionMethod !== CompressionMethod.Gzip) {
|
||||||
// Use GNUtar as default on windows
|
// We only use zstandard compression on windows when gnu tar is installed due to
|
||||||
|
// a bug with compressing large files with bsdtar + zstd
|
||||||
args.push('--force-local')
|
args.push('--force-local')
|
||||||
return gnuTar
|
|
||||||
} else if (existsSync(systemTar)) {
|
} else if (existsSync(systemTar)) {
|
||||||
return systemTar
|
return systemTar
|
||||||
|
} else if (await utils.isGnuTarInstalled()) {
|
||||||
|
args.push('--force-local')
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -36,9 +40,13 @@ async function getTarPath(args: string[]): Promise<string> {
|
||||||
return await io.which('tar', true)
|
return await io.which('tar', true)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function execTar(args: string[], cwd?: string): Promise<void> {
|
async function execTar(
|
||||||
|
args: string[],
|
||||||
|
compressionMethod: CompressionMethod,
|
||||||
|
cwd?: string
|
||||||
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await exec(`"${await getTarPath(args)}"`, args, {cwd})
|
await exec(`"${await getTarPath(args, compressionMethod)}"`, args, {cwd})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(`Tar failed with error: ${error?.message}`)
|
throw new Error(`Tar failed with error: ${error?.message}`)
|
||||||
}
|
}
|
||||||
|
@ -77,7 +85,7 @@ export async function listTar(
|
||||||
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
'-P'
|
'-P'
|
||||||
]
|
]
|
||||||
await execTar(args)
|
await execTar(args, compressionMethod)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function extractTar(
|
export async function extractTar(
|
||||||
|
@ -95,7 +103,7 @@ export async function extractTar(
|
||||||
'-C',
|
'-C',
|
||||||
workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/')
|
workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/')
|
||||||
]
|
]
|
||||||
await execTar(args)
|
await execTar(args, compressionMethod)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createTar(
|
export async function createTar(
|
||||||
|
@ -143,5 +151,5 @@ export async function createTar(
|
||||||
'--files-from',
|
'--files-from',
|
||||||
manifestFilename
|
manifestFilename
|
||||||
]
|
]
|
||||||
await execTar(args, archiveFolder)
|
await execTar(args, compressionMethod, archiveFolder)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue