tool-cache: Support for extracting xar compatible archives (#207)
* Test xar extraction * Support for extracting xar compatible archives * Only allow extractXar on mac * Create xar during test instead of using prebuilt * Update lockfiles * Add verbose flag if debug * Add extractXar example to readme * Revert "Update lockfiles" This reverts commit a6cbddccf6bf8f7278948e719dc9e28329608cdf. * Use node pkg in example * Remove and ignore prebuilt xar * Tests for non-existing dir and without flags * Better arguments handling * Make sure that target directory exists Co-authored-by: Thomas Boop <52323235+thboop@users.noreply.github.com>
This commit is contained in:
1 parent
0945165720
commit
c62c52f3d3
6 files changed
+158
No files matched your search
@@ -23,6 +23,7 @@ export class HTTPError extends Error {
|
||||
}
|
||||
|
||||
const IS_WINDOWS = process.platform === 'win32'
|
||||
const IS_MAC = process.platform === 'darwin'
|
||||
const userAgent = 'actions/tool-cache'
|
||||
|
||||
/**
|
||||
@@ -276,6 +277,43 @@ export async function extractTar(
|
||||
return dest
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract a xar compatible archive
|
||||
*
|
||||
* @param file path to the archive
|
||||
* @param dest destination directory. Optional.
|
||||
* @param flags flags for the xar. Optional.
|
||||
* @returns path to the destination directory
|
||||
*/
|
||||
export async function extractXar(
|
||||
file: string,
|
||||
dest?: string,
|
||||
flags: string | string[] = []
|
||||
): Promise<string> {
|
||||
ok(IS_MAC, 'extractXar() not supported on current OS')
|
||||
ok(file, 'parameter "file" is required')
|
||||
|
||||
dest = await _createExtractFolder(dest)
|
||||
|
||||
let args: string[]
|
||||
if (flags instanceof Array) {
|
||||
args = flags
|
||||
} else {
|
||||
args = [flags]
|
||||
}
|
||||
|
||||
args.push('-x', '-C', dest, '-f', file)
|
||||
|
||||
if (core.isDebug()) {
|
||||
args.push('-v')
|
||||
}
|
||||
|
||||
const xarPath: string = await io.which('xar', true)
|
||||
await exec(`"${xarPath}"`, _unique(args))
|
||||
|
||||
return dest
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract a zip
|
||||
*
|
||||
@@ -675,3 +713,11 @@ function _getGlobal<T>(key: string, defaultValue: T): T {
|
||||
/* eslint-enable @typescript-eslint/no-explicit-any */
|
||||
return value !== undefined ? value : defaultValue
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of unique values.
|
||||
* @param values Values to make unique.
|
||||
*/
|
||||
function _unique<T>(values: T[]): T[] {
|
||||
return Array.from(new Set(values))
|
||||
}
|
||||
Reference in new issue
Block a user