mirror of https://github.com/actions/toolkit
feat(cache): support passing extra tar options
parent
59e9d284e9
commit
18129f1d50
|
@ -3,7 +3,7 @@ import * as path from 'path'
|
||||||
import * as utils from './internal/cacheUtils'
|
import * as utils from './internal/cacheUtils'
|
||||||
import * as cacheHttpClient from './internal/cacheHttpClient'
|
import * as cacheHttpClient from './internal/cacheHttpClient'
|
||||||
import {createTar, extractTar, listTar} from './internal/tar'
|
import {createTar, extractTar, listTar} from './internal/tar'
|
||||||
import {DownloadOptions, UploadOptions} from './options'
|
import {DownloadOptions, ExtraTarOptions, UploadOptions} from './options'
|
||||||
|
|
||||||
export class ValidationError extends Error {
|
export class ValidationError extends Error {
|
||||||
constructor(message: string) {
|
constructor(message: string) {
|
||||||
|
@ -68,7 +68,8 @@ export async function restoreCache(
|
||||||
primaryKey: string,
|
primaryKey: string,
|
||||||
restoreKeys?: string[],
|
restoreKeys?: string[],
|
||||||
options?: DownloadOptions,
|
options?: DownloadOptions,
|
||||||
enableCrossOsArchive = false
|
enableCrossOsArchive = false,
|
||||||
|
extraTarOptions: ExtraTarOptions = []
|
||||||
): Promise<string | undefined> {
|
): Promise<string | undefined> {
|
||||||
checkPaths(paths)
|
checkPaths(paths)
|
||||||
|
|
||||||
|
@ -129,7 +130,7 @@ export async function restoreCache(
|
||||||
)} MB (${archiveFileSize} B)`
|
)} MB (${archiveFileSize} B)`
|
||||||
)
|
)
|
||||||
|
|
||||||
await extractTar(archivePath, compressionMethod)
|
await extractTar(archivePath, compressionMethod, extraTarOptions)
|
||||||
core.info('Cache restored successfully')
|
core.info('Cache restored successfully')
|
||||||
|
|
||||||
return cacheEntry.cacheKey
|
return cacheEntry.cacheKey
|
||||||
|
@ -166,7 +167,8 @@ export async function saveCache(
|
||||||
paths: string[],
|
paths: string[],
|
||||||
key: string,
|
key: string,
|
||||||
options?: UploadOptions,
|
options?: UploadOptions,
|
||||||
enableCrossOsArchive = false
|
enableCrossOsArchive = false,
|
||||||
|
extraTarOptions: ExtraTarOptions = []
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
checkPaths(paths)
|
checkPaths(paths)
|
||||||
checkKey(key)
|
checkKey(key)
|
||||||
|
@ -193,7 +195,12 @@ export async function saveCache(
|
||||||
core.debug(`Archive Path: ${archivePath}`)
|
core.debug(`Archive Path: ${archivePath}`)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await createTar(archiveFolder, cachePaths, compressionMethod)
|
await createTar(
|
||||||
|
archiveFolder,
|
||||||
|
cachePaths,
|
||||||
|
compressionMethod,
|
||||||
|
extraTarOptions
|
||||||
|
)
|
||||||
if (core.isDebug()) {
|
if (core.isDebug()) {
|
||||||
await listTar(archivePath, compressionMethod)
|
await listTar(archivePath, compressionMethod)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import {
|
||||||
TarFilename,
|
TarFilename,
|
||||||
ManifestFilename
|
ManifestFilename
|
||||||
} from './constants'
|
} from './constants'
|
||||||
|
import {ExtraTarOptions} from '../options'
|
||||||
|
|
||||||
const IS_WINDOWS = process.platform === 'win32'
|
const IS_WINDOWS = process.platform === 'win32'
|
||||||
|
|
||||||
|
@ -128,7 +129,8 @@ async function getTarArgs(
|
||||||
async function getCommands(
|
async function getCommands(
|
||||||
compressionMethod: CompressionMethod,
|
compressionMethod: CompressionMethod,
|
||||||
type: string,
|
type: string,
|
||||||
archivePath = ''
|
archivePath = '',
|
||||||
|
extraTarOptions: ExtraTarOptions = []
|
||||||
): Promise<string[]> {
|
): Promise<string[]> {
|
||||||
let args
|
let args
|
||||||
|
|
||||||
|
@ -139,6 +141,7 @@ async function getCommands(
|
||||||
type,
|
type,
|
||||||
archivePath
|
archivePath
|
||||||
)
|
)
|
||||||
|
tarArgs.push(...extraTarOptions)
|
||||||
const compressionArgs =
|
const compressionArgs =
|
||||||
type !== 'create'
|
type !== 'create'
|
||||||
? await getDecompressionProgram(tarPath, compressionMethod, archivePath)
|
? await getDecompressionProgram(tarPath, compressionMethod, archivePath)
|
||||||
|
@ -272,12 +275,18 @@ export async function listTar(
|
||||||
// Extract a tar
|
// Extract a tar
|
||||||
export async function extractTar(
|
export async function extractTar(
|
||||||
archivePath: string,
|
archivePath: string,
|
||||||
compressionMethod: CompressionMethod
|
compressionMethod: CompressionMethod,
|
||||||
|
extraTarOptions: ExtraTarOptions = []
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// Create directory to extract tar into
|
// Create directory to extract tar into
|
||||||
const workingDirectory = getWorkingDirectory()
|
const workingDirectory = getWorkingDirectory()
|
||||||
await io.mkdirP(workingDirectory)
|
await io.mkdirP(workingDirectory)
|
||||||
const commands = await getCommands(compressionMethod, 'extract', archivePath)
|
const commands = await getCommands(
|
||||||
|
compressionMethod,
|
||||||
|
'extract',
|
||||||
|
archivePath,
|
||||||
|
extraTarOptions
|
||||||
|
)
|
||||||
await execCommands(commands)
|
await execCommands(commands)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,13 +294,19 @@ export async function extractTar(
|
||||||
export async function createTar(
|
export async function createTar(
|
||||||
archiveFolder: string,
|
archiveFolder: string,
|
||||||
sourceDirectories: string[],
|
sourceDirectories: string[],
|
||||||
compressionMethod: CompressionMethod
|
compressionMethod: CompressionMethod,
|
||||||
|
extraTarOptions: ExtraTarOptions = []
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// Write source directories to manifest.txt to avoid command length limits
|
// Write source directories to manifest.txt to avoid command length limits
|
||||||
writeFileSync(
|
writeFileSync(
|
||||||
path.join(archiveFolder, ManifestFilename),
|
path.join(archiveFolder, ManifestFilename),
|
||||||
sourceDirectories.join('\n')
|
sourceDirectories.join('\n')
|
||||||
)
|
)
|
||||||
const commands = await getCommands(compressionMethod, 'create')
|
const commands = await getCommands(
|
||||||
|
compressionMethod,
|
||||||
|
'create',
|
||||||
|
undefined,
|
||||||
|
extraTarOptions
|
||||||
|
)
|
||||||
await execCommands(commands, archiveFolder)
|
await execCommands(commands, archiveFolder)
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,12 @@ export interface DownloadOptions {
|
||||||
lookupOnly?: boolean
|
lookupOnly?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Additional options passed to tar
|
||||||
|
*/
|
||||||
|
|
||||||
|
export type ExtraTarOptions = string[]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a copy of the upload options with defaults filled in.
|
* Returns a copy of the upload options with defaults filled in.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue