mirror of
https://git.mirrors.martin98.com/https://github.com/actions/toolkit
synced 2026-03-15 16:22:35 +08:00
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 a6cbddccf6.
* 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:
@@ -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