mirror of
https://git.mirrors.martin98.com/https://github.com/actions/toolkit
synced 2026-04-23 13:18:05 +08:00
Address comments
This commit is contained in:
18
packages/cache/src/internal/cacheUtils.ts
vendored
18
packages/cache/src/internal/cacheUtils.ts
vendored
@@ -7,7 +7,11 @@ import * as path from 'path'
|
||||
import * as semver from 'semver'
|
||||
import * as util from 'util'
|
||||
import {v4 as uuidV4} from 'uuid'
|
||||
import {CacheFilename, CompressionMethod} from './constants'
|
||||
import {
|
||||
CacheFilename,
|
||||
CompressionMethod,
|
||||
GnuTarPathOnWindows
|
||||
} from './constants'
|
||||
|
||||
// From https://github.com/actions/toolkit/blob/main/packages/tool-cache/src/tool-cache.ts#L23
|
||||
export async function createTempDirectory(): Promise<string> {
|
||||
@@ -90,7 +94,7 @@ async function getVersion(app: string): Promise<string> {
|
||||
|
||||
// Use zstandard if possible to maximize cache performance
|
||||
export async function getCompressionMethod(): Promise<CompressionMethod> {
|
||||
if (process.platform === 'win32' && !(await isGnuTarInstalled())) {
|
||||
if (process.platform === 'win32' && !(await getGnuTarPathOnWindows())) {
|
||||
// Disable zstd due to bug https://github.com/actions/cache/issues/301
|
||||
return CompressionMethod.Gzip
|
||||
}
|
||||
@@ -116,12 +120,12 @@ export function getCacheFileName(compressionMethod: CompressionMethod): string {
|
||||
: CacheFilename.Zstd
|
||||
}
|
||||
|
||||
export async function isGnuTarInstalled(): Promise<boolean> {
|
||||
const gnuTar = `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe`
|
||||
export async function getGnuTarPathOnWindows(): Promise<string> {
|
||||
if (fs.existsSync(GnuTarPathOnWindows)) {
|
||||
return GnuTarPathOnWindows
|
||||
}
|
||||
const versionOutput = await getVersion('tar')
|
||||
return (
|
||||
versionOutput.toLowerCase().includes('gnu tar') || fs.existsSync(gnuTar)
|
||||
)
|
||||
return versionOutput.toLowerCase().includes('gnu tar') ? io.which('tar') : ''
|
||||
}
|
||||
|
||||
export function assertDefined<T>(name: string, value?: T): T {
|
||||
|
||||
3
packages/cache/src/internal/constants.ts
vendored
3
packages/cache/src/internal/constants.ts
vendored
@@ -21,3 +21,6 @@ export const DefaultRetryDelay = 5000
|
||||
// over the socket during this period, the socket is destroyed and the download
|
||||
// is aborted.
|
||||
export const SocketTimeout = 5000
|
||||
|
||||
// The default path of GNUtar on hosted Windows runners
|
||||
export const GnuTarPathOnWindows = 'C:\\Program Files\\Git\\usr\\bin\\tar.exe'
|
||||
11
packages/cache/src/internal/tar.ts
vendored
11
packages/cache/src/internal/tar.ts
vendored
@@ -14,19 +14,12 @@ async function getTarPath(
|
||||
let tarPath = await io.which('tar', true)
|
||||
switch (process.platform) {
|
||||
case 'win32': {
|
||||
const gnuTar = `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe`
|
||||
const gnuTar = await utils.getGnuTarPathOnWindows()
|
||||
const systemTar = `${process.env['windir']}\\System32\\tar.exe`
|
||||
if (existsSync(gnuTar)) {
|
||||
if (gnuTar) {
|
||||
// Use GNUtar as default on windows
|
||||
args.push('--force-local')
|
||||
tarPath = gnuTar
|
||||
} else if (
|
||||
compressionMethod !== CompressionMethod.Gzip ||
|
||||
(await utils.isGnuTarInstalled())
|
||||
) {
|
||||
// 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')
|
||||
} else if (existsSync(systemTar)) {
|
||||
tarPath = systemTar
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user