From 18129f1d5095a9faa24928ba1955db9bb7112705 Mon Sep 17 00:00:00 2001 From: Danila Danko Date: Wed, 3 Apr 2024 00:00:05 +0300 Subject: [PATCH] feat(cache): support passing extra tar options --- packages/cache/src/cache.ts | 17 ++++++++++++----- packages/cache/src/internal/tar.ts | 25 ++++++++++++++++++++----- packages/cache/src/options.ts | 6 ++++++ 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/packages/cache/src/cache.ts b/packages/cache/src/cache.ts index f7fadb6f..a9ab1df6 100644 --- a/packages/cache/src/cache.ts +++ b/packages/cache/src/cache.ts @@ -3,7 +3,7 @@ import * as path from 'path' import * as utils from './internal/cacheUtils' import * as cacheHttpClient from './internal/cacheHttpClient' import {createTar, extractTar, listTar} from './internal/tar' -import {DownloadOptions, UploadOptions} from './options' +import {DownloadOptions, ExtraTarOptions, UploadOptions} from './options' export class ValidationError extends Error { constructor(message: string) { @@ -68,7 +68,8 @@ export async function restoreCache( primaryKey: string, restoreKeys?: string[], options?: DownloadOptions, - enableCrossOsArchive = false + enableCrossOsArchive = false, + extraTarOptions: ExtraTarOptions = [] ): Promise { checkPaths(paths) @@ -129,7 +130,7 @@ export async function restoreCache( )} MB (${archiveFileSize} B)` ) - await extractTar(archivePath, compressionMethod) + await extractTar(archivePath, compressionMethod, extraTarOptions) core.info('Cache restored successfully') return cacheEntry.cacheKey @@ -166,7 +167,8 @@ export async function saveCache( paths: string[], key: string, options?: UploadOptions, - enableCrossOsArchive = false + enableCrossOsArchive = false, + extraTarOptions: ExtraTarOptions = [] ): Promise { checkPaths(paths) checkKey(key) @@ -193,7 +195,12 @@ export async function saveCache( core.debug(`Archive Path: ${archivePath}`) try { - await createTar(archiveFolder, cachePaths, compressionMethod) + await createTar( + archiveFolder, + cachePaths, + compressionMethod, + extraTarOptions + ) if (core.isDebug()) { await listTar(archivePath, compressionMethod) } diff --git a/packages/cache/src/internal/tar.ts b/packages/cache/src/internal/tar.ts index adf61069..2272c892 100644 --- a/packages/cache/src/internal/tar.ts +++ b/packages/cache/src/internal/tar.ts @@ -11,6 +11,7 @@ import { TarFilename, ManifestFilename } from './constants' +import {ExtraTarOptions} from '../options' const IS_WINDOWS = process.platform === 'win32' @@ -128,7 +129,8 @@ async function getTarArgs( async function getCommands( compressionMethod: CompressionMethod, type: string, - archivePath = '' + archivePath = '', + extraTarOptions: ExtraTarOptions = [] ): Promise { let args @@ -139,6 +141,7 @@ async function getCommands( type, archivePath ) + tarArgs.push(...extraTarOptions) const compressionArgs = type !== 'create' ? await getDecompressionProgram(tarPath, compressionMethod, archivePath) @@ -272,12 +275,18 @@ export async function listTar( // Extract a tar export async function extractTar( archivePath: string, - compressionMethod: CompressionMethod + compressionMethod: CompressionMethod, + extraTarOptions: ExtraTarOptions = [] ): Promise { // Create directory to extract tar into const workingDirectory = getWorkingDirectory() await io.mkdirP(workingDirectory) - const commands = await getCommands(compressionMethod, 'extract', archivePath) + const commands = await getCommands( + compressionMethod, + 'extract', + archivePath, + extraTarOptions + ) await execCommands(commands) } @@ -285,13 +294,19 @@ export async function extractTar( export async function createTar( archiveFolder: string, sourceDirectories: string[], - compressionMethod: CompressionMethod + compressionMethod: CompressionMethod, + extraTarOptions: ExtraTarOptions = [] ): Promise { // Write source directories to manifest.txt to avoid command length limits writeFileSync( path.join(archiveFolder, ManifestFilename), sourceDirectories.join('\n') ) - const commands = await getCommands(compressionMethod, 'create') + const commands = await getCommands( + compressionMethod, + 'create', + undefined, + extraTarOptions + ) await execCommands(commands, archiveFolder) } diff --git a/packages/cache/src/options.ts b/packages/cache/src/options.ts index d768ff54..c936968f 100644 --- a/packages/cache/src/options.ts +++ b/packages/cache/src/options.ts @@ -70,6 +70,12 @@ export interface DownloadOptions { lookupOnly?: boolean } +/** + * Additional options passed to tar + */ + +export type ExtraTarOptions = string[] + /** * Returns a copy of the upload options with defaults filled in. *