mirror of https://github.com/actions/toolkit
Common getCompressionMethod for listTar and extractTar
parent
98a4069558
commit
ce68daa10e
|
@ -11,6 +11,12 @@ export enum CompressionMethod {
|
|||
Zstd = 'zstd'
|
||||
}
|
||||
|
||||
export enum TarOperation {
|
||||
Create = 'create',
|
||||
List = 'list',
|
||||
Extract = 'extract'
|
||||
}
|
||||
|
||||
// The default number of retry attempts.
|
||||
export const DefaultRetryAttempts = 2
|
||||
|
||||
|
|
|
@ -3,7 +3,9 @@ import * as io from '@actions/io'
|
|||
import {existsSync, writeFileSync} from 'fs'
|
||||
import * as path from 'path'
|
||||
import * as utils from './cacheUtils'
|
||||
import {CompressionMethod} from './constants'
|
||||
import {CompressionMethod, TarOperation} from './constants'
|
||||
|
||||
const IS_WINDOWS = process.platform === 'win32'
|
||||
|
||||
async function getTarPath(
|
||||
args: string[],
|
||||
|
@ -54,6 +56,41 @@ function getWorkingDirectory(): string {
|
|||
return process.env['GITHUB_WORKSPACE'] ?? process.cwd()
|
||||
}
|
||||
|
||||
// Common function for extractTar and listTar to get the compression method
|
||||
function getCompressionProgram(compressionMethod: CompressionMethod): string[] {
|
||||
// -d: Decompress.
|
||||
// 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.
|
||||
// Using 30 here because we also support 32-bit self-hosted runners.
|
||||
switch (compressionMethod) {
|
||||
case CompressionMethod.Zstd:
|
||||
return [
|
||||
'--use-compress-program',
|
||||
IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30',
|
||||
]
|
||||
case CompressionMethod.ZstdWithoutLong:
|
||||
return [
|
||||
'--use-compress-program',
|
||||
IS_WINDOWS ? 'zstd -d' : 'unzstd',
|
||||
]
|
||||
default:
|
||||
return ['-z']
|
||||
}
|
||||
}
|
||||
|
||||
export async function listTar(
|
||||
archivePath: string,
|
||||
compressionMethod: CompressionMethod
|
||||
): Promise<void> {
|
||||
const args = [
|
||||
getCompressionProgram(compressionMethod),
|
||||
'-tf',
|
||||
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||
'-P'
|
||||
]
|
||||
await execTar(args, compressionMethod)
|
||||
}
|
||||
|
||||
export async function extractTar(
|
||||
archivePath: string,
|
||||
compressionMethod: CompressionMethod
|
||||
|
@ -61,28 +98,8 @@ export async function extractTar(
|
|||
// Create directory to extract tar into
|
||||
const workingDirectory = getWorkingDirectory()
|
||||
await io.mkdirP(workingDirectory)
|
||||
// -d: Decompress.
|
||||
// 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.
|
||||
// Using 30 here because we also support 32-bit self-hosted runners.
|
||||
function getCompressionProgram(): string[] {
|
||||
switch (compressionMethod) {
|
||||
case CompressionMethod.Zstd:
|
||||
if (process.platform === 'win32') {
|
||||
return ['--use-compress-program', 'zstd -d --long=30']
|
||||
}
|
||||
return ['--use-compress-program', 'unzstd --long=30']
|
||||
case CompressionMethod.ZstdWithoutLong:
|
||||
if (process.platform === 'win32') {
|
||||
return ['--use-compress-program', 'zstd -d']
|
||||
}
|
||||
return ['--use-compress-program', 'unzstd']
|
||||
default:
|
||||
return ['-z']
|
||||
}
|
||||
}
|
||||
const args = [
|
||||
...getCompressionProgram(),
|
||||
getCompressionProgram(compressionMethod),
|
||||
'-xf',
|
||||
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||
'-P',
|
||||
|
@ -114,15 +131,15 @@ export async function createTar(
|
|||
function getCompressionProgram(): string[] {
|
||||
switch (compressionMethod) {
|
||||
case CompressionMethod.Zstd:
|
||||
if (process.platform === 'win32') {
|
||||
return ['--use-compress-program', 'zstd -T0 --long=30']
|
||||
}
|
||||
return ['--use-compress-program', 'zstdmt --long=30']
|
||||
return [
|
||||
'--use-compress-program',
|
||||
IS_WINDOWS ? 'zstd -T0 --long=30' : 'zstdmt --long=30'
|
||||
]
|
||||
case CompressionMethod.ZstdWithoutLong:
|
||||
if (process.platform === 'win32') {
|
||||
return ['--use-compress-program', 'zstd -T0']
|
||||
}
|
||||
return ['--use-compress-program', 'zstdmt']
|
||||
return [
|
||||
'--use-compress-program',
|
||||
IS_WINDOWS ? 'zstd -T0' : 'zstdmt'
|
||||
]
|
||||
default:
|
||||
return ['-z']
|
||||
}
|
||||
|
@ -141,38 +158,4 @@ export async function createTar(
|
|||
manifestFilename
|
||||
]
|
||||
await execTar(args, compressionMethod, archiveFolder)
|
||||
}
|
||||
|
||||
export async function listTar(
|
||||
archivePath: string,
|
||||
compressionMethod: CompressionMethod
|
||||
): Promise<void> {
|
||||
// -d: Decompress.
|
||||
// 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.
|
||||
// Using 30 here because we also support 32-bit self-hosted runners.
|
||||
function getCompressionProgram(): string[] {
|
||||
switch (compressionMethod) {
|
||||
case CompressionMethod.Zstd:
|
||||
if (process.platform === 'win32') {
|
||||
return ['--use-compress-program', 'zstd -d --long=30']
|
||||
}
|
||||
return ['--use-compress-program', 'unzstd --long=30']
|
||||
case CompressionMethod.ZstdWithoutLong:
|
||||
if (process.platform === 'win32') {
|
||||
return ['--use-compress-program', 'zstd -d']
|
||||
}
|
||||
return ['--use-compress-program', 'unzstd']
|
||||
default:
|
||||
return ['-z']
|
||||
}
|
||||
}
|
||||
const args = [
|
||||
...getCompressionProgram(),
|
||||
'-tf',
|
||||
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||
'-P'
|
||||
]
|
||||
await execTar(args, compressionMethod)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue