Compare commits
19
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
44cd5d150b | ||
|
|
0822441ee0 | ||
|
|
187781e273 | ||
|
|
1f3371766a | ||
|
|
39b7a86b23 | ||
|
|
2f73afa843 | ||
|
|
ffde3e4bd5 | ||
|
|
32f538163d | ||
|
|
32b95825ba | ||
|
|
54eb9b8055 | ||
|
|
f9dfb05bd2 | ||
|
|
b3bd482c0f | ||
|
|
4fa5b7d133 | ||
|
|
ea9856079f | ||
|
|
5f89653f1b | ||
|
|
e9e146bbf8 | ||
|
|
27bf8304ea | ||
|
|
db3517fe3b | ||
|
|
6349c3ca3a |
@@ -25,7 +25,7 @@ jobs:
|
|||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Set Node.js 12.x
|
- name: Set Node.js 12.x
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: 12.x
|
node-version: 12.x
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ jobs:
|
|||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Set Node.js 12.x
|
- name: Set Node.js 12.x
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: 12.x
|
node-version: 12.x
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ jobs:
|
|||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Set Node.js 12.x
|
- name: Set Node.js 12.x
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: 12.x
|
node-version: 12.x
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ jobs:
|
|||||||
run: ls packages/${{ github.event.inputs.package }}
|
run: ls packages/${{ github.event.inputs.package }}
|
||||||
|
|
||||||
- name: Set Node.js 12.x
|
- name: Set Node.js 12.x
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: 12.x
|
node-version: 12.x
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ jobs:
|
|||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Set Node.js 12.x
|
- name: Set Node.js 12.x
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: 12.x
|
node-version: 12.x
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ jobs:
|
|||||||
os: [ubuntu-16.04, windows-2019]
|
os: [ubuntu-16.04, windows-2019]
|
||||||
runs-on: ${{matrix.os}}
|
runs-on: ${{matrix.os}}
|
||||||
actions:
|
actions:
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
version: ${{matrix.node}}
|
version: ${{matrix.node}}
|
||||||
- run: |
|
- run: |
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ e.g. To use https://github.com/actions/setup-node, users will author:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
using: actions/setup-node@v3
|
using: actions/setup-node@v1
|
||||||
```
|
```
|
||||||
|
|
||||||
# Define Metadata
|
# Define Metadata
|
||||||
|
|||||||
Vendored
+173
-56
@@ -1,7 +1,12 @@
|
|||||||
import * as exec from '@actions/exec'
|
import * as exec from '@actions/exec'
|
||||||
import * as io from '@actions/io'
|
import * as io from '@actions/io'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import {CacheFilename, CompressionMethod} from '../src/internal/constants'
|
import {
|
||||||
|
CacheFilename,
|
||||||
|
CompressionMethod,
|
||||||
|
GnuTarPathOnWindows,
|
||||||
|
SystemTarPathOnWindows
|
||||||
|
} from '../src/internal/constants'
|
||||||
import * as tar from '../src/internal/tar'
|
import * as tar from '../src/internal/tar'
|
||||||
import * as utils from '../src/internal/cacheUtils'
|
import * as utils from '../src/internal/cacheUtils'
|
||||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||||
@@ -13,7 +18,7 @@ jest.mock('@actions/io')
|
|||||||
const IS_WINDOWS = process.platform === 'win32'
|
const IS_WINDOWS = process.platform === 'win32'
|
||||||
const IS_MAC = process.platform === 'darwin'
|
const IS_MAC = process.platform === 'darwin'
|
||||||
|
|
||||||
const defaultTarPath = process.platform === 'darwin' ? 'gtar' : 'tar'
|
const defaultTarPath = IS_MAC ? 'gtar' : 'tar'
|
||||||
|
|
||||||
function getTempDir(): string {
|
function getTempDir(): string {
|
||||||
return path.join(__dirname, '_temp', 'tar')
|
return path.join(__dirname, '_temp', 'tar')
|
||||||
@@ -28,6 +33,10 @@ beforeAll(async () => {
|
|||||||
await jest.requireActual('@actions/io').rmRF(getTempDir())
|
await jest.requireActual('@actions/io').rmRF(getTempDir())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
jest.restoreAllMocks()
|
||||||
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
delete process.env['GITHUB_WORKSPACE']
|
delete process.env['GITHUB_WORKSPACE']
|
||||||
await jest.requireActual('@actions/io').rmRF(getTempDir())
|
await jest.requireActual('@actions/io').rmRF(getTempDir())
|
||||||
@@ -41,16 +50,15 @@ test('zstd extract tar', async () => {
|
|||||||
? `${process.env['windir']}\\fakepath\\cache.tar`
|
? `${process.env['windir']}\\fakepath\\cache.tar`
|
||||||
: 'cache.tar'
|
: 'cache.tar'
|
||||||
const workspace = process.env['GITHUB_WORKSPACE']
|
const workspace = process.env['GITHUB_WORKSPACE']
|
||||||
|
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
||||||
|
|
||||||
await tar.extractTar(archivePath, CompressionMethod.Zstd)
|
await tar.extractTar(archivePath, CompressionMethod.Zstd)
|
||||||
|
|
||||||
expect(mkdirMock).toHaveBeenCalledWith(workspace)
|
expect(mkdirMock).toHaveBeenCalledWith(workspace)
|
||||||
expect(execMock).toHaveBeenCalledTimes(1)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
expect(execMock).toHaveBeenCalledWith(
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
`"${defaultTarPath}"`,
|
`"${tarPath}"`,
|
||||||
[
|
[
|
||||||
'--use-compress-program',
|
|
||||||
IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30',
|
|
||||||
'-xf',
|
'-xf',
|
||||||
IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath,
|
IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath,
|
||||||
'-P',
|
'-P',
|
||||||
@@ -58,11 +66,50 @@ test('zstd extract tar', async () => {
|
|||||||
IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace
|
IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace
|
||||||
]
|
]
|
||||||
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
||||||
.concat(IS_MAC ? ['--delay-directory-restore'] : []),
|
.concat(IS_MAC ? ['--delay-directory-restore'] : [])
|
||||||
|
.concat([
|
||||||
|
'--use-compress-program',
|
||||||
|
IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30'
|
||||||
|
]),
|
||||||
{cwd: undefined}
|
{cwd: undefined}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('zstd extract tar with windows BSDtar', async () => {
|
||||||
|
if (IS_WINDOWS) {
|
||||||
|
const mkdirMock = jest.spyOn(io, 'mkdirP')
|
||||||
|
const execMock = jest.spyOn(exec, 'exec')
|
||||||
|
jest
|
||||||
|
.spyOn(utils, 'getGnuTarPathOnWindows')
|
||||||
|
.mockReturnValue(Promise.resolve(''))
|
||||||
|
|
||||||
|
const archivePath = `${process.env['windir']}\\fakepath\\cache.tar`
|
||||||
|
const workspace = process.env['GITHUB_WORKSPACE']
|
||||||
|
const tarPath = SystemTarPathOnWindows
|
||||||
|
const tarFilename = 'cache.tar'
|
||||||
|
|
||||||
|
await tar.extractTar(archivePath, CompressionMethod.Zstd)
|
||||||
|
|
||||||
|
expect(mkdirMock).toHaveBeenCalledWith(workspace)
|
||||||
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
|
'zstd -d --long=30 -o',
|
||||||
|
[
|
||||||
|
tarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
|
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
|
'&&',
|
||||||
|
`${tarPath}`,
|
||||||
|
'-xf',
|
||||||
|
tarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
|
'-P',
|
||||||
|
'-C',
|
||||||
|
workspace?.replace(/\\/g, '/')
|
||||||
|
],
|
||||||
|
{cwd: undefined}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
test('gzip extract tar', async () => {
|
test('gzip extract tar', async () => {
|
||||||
const mkdirMock = jest.spyOn(io, 'mkdirP')
|
const mkdirMock = jest.spyOn(io, 'mkdirP')
|
||||||
const execMock = jest.spyOn(exec, 'exec')
|
const execMock = jest.spyOn(exec, 'exec')
|
||||||
@@ -74,49 +121,47 @@ test('gzip extract tar', async () => {
|
|||||||
await tar.extractTar(archivePath, CompressionMethod.Gzip)
|
await tar.extractTar(archivePath, CompressionMethod.Gzip)
|
||||||
|
|
||||||
expect(mkdirMock).toHaveBeenCalledWith(workspace)
|
expect(mkdirMock).toHaveBeenCalledWith(workspace)
|
||||||
const tarPath = IS_WINDOWS
|
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
||||||
? `${process.env['windir']}\\System32\\tar.exe`
|
|
||||||
: defaultTarPath
|
|
||||||
expect(execMock).toHaveBeenCalledTimes(1)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
expect(execMock).toHaveBeenCalledWith(
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
`"${tarPath}"`,
|
`"${tarPath}"`,
|
||||||
[
|
[
|
||||||
'-z',
|
|
||||||
'-xf',
|
'-xf',
|
||||||
IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath,
|
IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath,
|
||||||
'-P',
|
'-P',
|
||||||
'-C',
|
'-C',
|
||||||
IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace
|
IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace
|
||||||
].concat(IS_MAC ? ['--delay-directory-restore'] : []),
|
]
|
||||||
|
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
||||||
|
.concat(IS_MAC ? ['--delay-directory-restore'] : [])
|
||||||
|
.concat(['-z']),
|
||||||
{cwd: undefined}
|
{cwd: undefined}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('gzip extract GNU tar on windows', async () => {
|
test('gzip extract GNU tar on windows with GNUtar in path', async () => {
|
||||||
if (IS_WINDOWS) {
|
if (IS_WINDOWS) {
|
||||||
jest.spyOn(fs, 'existsSync').mockReturnValueOnce(false)
|
// GNU tar present in path but not at default location
|
||||||
|
jest
|
||||||
const isGnuMock = jest
|
.spyOn(utils, 'getGnuTarPathOnWindows')
|
||||||
.spyOn(utils, 'isGnuTarInstalled')
|
.mockReturnValue(Promise.resolve('tar'))
|
||||||
.mockReturnValue(Promise.resolve(true))
|
|
||||||
const execMock = jest.spyOn(exec, 'exec')
|
const execMock = jest.spyOn(exec, 'exec')
|
||||||
const archivePath = `${process.env['windir']}\\fakepath\\cache.tar`
|
const archivePath = `${process.env['windir']}\\fakepath\\cache.tar`
|
||||||
const workspace = process.env['GITHUB_WORKSPACE']
|
const workspace = process.env['GITHUB_WORKSPACE']
|
||||||
|
|
||||||
await tar.extractTar(archivePath, CompressionMethod.Gzip)
|
await tar.extractTar(archivePath, CompressionMethod.Gzip)
|
||||||
|
|
||||||
expect(isGnuMock).toHaveBeenCalledTimes(1)
|
|
||||||
expect(execMock).toHaveBeenCalledTimes(1)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
expect(execMock).toHaveBeenCalledWith(
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
`"tar"`,
|
`"tar"`,
|
||||||
[
|
[
|
||||||
'-z',
|
|
||||||
'-xf',
|
'-xf',
|
||||||
archivePath.replace(/\\/g, '/'),
|
archivePath.replace(/\\/g, '/'),
|
||||||
'-P',
|
'-P',
|
||||||
'-C',
|
'-C',
|
||||||
workspace?.replace(/\\/g, '/'),
|
workspace?.replace(/\\/g, '/'),
|
||||||
'--force-local'
|
'--force-local',
|
||||||
|
'-z'
|
||||||
],
|
],
|
||||||
{cwd: undefined}
|
{cwd: undefined}
|
||||||
)
|
)
|
||||||
@@ -134,13 +179,13 @@ test('zstd create tar', async () => {
|
|||||||
|
|
||||||
await tar.createTar(archiveFolder, sourceDirectories, CompressionMethod.Zstd)
|
await tar.createTar(archiveFolder, sourceDirectories, CompressionMethod.Zstd)
|
||||||
|
|
||||||
|
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
||||||
|
|
||||||
expect(execMock).toHaveBeenCalledTimes(1)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
expect(execMock).toHaveBeenCalledWith(
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
`"${defaultTarPath}"`,
|
`"${tarPath}"`,
|
||||||
[
|
[
|
||||||
'--posix',
|
'--posix',
|
||||||
'--use-compress-program',
|
|
||||||
IS_WINDOWS ? 'zstd -T0 --long=30' : 'zstdmt --long=30',
|
|
||||||
'-cf',
|
'-cf',
|
||||||
IS_WINDOWS ? CacheFilename.Zstd.replace(/\\/g, '/') : CacheFilename.Zstd,
|
IS_WINDOWS ? CacheFilename.Zstd.replace(/\\/g, '/') : CacheFilename.Zstd,
|
||||||
'--exclude',
|
'--exclude',
|
||||||
@@ -152,13 +197,65 @@ test('zstd create tar', async () => {
|
|||||||
'manifest.txt'
|
'manifest.txt'
|
||||||
]
|
]
|
||||||
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
||||||
.concat(IS_MAC ? ['--delay-directory-restore'] : []),
|
.concat(IS_MAC ? ['--delay-directory-restore'] : [])
|
||||||
|
.concat([
|
||||||
|
'--use-compress-program',
|
||||||
|
IS_WINDOWS ? 'zstd -T0 --long=30' : 'zstdmt --long=30'
|
||||||
|
]),
|
||||||
{
|
{
|
||||||
cwd: archiveFolder
|
cwd: archiveFolder
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('zstd create tar with windows BSDtar', async () => {
|
||||||
|
if (IS_WINDOWS) {
|
||||||
|
const execMock = jest.spyOn(exec, 'exec')
|
||||||
|
jest
|
||||||
|
.spyOn(utils, 'getGnuTarPathOnWindows')
|
||||||
|
.mockReturnValue(Promise.resolve(''))
|
||||||
|
|
||||||
|
const archiveFolder = getTempDir()
|
||||||
|
const workspace = process.env['GITHUB_WORKSPACE']
|
||||||
|
const sourceDirectories = ['~/.npm/cache', `${workspace}/dist`]
|
||||||
|
const tarFilename = 'cache.tar'
|
||||||
|
|
||||||
|
await fs.promises.mkdir(archiveFolder, {recursive: true})
|
||||||
|
|
||||||
|
await tar.createTar(
|
||||||
|
archiveFolder,
|
||||||
|
sourceDirectories,
|
||||||
|
CompressionMethod.Zstd
|
||||||
|
)
|
||||||
|
|
||||||
|
const tarPath = SystemTarPathOnWindows
|
||||||
|
|
||||||
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
|
`"${tarPath}"`,
|
||||||
|
[
|
||||||
|
'--posix',
|
||||||
|
'-cf',
|
||||||
|
tarFilename.replace(/\\/g, '/'),
|
||||||
|
'--exclude',
|
||||||
|
tarFilename.replace(/\\/g, '/'),
|
||||||
|
'-P',
|
||||||
|
'-C',
|
||||||
|
workspace?.replace(/\\/g, '/'),
|
||||||
|
'--files-from',
|
||||||
|
'manifest.txt',
|
||||||
|
'&&',
|
||||||
|
'zstd -T0 --long=30 -o',
|
||||||
|
CacheFilename.Zstd.replace(/\\/g, '/'),
|
||||||
|
tarFilename.replace(/\\/g, '/')
|
||||||
|
],
|
||||||
|
{
|
||||||
|
cwd: archiveFolder
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
test('gzip create tar', async () => {
|
test('gzip create tar', async () => {
|
||||||
const execMock = jest.spyOn(exec, 'exec')
|
const execMock = jest.spyOn(exec, 'exec')
|
||||||
|
|
||||||
@@ -170,16 +267,13 @@ test('gzip create tar', async () => {
|
|||||||
|
|
||||||
await tar.createTar(archiveFolder, sourceDirectories, CompressionMethod.Gzip)
|
await tar.createTar(archiveFolder, sourceDirectories, CompressionMethod.Gzip)
|
||||||
|
|
||||||
const tarPath = IS_WINDOWS
|
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
||||||
? `${process.env['windir']}\\System32\\tar.exe`
|
|
||||||
: defaultTarPath
|
|
||||||
|
|
||||||
expect(execMock).toHaveBeenCalledTimes(1)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
expect(execMock).toHaveBeenCalledWith(
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
`"${tarPath}"`,
|
`"${tarPath}"`,
|
||||||
[
|
[
|
||||||
'--posix',
|
'--posix',
|
||||||
'-z',
|
|
||||||
'-cf',
|
'-cf',
|
||||||
IS_WINDOWS ? CacheFilename.Gzip.replace(/\\/g, '/') : CacheFilename.Gzip,
|
IS_WINDOWS ? CacheFilename.Gzip.replace(/\\/g, '/') : CacheFilename.Gzip,
|
||||||
'--exclude',
|
'--exclude',
|
||||||
@@ -189,7 +283,10 @@ test('gzip create tar', async () => {
|
|||||||
IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace,
|
IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace,
|
||||||
'--files-from',
|
'--files-from',
|
||||||
'manifest.txt'
|
'manifest.txt'
|
||||||
].concat(IS_MAC ? ['--delay-directory-restore'] : []),
|
]
|
||||||
|
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
||||||
|
.concat(IS_MAC ? ['--delay-directory-restore'] : [])
|
||||||
|
.concat(['-z']),
|
||||||
{
|
{
|
||||||
cwd: archiveFolder
|
cwd: archiveFolder
|
||||||
}
|
}
|
||||||
@@ -205,22 +302,50 @@ test('zstd list tar', async () => {
|
|||||||
|
|
||||||
await tar.listTar(archivePath, CompressionMethod.Zstd)
|
await tar.listTar(archivePath, CompressionMethod.Zstd)
|
||||||
|
|
||||||
|
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
||||||
expect(execMock).toHaveBeenCalledTimes(1)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
expect(execMock).toHaveBeenCalledWith(
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
`"${defaultTarPath}"`,
|
`"${tarPath}"`,
|
||||||
[
|
['-tf', IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, '-P']
|
||||||
'--use-compress-program',
|
|
||||||
IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30',
|
|
||||||
'-tf',
|
|
||||||
IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath,
|
|
||||||
'-P'
|
|
||||||
]
|
|
||||||
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
||||||
.concat(IS_MAC ? ['--delay-directory-restore'] : []),
|
.concat(IS_MAC ? ['--delay-directory-restore'] : [])
|
||||||
|
.concat([
|
||||||
|
'--use-compress-program',
|
||||||
|
IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30'
|
||||||
|
]),
|
||||||
{cwd: undefined}
|
{cwd: undefined}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('zstd list tar with windows BSDtar', async () => {
|
||||||
|
if (IS_WINDOWS) {
|
||||||
|
const execMock = jest.spyOn(exec, 'exec')
|
||||||
|
jest
|
||||||
|
.spyOn(utils, 'getGnuTarPathOnWindows')
|
||||||
|
.mockReturnValue(Promise.resolve(''))
|
||||||
|
const archivePath = `${process.env['windir']}\\fakepath\\cache.tar`
|
||||||
|
|
||||||
|
await tar.listTar(archivePath, CompressionMethod.Zstd)
|
||||||
|
|
||||||
|
const tarFilename = 'cache.tar'
|
||||||
|
const tarPath = SystemTarPathOnWindows
|
||||||
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
|
'zstd -d --long=30 -o',
|
||||||
|
[
|
||||||
|
tarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
|
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
|
'&&',
|
||||||
|
`${tarPath}`,
|
||||||
|
'-tf',
|
||||||
|
tarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
|
'-P'
|
||||||
|
],
|
||||||
|
{cwd: undefined}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
test('zstdWithoutLong list tar', async () => {
|
test('zstdWithoutLong list tar', async () => {
|
||||||
const execMock = jest.spyOn(exec, 'exec')
|
const execMock = jest.spyOn(exec, 'exec')
|
||||||
|
|
||||||
@@ -230,18 +355,14 @@ test('zstdWithoutLong list tar', async () => {
|
|||||||
|
|
||||||
await tar.listTar(archivePath, CompressionMethod.ZstdWithoutLong)
|
await tar.listTar(archivePath, CompressionMethod.ZstdWithoutLong)
|
||||||
|
|
||||||
|
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
||||||
expect(execMock).toHaveBeenCalledTimes(1)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
expect(execMock).toHaveBeenCalledWith(
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
`"${defaultTarPath}"`,
|
`"${tarPath}"`,
|
||||||
[
|
['-tf', IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, '-P']
|
||||||
'--use-compress-program',
|
|
||||||
IS_WINDOWS ? 'zstd -d' : 'unzstd',
|
|
||||||
'-tf',
|
|
||||||
IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath,
|
|
||||||
'-P'
|
|
||||||
]
|
|
||||||
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
||||||
.concat(IS_MAC ? ['--delay-directory-restore'] : []),
|
.concat(IS_MAC ? ['--delay-directory-restore'] : [])
|
||||||
|
.concat(['--use-compress-program', IS_WINDOWS ? 'zstd -d' : 'unzstd']),
|
||||||
{cwd: undefined}
|
{cwd: undefined}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -254,18 +375,14 @@ test('gzip list tar', async () => {
|
|||||||
|
|
||||||
await tar.listTar(archivePath, CompressionMethod.Gzip)
|
await tar.listTar(archivePath, CompressionMethod.Gzip)
|
||||||
|
|
||||||
const tarPath = IS_WINDOWS
|
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
||||||
? `${process.env['windir']}\\System32\\tar.exe`
|
|
||||||
: defaultTarPath
|
|
||||||
expect(execMock).toHaveBeenCalledTimes(1)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
expect(execMock).toHaveBeenCalledWith(
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
`"${tarPath}"`,
|
`"${tarPath}"`,
|
||||||
[
|
['-tf', IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, '-P']
|
||||||
'-z',
|
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
||||||
'-tf',
|
.concat(IS_MAC ? ['--delay-directory-restore'] : [])
|
||||||
IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath,
|
.concat(['-z']),
|
||||||
'-P'
|
|
||||||
].concat(IS_MAC ? ['--delay-directory-restore'] : []),
|
|
||||||
{cwd: undefined}
|
{cwd: undefined}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
+11
-9
@@ -7,7 +7,11 @@ import * as path from 'path'
|
|||||||
import * as semver from 'semver'
|
import * as semver from 'semver'
|
||||||
import * as util from 'util'
|
import * as util from 'util'
|
||||||
import {v4 as uuidV4} from 'uuid'
|
import {v4 as uuidV4} from 'uuid'
|
||||||
import {CacheFilename, CompressionMethod} from './constants'
|
import {
|
||||||
|
CacheFilename,
|
||||||
|
CompressionMethod,
|
||||||
|
GnuTarPathOnWindows
|
||||||
|
} from './constants'
|
||||||
|
|
||||||
// From https://github.com/actions/toolkit/blob/main/packages/tool-cache/src/tool-cache.ts#L23
|
// From https://github.com/actions/toolkit/blob/main/packages/tool-cache/src/tool-cache.ts#L23
|
||||||
export async function createTempDirectory(): Promise<string> {
|
export async function createTempDirectory(): Promise<string> {
|
||||||
@@ -67,7 +71,7 @@ export async function unlinkFile(filePath: fs.PathLike): Promise<void> {
|
|||||||
return util.promisify(fs.unlink)(filePath)
|
return util.promisify(fs.unlink)(filePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getVersion(app: string): Promise<string> {
|
export async function getVersion(app: string): Promise<string> {
|
||||||
core.debug(`Checking ${app} --version`)
|
core.debug(`Checking ${app} --version`)
|
||||||
let versionOutput = ''
|
let versionOutput = ''
|
||||||
try {
|
try {
|
||||||
@@ -90,11 +94,6 @@ async function getVersion(app: string): Promise<string> {
|
|||||||
|
|
||||||
// Use zstandard if possible to maximize cache performance
|
// Use zstandard if possible to maximize cache performance
|
||||||
export async function getCompressionMethod(): Promise<CompressionMethod> {
|
export async function getCompressionMethod(): Promise<CompressionMethod> {
|
||||||
if (process.platform === 'win32' && !(await isGnuTarInstalled())) {
|
|
||||||
// Disable zstd due to bug https://github.com/actions/cache/issues/301
|
|
||||||
return CompressionMethod.Gzip
|
|
||||||
}
|
|
||||||
|
|
||||||
const versionOutput = await getVersion('zstd')
|
const versionOutput = await getVersion('zstd')
|
||||||
const version = semver.clean(versionOutput)
|
const version = semver.clean(versionOutput)
|
||||||
|
|
||||||
@@ -116,9 +115,12 @@ export function getCacheFileName(compressionMethod: CompressionMethod): string {
|
|||||||
: CacheFilename.Zstd
|
: CacheFilename.Zstd
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function isGnuTarInstalled(): Promise<boolean> {
|
export async function getGnuTarPathOnWindows(): Promise<string> {
|
||||||
|
if (fs.existsSync(GnuTarPathOnWindows)) {
|
||||||
|
return GnuTarPathOnWindows
|
||||||
|
}
|
||||||
const versionOutput = await getVersion('tar')
|
const versionOutput = await getVersion('tar')
|
||||||
return versionOutput.toLowerCase().includes('gnu tar')
|
return versionOutput.toLowerCase().includes('gnu tar') ? io.which('tar') : ''
|
||||||
}
|
}
|
||||||
|
|
||||||
export function assertDefined<T>(name: string, value?: T): T {
|
export function assertDefined<T>(name: string, value?: T): T {
|
||||||
|
|||||||
+5
@@ -21,3 +21,8 @@ export const DefaultRetryDelay = 5000
|
|||||||
// over the socket during this period, the socket is destroyed and the download
|
// over the socket during this period, the socket is destroyed and the download
|
||||||
// is aborted.
|
// is aborted.
|
||||||
export const SocketTimeout = 5000
|
export const SocketTimeout = 5000
|
||||||
|
|
||||||
|
// The default path of GNUtar on hosted Windows runners
|
||||||
|
export const GnuTarPathOnWindows = `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe`
|
||||||
|
|
||||||
|
export const SystemTarPathOnWindows = `${process.env['SYSTEMDRIVE']}\\Windows\\System32\\tar.exe`
|
||||||
|
|||||||
Vendored
+309
-58
@@ -3,25 +3,21 @@ import * as io from '@actions/io'
|
|||||||
import {existsSync, writeFileSync} from 'fs'
|
import {existsSync, writeFileSync} from 'fs'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import * as utils from './cacheUtils'
|
import * as utils from './cacheUtils'
|
||||||
import {CompressionMethod} from './constants'
|
import {CompressionMethod, SystemTarPathOnWindows} from './constants'
|
||||||
|
|
||||||
const IS_WINDOWS = process.platform === 'win32'
|
const IS_WINDOWS = process.platform === 'win32'
|
||||||
|
|
||||||
async function getTarPath(
|
// Function also mutates the args array. For non-mutation call with passing an empty array.
|
||||||
args: string[],
|
async function getTarPath(): Promise<string> {
|
||||||
compressionMethod: CompressionMethod
|
|
||||||
): Promise<string> {
|
|
||||||
switch (process.platform) {
|
switch (process.platform) {
|
||||||
case 'win32': {
|
case 'win32': {
|
||||||
const systemTar = `${process.env['windir']}\\System32\\tar.exe`
|
const gnuTar = await utils.getGnuTarPathOnWindows()
|
||||||
if (compressionMethod !== CompressionMethod.Gzip) {
|
const systemTar = SystemTarPathOnWindows
|
||||||
// We only use zstandard compression on windows when gnu tar is installed due to
|
if (gnuTar) {
|
||||||
// a bug with compressing large files with bsdtar + zstd
|
// Use GNUtar as default on windows
|
||||||
args.push('--force-local')
|
return gnuTar
|
||||||
} else if (existsSync(systemTar)) {
|
} else if (existsSync(systemTar)) {
|
||||||
return systemTar
|
return systemTar
|
||||||
} else if (await utils.isGnuTarInstalled()) {
|
|
||||||
args.push('--force-local')
|
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -29,7 +25,6 @@ async function getTarPath(
|
|||||||
const gnuTar = await io.which('gtar', false)
|
const gnuTar = await io.which('gtar', false)
|
||||||
if (gnuTar) {
|
if (gnuTar) {
|
||||||
// fix permission denied errors when extracting BSD tar archive with GNU tar - https://github.com/actions/cache/issues/527
|
// fix permission denied errors when extracting BSD tar archive with GNU tar - https://github.com/actions/cache/issues/527
|
||||||
args.push('--delay-directory-restore')
|
|
||||||
return gnuTar
|
return gnuTar
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
@@ -40,13 +35,101 @@ async function getTarPath(
|
|||||||
return await io.which('tar', true)
|
return await io.which('tar', true)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function execTar(
|
async function getTarArgs(
|
||||||
args: string[],
|
|
||||||
compressionMethod: CompressionMethod,
|
compressionMethod: CompressionMethod,
|
||||||
|
type: string,
|
||||||
|
archivePath = ''
|
||||||
|
): Promise<string[]> {
|
||||||
|
const args = []
|
||||||
|
const manifestFilename = 'manifest.txt'
|
||||||
|
const cacheFileName = utils.getCacheFileName(compressionMethod)
|
||||||
|
const tarFile = 'cache.tar'
|
||||||
|
const tarPath = await getTarPath()
|
||||||
|
const workingDirectory = getWorkingDirectory()
|
||||||
|
const BSD_TAR_ZSTD =
|
||||||
|
tarPath === SystemTarPathOnWindows &&
|
||||||
|
compressionMethod !== CompressionMethod.Gzip
|
||||||
|
|
||||||
|
// Method specific args
|
||||||
|
switch (type) {
|
||||||
|
case 'create':
|
||||||
|
args.push(
|
||||||
|
'--posix',
|
||||||
|
'-cf',
|
||||||
|
BSD_TAR_ZSTD
|
||||||
|
? tarFile
|
||||||
|
: cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
|
'--exclude',
|
||||||
|
BSD_TAR_ZSTD
|
||||||
|
? tarFile
|
||||||
|
: cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
|
'-P',
|
||||||
|
'-C',
|
||||||
|
workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
|
'--files-from',
|
||||||
|
manifestFilename
|
||||||
|
)
|
||||||
|
break
|
||||||
|
case 'extract':
|
||||||
|
args.push(
|
||||||
|
'-xf',
|
||||||
|
BSD_TAR_ZSTD
|
||||||
|
? tarFile
|
||||||
|
: archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
|
'-P',
|
||||||
|
'-C',
|
||||||
|
workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/')
|
||||||
|
)
|
||||||
|
break
|
||||||
|
case 'list':
|
||||||
|
args.push(
|
||||||
|
'-tf',
|
||||||
|
BSD_TAR_ZSTD
|
||||||
|
? tarFile
|
||||||
|
: archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
|
'-P'
|
||||||
|
)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
// Platform specific args
|
||||||
|
switch (process.platform) {
|
||||||
|
case 'win32': {
|
||||||
|
const gnuTar = await utils.getGnuTarPathOnWindows()
|
||||||
|
if (gnuTar) {
|
||||||
|
// Use GNUtar as default on windows
|
||||||
|
args.push('--force-local')
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case 'darwin': {
|
||||||
|
const gnuTar = await io.which('gtar', false)
|
||||||
|
if (gnuTar) {
|
||||||
|
// fix permission denied errors when extracting BSD tar archive with GNU tar - https://github.com/actions/cache/issues/527
|
||||||
|
args.push('--delay-directory-restore')
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return args
|
||||||
|
}
|
||||||
|
|
||||||
|
async function execTar(args: string[], cwd?: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
await exec(`"${await getTarPath()}"`, args, {cwd})
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(`Tar failed with error: ${error?.message}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function execCommand(
|
||||||
|
command: string,
|
||||||
|
args: string[],
|
||||||
cwd?: string
|
cwd?: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await exec(`"${await getTarPath(args, compressionMethod)}"`, args, {cwd})
|
await exec(command, args, {cwd})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(`Tar failed with error: ${error?.message}`)
|
throw new Error(`Tar failed with error: ${error?.message}`)
|
||||||
}
|
}
|
||||||
@@ -57,19 +140,41 @@ function getWorkingDirectory(): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Common function for extractTar and listTar to get the compression method
|
// Common function for extractTar and listTar to get the compression method
|
||||||
function getCompressionProgram(compressionMethod: CompressionMethod): string[] {
|
async function getCompressionProgram(
|
||||||
|
compressionMethod: CompressionMethod,
|
||||||
|
archivePath: string
|
||||||
|
): Promise<string[]> {
|
||||||
// -d: Decompress.
|
// -d: Decompress.
|
||||||
// unzstd is equivalent to 'zstd -d'
|
// unzstd is equivalent to 'zstd -d'
|
||||||
// --long=#: Enables long distance matching with # bits. Maximum is 30 (1GB) on 32-bit OS and 31 (2GB) on 64-bit.
|
// --long=#: Enables long distance matching with # bits. Maximum is 30 (1GB) on 32-bit OS and 31 (2GB) on 64-bit.
|
||||||
// Using 30 here because we also support 32-bit self-hosted runners.
|
// Using 30 here because we also support 32-bit self-hosted runners.
|
||||||
|
const tarPath = await getTarPath()
|
||||||
|
const tarFile = 'cache.tar'
|
||||||
|
const BSD_TAR_ZSTD =
|
||||||
|
tarPath === SystemTarPathOnWindows &&
|
||||||
|
compressionMethod !== CompressionMethod.Gzip
|
||||||
switch (compressionMethod) {
|
switch (compressionMethod) {
|
||||||
case CompressionMethod.Zstd:
|
case CompressionMethod.Zstd:
|
||||||
return [
|
return BSD_TAR_ZSTD
|
||||||
'--use-compress-program',
|
? [
|
||||||
IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30'
|
'zstd -d --long=30 -o',
|
||||||
]
|
tarFile,
|
||||||
|
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
|
'&&'
|
||||||
|
]
|
||||||
|
: [
|
||||||
|
'--use-compress-program',
|
||||||
|
IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30'
|
||||||
|
]
|
||||||
case CompressionMethod.ZstdWithoutLong:
|
case CompressionMethod.ZstdWithoutLong:
|
||||||
return ['--use-compress-program', IS_WINDOWS ? 'zstd -d' : 'unzstd']
|
return BSD_TAR_ZSTD
|
||||||
|
? [
|
||||||
|
'zstd -d -o',
|
||||||
|
tarFile,
|
||||||
|
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
|
'&&'
|
||||||
|
]
|
||||||
|
: ['--use-compress-program', IS_WINDOWS ? 'zstd -d' : 'unzstd']
|
||||||
default:
|
default:
|
||||||
return ['-z']
|
return ['-z']
|
||||||
}
|
}
|
||||||
@@ -79,13 +184,27 @@ export async function listTar(
|
|||||||
archivePath: string,
|
archivePath: string,
|
||||||
compressionMethod: CompressionMethod
|
compressionMethod: CompressionMethod
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const args = [
|
const tarPath = await getTarPath()
|
||||||
...getCompressionProgram(compressionMethod),
|
const BSD_TAR_ZSTD =
|
||||||
'-tf',
|
tarPath === SystemTarPathOnWindows &&
|
||||||
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
compressionMethod !== CompressionMethod.Gzip
|
||||||
'-P'
|
const compressionArgs = await getCompressionProgram(
|
||||||
]
|
compressionMethod,
|
||||||
await execTar(args, compressionMethod)
|
archivePath
|
||||||
|
)
|
||||||
|
const tarArgs = await getTarArgs(compressionMethod, 'list', archivePath)
|
||||||
|
// TODO: Add a test for BSD tar on windows
|
||||||
|
if (BSD_TAR_ZSTD) {
|
||||||
|
const command = compressionArgs[0]
|
||||||
|
const args = compressionArgs
|
||||||
|
.slice(1)
|
||||||
|
.concat([tarPath])
|
||||||
|
.concat(tarArgs)
|
||||||
|
await execCommand(command, args)
|
||||||
|
} else {
|
||||||
|
const args = tarArgs.concat(compressionArgs)
|
||||||
|
await execTar(args)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function extractTar(
|
export async function extractTar(
|
||||||
@@ -94,16 +213,27 @@ export async function extractTar(
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// Create directory to extract tar into
|
// Create directory to extract tar into
|
||||||
const workingDirectory = getWorkingDirectory()
|
const workingDirectory = getWorkingDirectory()
|
||||||
|
const tarPath = await getTarPath()
|
||||||
|
const BSD_TAR_ZSTD =
|
||||||
|
tarPath === SystemTarPathOnWindows &&
|
||||||
|
compressionMethod !== CompressionMethod.Gzip
|
||||||
await io.mkdirP(workingDirectory)
|
await io.mkdirP(workingDirectory)
|
||||||
const args = [
|
const tarArgs = await getTarArgs(compressionMethod, 'extract', archivePath)
|
||||||
...getCompressionProgram(compressionMethod),
|
const compressionArgs = await getCompressionProgram(
|
||||||
'-xf',
|
compressionMethod,
|
||||||
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
archivePath
|
||||||
'-P',
|
)
|
||||||
'-C',
|
if (BSD_TAR_ZSTD) {
|
||||||
workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/')
|
const command = compressionArgs[0]
|
||||||
]
|
const args = compressionArgs
|
||||||
await execTar(args, compressionMethod)
|
.slice(1)
|
||||||
|
.concat([tarPath])
|
||||||
|
.concat(tarArgs)
|
||||||
|
await execCommand(command, args)
|
||||||
|
} else {
|
||||||
|
const args = tarArgs.concat(compressionArgs)
|
||||||
|
await execTar(args)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createTar(
|
export async function createTar(
|
||||||
@@ -114,11 +244,15 @@ export async function createTar(
|
|||||||
// Write source directories to manifest.txt to avoid command length limits
|
// Write source directories to manifest.txt to avoid command length limits
|
||||||
const manifestFilename = 'manifest.txt'
|
const manifestFilename = 'manifest.txt'
|
||||||
const cacheFileName = utils.getCacheFileName(compressionMethod)
|
const cacheFileName = utils.getCacheFileName(compressionMethod)
|
||||||
|
const tarFile = 'cache.tar'
|
||||||
|
const tarPath = await getTarPath()
|
||||||
|
const BSD_TAR_ZSTD =
|
||||||
|
tarPath === SystemTarPathOnWindows &&
|
||||||
|
compressionMethod !== CompressionMethod.Gzip
|
||||||
writeFileSync(
|
writeFileSync(
|
||||||
path.join(archiveFolder, manifestFilename),
|
path.join(archiveFolder, manifestFilename),
|
||||||
sourceDirectories.join('\n')
|
sourceDirectories.join('\n')
|
||||||
)
|
)
|
||||||
const workingDirectory = getWorkingDirectory()
|
|
||||||
|
|
||||||
// -T#: Compress using # working thread. If # is 0, attempt to detect and use the number of physical CPU cores.
|
// -T#: Compress using # working thread. If # is 0, attempt to detect and use the number of physical CPU cores.
|
||||||
// zstdmt is equivalent to 'zstd -T0'
|
// zstdmt is equivalent to 'zstd -T0'
|
||||||
@@ -128,28 +262,145 @@ export async function createTar(
|
|||||||
function getCompressionProgram(): string[] {
|
function getCompressionProgram(): string[] {
|
||||||
switch (compressionMethod) {
|
switch (compressionMethod) {
|
||||||
case CompressionMethod.Zstd:
|
case CompressionMethod.Zstd:
|
||||||
return [
|
return BSD_TAR_ZSTD
|
||||||
'--use-compress-program',
|
? [
|
||||||
IS_WINDOWS ? 'zstd -T0 --long=30' : 'zstdmt --long=30'
|
'&&',
|
||||||
]
|
'zstd -T0 --long=30 -o',
|
||||||
|
cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
|
tarFile
|
||||||
|
]
|
||||||
|
: [
|
||||||
|
'--use-compress-program',
|
||||||
|
IS_WINDOWS ? 'zstd -T0 --long=30' : 'zstdmt --long=30'
|
||||||
|
]
|
||||||
case CompressionMethod.ZstdWithoutLong:
|
case CompressionMethod.ZstdWithoutLong:
|
||||||
return ['--use-compress-program', IS_WINDOWS ? 'zstd -T0' : 'zstdmt']
|
return BSD_TAR_ZSTD
|
||||||
|
? [
|
||||||
|
'&&',
|
||||||
|
'zstd -T0 -o',
|
||||||
|
cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
|
tarFile
|
||||||
|
]
|
||||||
|
: ['--use-compress-program', IS_WINDOWS ? 'zstd -T0' : 'zstdmt']
|
||||||
default:
|
default:
|
||||||
return ['-z']
|
return ['-z']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const args = [
|
const tarArgs = await getTarArgs(compressionMethod, 'create')
|
||||||
'--posix',
|
const compressionArgs = getCompressionProgram()
|
||||||
...getCompressionProgram(),
|
const args = tarArgs.concat(compressionArgs)
|
||||||
'-cf',
|
await execTar(args, archiveFolder)
|
||||||
cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
|
||||||
'--exclude',
|
|
||||||
cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
|
||||||
'-P',
|
|
||||||
'-C',
|
|
||||||
workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
|
||||||
'--files-from',
|
|
||||||
manifestFilename
|
|
||||||
]
|
|
||||||
await execTar(args, compressionMethod, archiveFolder)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ARCHIVE_TOOL_GNU: string = 'gnu'
|
||||||
|
const ARCHIVE_TOOL_BSD: string = 'bsd'
|
||||||
|
|
||||||
|
const manifestFilename = 'manifest.txt'
|
||||||
|
|
||||||
|
export async function createTar2(
|
||||||
|
archiveFolder: string,
|
||||||
|
sourceDirectories: string[]
|
||||||
|
): Promise<void> {
|
||||||
|
|
||||||
|
// 1. decide the compression algo - zstd otherwise gzip
|
||||||
|
// 2. decide tar - gnutar otherwise bsdtar or systemtar
|
||||||
|
// 3. deide archiving/unarchiving args depending on tar
|
||||||
|
// 4. decide compression/decompression args depending on tar and compression
|
||||||
|
// 5. decide the exec command
|
||||||
|
|
||||||
|
let tar = getTarPath2()
|
||||||
|
let compression = getCompressionMethod2()
|
||||||
|
let args = argsMap.get({tar: tar, compression: compression, os: process.platform, "create"})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// return archive tool name and path
|
||||||
|
async function getTarPath2(): Promise<ArchiveTool> {
|
||||||
|
switch (process.platform) {
|
||||||
|
case 'win32': {
|
||||||
|
const gnuTar = await utils.getGnuTarPathOnWindows()
|
||||||
|
const systemTar = SystemTarPathOnWindows
|
||||||
|
if (gnuTar) {
|
||||||
|
// Use GNUtar as default on windows
|
||||||
|
return <ArchiveTool>{ name: ARCHIVE_TOOL_GNU, path: gnuTar }
|
||||||
|
} else if (existsSync(systemTar)) {
|
||||||
|
return <ArchiveTool>{name: ARCHIVE_TOOL_BSD, path: systemTar}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case 'darwin': {
|
||||||
|
const gnuTar = await io.which('gtar', false)
|
||||||
|
if (gnuTar) {
|
||||||
|
// fix permission denied errors when extracting BSD tar archive with GNU tar - https://github.com/actions/cache/issues/527
|
||||||
|
return <ArchiveTool>{ name: ARCHIVE_TOOL_GNU, path: gnuTar }
|
||||||
|
} else {
|
||||||
|
const path = await io.which('tar', true)
|
||||||
|
return <ArchiveTool>{name: ARCHIVE_TOOL_BSD, path: path}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
const path = await io.which('tar', true)
|
||||||
|
return <ArchiveTool>{name: ARCHIVE_TOOL_GNU, path: path}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use zstandard if possible to maximize cache performance
|
||||||
|
export async function getCompressionMethod2(): Promise<CompressionMethod> {
|
||||||
|
const versionOutput = await utils.getVersion('zstd')
|
||||||
|
const version = semver.clean(versionOutput)
|
||||||
|
|
||||||
|
if (!versionOutput.toLowerCase().includes('zstd command line interface')) {
|
||||||
|
// zstd is not installed
|
||||||
|
return CompressionMethod.Gzip
|
||||||
|
} else if (!version || semver.lt(version, 'v1.3.2')) {
|
||||||
|
// zstd is installed but using a version earlier than v1.3.2
|
||||||
|
// v1.3.2 is required to use the `--long` options in zstd
|
||||||
|
return CompressionMethod.ZstdWithoutLong
|
||||||
|
} else {
|
||||||
|
return CompressionMethod.Zstd
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ArchiveTool {
|
||||||
|
name: string
|
||||||
|
path: string
|
||||||
|
}
|
||||||
|
|
||||||
|
// tar, compression, os, operation -> tar args + compression args
|
||||||
|
const argsMap: Map<ArgsLookupKey, string[][]> = new Map()
|
||||||
|
argsMap.set({tar: ARCHIVE_TOOL_GNU, compression: CompressionMethod.Zstd, os: "windows", operation: "create"},
|
||||||
|
[[
|
||||||
|
'--posix',
|
||||||
|
'-cf',
|
||||||
|
'%%cacheFileName%%',
|
||||||
|
'--exclude',
|
||||||
|
'%%cacheFileName%%',
|
||||||
|
'-P',
|
||||||
|
'-C',
|
||||||
|
'%%workingDirectory%%',
|
||||||
|
'--files-from',
|
||||||
|
manifestFilename],
|
||||||
|
['--use-compress-program',
|
||||||
|
'zstd -T0 --long=30']
|
||||||
|
])
|
||||||
|
|
||||||
|
argsMap.set({tar: ARCHIVE_TOOL_GNU, compression: CompressionMethod.Zstd, os: "linux", operation: "create"},
|
||||||
|
[
|
||||||
|
'--use-compress-program',
|
||||||
|
'zstdmt --long=30'
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
interface ArgsLookupKey {
|
||||||
|
tar: string
|
||||||
|
compression: string
|
||||||
|
os: string
|
||||||
|
operation: string
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user