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
@@ -0,0 +1 @@
|
||||
file-with-ç-character.txt
|
||||
@@ -0,0 +1 @@
|
||||
file.txt contents
|
||||
@@ -0,0 +1 @@
|
||||
folder/nested-file.txt contents
|
||||
@@ -15,6 +15,7 @@ process.env['RUNNER_TOOL_CACHE'] = cachePath
|
||||
import * as tc from '../src/tool-cache'
|
||||
|
||||
const IS_WINDOWS = process.platform === 'win32'
|
||||
const IS_MAC = process.platform === 'darwin'
|
||||
|
||||
describe('@actions/tool-cache', function() {
|
||||
beforeAll(function() {
|
||||
@@ -346,6 +347,110 @@ describe('@actions/tool-cache', function() {
|
||||
await io.rmRF(tempDir)
|
||||
}
|
||||
})
|
||||
} else if (IS_MAC) {
|
||||
it('extract .xar', async () => {
|
||||
const tempDir = path.join(tempPath, 'test-install.xar')
|
||||
const sourcePath = path.join(__dirname, 'data', 'archive-content')
|
||||
const targetPath = path.join(tempDir, 'test.xar')
|
||||
await io.mkdirP(tempDir)
|
||||
|
||||
// Create test archive
|
||||
const xarPath = await io.which('xar', true)
|
||||
await exec.exec(`${xarPath}`, ['-cf', targetPath, '.'], {
|
||||
cwd: sourcePath
|
||||
})
|
||||
|
||||
// extract/cache
|
||||
const extPath: string = await tc.extractXar(targetPath, undefined, '-x')
|
||||
await tc.cacheDir(extPath, 'my-xar-contents', '1.1.0')
|
||||
const toolPath: string = tc.find('my-xar-contents', '1.1.0')
|
||||
|
||||
expect(fs.existsSync(toolPath)).toBeTruthy()
|
||||
expect(fs.existsSync(`${toolPath}.complete`)).toBeTruthy()
|
||||
expect(fs.existsSync(path.join(toolPath, 'file.txt'))).toBeTruthy()
|
||||
expect(
|
||||
fs.existsSync(path.join(toolPath, 'file-with-ç-character.txt'))
|
||||
).toBeTruthy()
|
||||
expect(
|
||||
fs.existsSync(path.join(toolPath, 'folder', 'nested-file.txt'))
|
||||
).toBeTruthy()
|
||||
expect(
|
||||
fs.readFileSync(
|
||||
path.join(toolPath, 'folder', 'nested-file.txt'),
|
||||
'utf8'
|
||||
)
|
||||
).toBe('folder/nested-file.txt contents')
|
||||
})
|
||||
|
||||
it('extract .xar to a directory that does not exist', async () => {
|
||||
const tempDir = path.join(tempPath, 'test-install.xar')
|
||||
const sourcePath = path.join(__dirname, 'data', 'archive-content')
|
||||
const targetPath = path.join(tempDir, 'test.xar')
|
||||
await io.mkdirP(tempDir)
|
||||
|
||||
const destDir = path.join(tempDir, 'not-exist')
|
||||
|
||||
// Create test archive
|
||||
const xarPath = await io.which('xar', true)
|
||||
await exec.exec(`${xarPath}`, ['-cf', targetPath, '.'], {
|
||||
cwd: sourcePath
|
||||
})
|
||||
|
||||
// extract/cache
|
||||
const extPath: string = await tc.extractXar(targetPath, destDir, '-x')
|
||||
await tc.cacheDir(extPath, 'my-xar-contents', '1.1.0')
|
||||
const toolPath: string = tc.find('my-xar-contents', '1.1.0')
|
||||
|
||||
expect(fs.existsSync(toolPath)).toBeTruthy()
|
||||
expect(fs.existsSync(`${toolPath}.complete`)).toBeTruthy()
|
||||
expect(fs.existsSync(path.join(toolPath, 'file.txt'))).toBeTruthy()
|
||||
expect(
|
||||
fs.existsSync(path.join(toolPath, 'file-with-ç-character.txt'))
|
||||
).toBeTruthy()
|
||||
expect(
|
||||
fs.existsSync(path.join(toolPath, 'folder', 'nested-file.txt'))
|
||||
).toBeTruthy()
|
||||
expect(
|
||||
fs.readFileSync(
|
||||
path.join(toolPath, 'folder', 'nested-file.txt'),
|
||||
'utf8'
|
||||
)
|
||||
).toBe('folder/nested-file.txt contents')
|
||||
})
|
||||
|
||||
it('extract .xar without flags', async () => {
|
||||
const tempDir = path.join(tempPath, 'test-install.xar')
|
||||
const sourcePath = path.join(__dirname, 'data', 'archive-content')
|
||||
const targetPath = path.join(tempDir, 'test.xar')
|
||||
await io.mkdirP(tempDir)
|
||||
|
||||
// Create test archive
|
||||
const xarPath = await io.which('xar', true)
|
||||
await exec.exec(`${xarPath}`, ['-cf', targetPath, '.'], {
|
||||
cwd: sourcePath
|
||||
})
|
||||
|
||||
// extract/cache
|
||||
const extPath: string = await tc.extractXar(targetPath, undefined)
|
||||
await tc.cacheDir(extPath, 'my-xar-contents', '1.1.0')
|
||||
const toolPath: string = tc.find('my-xar-contents', '1.1.0')
|
||||
|
||||
expect(fs.existsSync(toolPath)).toBeTruthy()
|
||||
expect(fs.existsSync(`${toolPath}.complete`)).toBeTruthy()
|
||||
expect(fs.existsSync(path.join(toolPath, 'file.txt'))).toBeTruthy()
|
||||
expect(
|
||||
fs.existsSync(path.join(toolPath, 'file-with-ç-character.txt'))
|
||||
).toBeTruthy()
|
||||
expect(
|
||||
fs.existsSync(path.join(toolPath, 'folder', 'nested-file.txt'))
|
||||
).toBeTruthy()
|
||||
expect(
|
||||
fs.readFileSync(
|
||||
path.join(toolPath, 'folder', 'nested-file.txt'),
|
||||
'utf8'
|
||||
)
|
||||
).toBe('folder/nested-file.txt contents')
|
||||
})
|
||||
}
|
||||
|
||||
it('extract .tar.gz', async () => {
|
||||
|
||||
Reference in new issue
Block a user