Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
44cd5d150b |
@@ -1,91 +0,0 @@
|
|||||||
name: cache-windows-bsd-unit-tests
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
paths-ignore:
|
|
||||||
- '**.md'
|
|
||||||
pull_request:
|
|
||||||
paths-ignore:
|
|
||||||
- '**.md'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
name: Build
|
|
||||||
|
|
||||||
runs-on: windows-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- shell: bash
|
|
||||||
run: |
|
|
||||||
rm "C:\Program Files\Git\usr\bin\tar.exe"
|
|
||||||
|
|
||||||
- name: Set Node.js 12.x
|
|
||||||
uses: actions/setup-node@v1
|
|
||||||
with:
|
|
||||||
node-version: 12.x
|
|
||||||
|
|
||||||
# In order to save & restore cache from a shell script, certain env variables need to be set that are only available in the
|
|
||||||
# node context. This runs a local action that gets and sets the necessary env variables that are needed
|
|
||||||
- name: Set env variables
|
|
||||||
uses: ./packages/cache/__tests__/__fixtures__/
|
|
||||||
|
|
||||||
# Need root node_modules because certain npm packages like jest are configured for the entire repository and it won't be possible
|
|
||||||
# without these to just compile the cache package
|
|
||||||
- name: Install root npm packages
|
|
||||||
run: npm ci
|
|
||||||
|
|
||||||
- name: Compile cache package
|
|
||||||
run: |
|
|
||||||
npm ci
|
|
||||||
npm run tsc
|
|
||||||
working-directory: packages/cache
|
|
||||||
|
|
||||||
- name: Generate files in working directory
|
|
||||||
shell: bash
|
|
||||||
run: packages/cache/__tests__/create-cache-files.sh ${{ runner.os }} test-cache
|
|
||||||
|
|
||||||
- name: Generate files outside working directory
|
|
||||||
shell: bash
|
|
||||||
run: packages/cache/__tests__/create-cache-files.sh ${{ runner.os }} ~/test-cache
|
|
||||||
|
|
||||||
# We're using node -e to call the functions directly available in the @actions/cache package
|
|
||||||
- name: Save cache using saveCache()
|
|
||||||
run: |
|
|
||||||
node -e "Promise.resolve(require('./packages/cache/lib/cache').saveCache(['test-cache','~/test-cache'],'test-${{ runner.os }}-${{ github.run_id }}'))"
|
|
||||||
|
|
||||||
- name: Delete cache folders before restoring
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
rm -rf test-cache
|
|
||||||
rm -rf ~/test-cache
|
|
||||||
|
|
||||||
- name: Restore cache using restoreCache() with http-client
|
|
||||||
run: |
|
|
||||||
node -e "Promise.resolve(require('./packages/cache/lib/cache').restoreCache(['test-cache','~/test-cache'],'test-${{ runner.os }}-${{ github.run_id }}',[],{useAzureSdk: false}))"
|
|
||||||
|
|
||||||
- name: Verify cache restored with http-client
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
packages/cache/__tests__/verify-cache-files.sh ${{ runner.os }} test-cache
|
|
||||||
packages/cache/__tests__/verify-cache-files.sh ${{ runner.os }} ~/test-cache
|
|
||||||
|
|
||||||
- name: Delete cache folders before restoring
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
rm -rf test-cache
|
|
||||||
rm -rf ~/test-cache
|
|
||||||
rm -f cache.tar
|
|
||||||
|
|
||||||
- name: Restore cache using restoreCache() with Azure SDK
|
|
||||||
run: |
|
|
||||||
node -e "Promise.resolve(require('./packages/cache/lib/cache').restoreCache(['test-cache','~/test-cache'],'test-${{ runner.os }}-${{ github.run_id }}'))"
|
|
||||||
|
|
||||||
- name: Verify cache restored with Azure SDK
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
packages/cache/__tests__/verify-cache-files.sh ${{ runner.os }} test-cache
|
|
||||||
packages/cache/__tests__/verify-cache-files.sh ${{ runner.os }} ~/test-cache
|
|
||||||
Vendored
-3
@@ -91,6 +91,3 @@
|
|||||||
|
|
||||||
### 3.0.6
|
### 3.0.6
|
||||||
- Added `@azure/abort-controller` to dependencies to fix compatibility issue with ESM [#1208](https://github.com/actions/toolkit/issues/1208)
|
- Added `@azure/abort-controller` to dependencies to fix compatibility issue with ESM [#1208](https://github.com/actions/toolkit/issues/1208)
|
||||||
|
|
||||||
### 3.1.0-beta.1
|
|
||||||
- Update actions/cache on windows to use gnu tar and zstd by default and fallback to bsdtar and zstd if gnu tar is not available. ([issue](https://github.com/actions/cache/issues/984))
|
|
||||||
-75
@@ -161,81 +161,6 @@ test('restore with gzip compressed cache found', async () => {
|
|||||||
expect(getCompressionMock).toHaveBeenCalledTimes(1)
|
expect(getCompressionMock).toHaveBeenCalledTimes(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('restore with zstd as default but gzip compressed cache found on windows', async () => {
|
|
||||||
if (process.platform === 'win32') {
|
|
||||||
const paths = ['node_modules']
|
|
||||||
const key = 'node-test'
|
|
||||||
|
|
||||||
const cacheEntry: ArtifactCacheEntry = {
|
|
||||||
cacheKey: key,
|
|
||||||
scope: 'refs/heads/main',
|
|
||||||
archiveLocation: 'www.actionscache.test/download'
|
|
||||||
}
|
|
||||||
const getCacheMock = jest.spyOn(cacheHttpClient, 'getCacheEntry')
|
|
||||||
getCacheMock
|
|
||||||
.mockImplementationOnce(async () => {
|
|
||||||
return Promise.resolve(null)
|
|
||||||
})
|
|
||||||
.mockImplementationOnce(async () => {
|
|
||||||
return Promise.resolve(cacheEntry)
|
|
||||||
})
|
|
||||||
|
|
||||||
const tempPath = '/foo/bar'
|
|
||||||
|
|
||||||
const createTempDirectoryMock = jest.spyOn(
|
|
||||||
cacheUtils,
|
|
||||||
'createTempDirectory'
|
|
||||||
)
|
|
||||||
createTempDirectoryMock.mockImplementation(async () => {
|
|
||||||
return Promise.resolve(tempPath)
|
|
||||||
})
|
|
||||||
|
|
||||||
const archivePath = path.join(tempPath, CacheFilename.Gzip)
|
|
||||||
const downloadCacheMock = jest.spyOn(cacheHttpClient, 'downloadCache')
|
|
||||||
|
|
||||||
const fileSize = 142
|
|
||||||
const getArchiveFileSizeInBytesMock = jest
|
|
||||||
.spyOn(cacheUtils, 'getArchiveFileSizeInBytes')
|
|
||||||
.mockReturnValue(fileSize)
|
|
||||||
|
|
||||||
const extractTarMock = jest.spyOn(tar, 'extractTar')
|
|
||||||
const unlinkFileMock = jest.spyOn(cacheUtils, 'unlinkFile')
|
|
||||||
|
|
||||||
const compression = CompressionMethod.Zstd
|
|
||||||
const getCompressionMock = jest
|
|
||||||
.spyOn(cacheUtils, 'getCompressionMethod')
|
|
||||||
.mockReturnValue(Promise.resolve(compression))
|
|
||||||
|
|
||||||
const cacheKey = await restoreCache(paths, key)
|
|
||||||
|
|
||||||
expect(cacheKey).toBe(key)
|
|
||||||
expect(getCacheMock).toHaveBeenNthCalledWith(1, [key], paths, {
|
|
||||||
compressionMethod: compression
|
|
||||||
})
|
|
||||||
expect(getCacheMock).toHaveBeenNthCalledWith(2, [key], paths, {
|
|
||||||
compressionMethod: CompressionMethod.Gzip
|
|
||||||
})
|
|
||||||
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1)
|
|
||||||
expect(downloadCacheMock).toHaveBeenCalledWith(
|
|
||||||
cacheEntry.archiveLocation,
|
|
||||||
archivePath,
|
|
||||||
undefined
|
|
||||||
)
|
|
||||||
expect(getArchiveFileSizeInBytesMock).toHaveBeenCalledWith(archivePath)
|
|
||||||
|
|
||||||
expect(extractTarMock).toHaveBeenCalledTimes(1)
|
|
||||||
expect(extractTarMock).toHaveBeenCalledWith(
|
|
||||||
archivePath,
|
|
||||||
CompressionMethod.Gzip
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(unlinkFileMock).toHaveBeenCalledTimes(1)
|
|
||||||
expect(unlinkFileMock).toHaveBeenCalledWith(archivePath)
|
|
||||||
|
|
||||||
expect(getCompressionMock).toHaveBeenCalledTimes(1)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
test('restore with zstd compressed cache found', async () => {
|
test('restore with zstd compressed cache found', async () => {
|
||||||
const paths = ['node_modules']
|
const paths = ['node_modules']
|
||||||
const key = 'node-test'
|
const key = 'node-test'
|
||||||
|
|||||||
Vendored
+55
-113
@@ -5,9 +5,7 @@ import {
|
|||||||
CacheFilename,
|
CacheFilename,
|
||||||
CompressionMethod,
|
CompressionMethod,
|
||||||
GnuTarPathOnWindows,
|
GnuTarPathOnWindows,
|
||||||
ManifestFilename,
|
SystemTarPathOnWindows
|
||||||
SystemTarPathOnWindows,
|
|
||||||
TarFilename
|
|
||||||
} from '../src/internal/constants'
|
} 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'
|
||||||
@@ -59,8 +57,8 @@ test('zstd extract tar', async () => {
|
|||||||
expect(mkdirMock).toHaveBeenCalledWith(workspace)
|
expect(mkdirMock).toHaveBeenCalledWith(workspace)
|
||||||
expect(execMock).toHaveBeenCalledTimes(1)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
expect(execMock).toHaveBeenCalledWith(
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
|
`"${tarPath}"`,
|
||||||
[
|
[
|
||||||
`"${tarPath}"`,
|
|
||||||
'-xf',
|
'-xf',
|
||||||
IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath,
|
IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath,
|
||||||
'-P',
|
'-P',
|
||||||
@@ -71,10 +69,8 @@ test('zstd extract tar', async () => {
|
|||||||
.concat(IS_MAC ? ['--delay-directory-restore'] : [])
|
.concat(IS_MAC ? ['--delay-directory-restore'] : [])
|
||||||
.concat([
|
.concat([
|
||||||
'--use-compress-program',
|
'--use-compress-program',
|
||||||
IS_WINDOWS ? '"zstd -d --long=30"' : 'unzstd --long=30'
|
IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30'
|
||||||
])
|
]),
|
||||||
.join(' '),
|
|
||||||
undefined,
|
|
||||||
{cwd: undefined}
|
{cwd: undefined}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -90,34 +86,25 @@ test('zstd extract tar with windows BSDtar', async () => {
|
|||||||
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']
|
||||||
const tarPath = SystemTarPathOnWindows
|
const tarPath = SystemTarPathOnWindows
|
||||||
|
const tarFilename = 'cache.tar'
|
||||||
|
|
||||||
await tar.extractTar(archivePath, CompressionMethod.Zstd)
|
await tar.extractTar(archivePath, CompressionMethod.Zstd)
|
||||||
|
|
||||||
expect(mkdirMock).toHaveBeenCalledWith(workspace)
|
expect(mkdirMock).toHaveBeenCalledWith(workspace)
|
||||||
expect(execMock).toHaveBeenCalledTimes(2)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
expect(execMock).toHaveBeenNthCalledWith(
|
'zstd -d --long=30 -o',
|
||||||
1,
|
|
||||||
[
|
[
|
||||||
'zstd -d --long=30 -o',
|
tarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
TarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/')
|
'&&',
|
||||||
].join(' '),
|
`${tarPath}`,
|
||||||
undefined,
|
|
||||||
{cwd: undefined}
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(execMock).toHaveBeenNthCalledWith(
|
|
||||||
2,
|
|
||||||
[
|
|
||||||
`"${tarPath}"`,
|
|
||||||
'-xf',
|
'-xf',
|
||||||
TarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
tarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
'-P',
|
'-P',
|
||||||
'-C',
|
'-C',
|
||||||
workspace?.replace(/\\/g, '/')
|
workspace?.replace(/\\/g, '/')
|
||||||
].join(' '),
|
],
|
||||||
undefined,
|
|
||||||
{cwd: undefined}
|
{cwd: undefined}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -137,8 +124,8 @@ test('gzip extract tar', async () => {
|
|||||||
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
||||||
expect(execMock).toHaveBeenCalledTimes(1)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
expect(execMock).toHaveBeenCalledWith(
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
|
`"${tarPath}"`,
|
||||||
[
|
[
|
||||||
`"${tarPath}"`,
|
|
||||||
'-xf',
|
'-xf',
|
||||||
IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath,
|
IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath,
|
||||||
'-P',
|
'-P',
|
||||||
@@ -147,9 +134,7 @@ test('gzip extract tar', async () => {
|
|||||||
]
|
]
|
||||||
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
||||||
.concat(IS_MAC ? ['--delay-directory-restore'] : [])
|
.concat(IS_MAC ? ['--delay-directory-restore'] : [])
|
||||||
.concat(['-z'])
|
.concat(['-z']),
|
||||||
.join(' '),
|
|
||||||
undefined,
|
|
||||||
{cwd: undefined}
|
{cwd: undefined}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -168,8 +153,8 @@ test('gzip extract GNU tar on windows with GNUtar in path', async () => {
|
|||||||
|
|
||||||
expect(execMock).toHaveBeenCalledTimes(1)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
expect(execMock).toHaveBeenCalledWith(
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
|
`"tar"`,
|
||||||
[
|
[
|
||||||
`"tar"`,
|
|
||||||
'-xf',
|
'-xf',
|
||||||
archivePath.replace(/\\/g, '/'),
|
archivePath.replace(/\\/g, '/'),
|
||||||
'-P',
|
'-P',
|
||||||
@@ -177,8 +162,7 @@ test('gzip extract GNU tar on windows with GNUtar in path', async () => {
|
|||||||
workspace?.replace(/\\/g, '/'),
|
workspace?.replace(/\\/g, '/'),
|
||||||
'--force-local',
|
'--force-local',
|
||||||
'-z'
|
'-z'
|
||||||
].join(' '),
|
],
|
||||||
undefined,
|
|
||||||
{cwd: undefined}
|
{cwd: undefined}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -199,8 +183,8 @@ test('zstd create tar', async () => {
|
|||||||
|
|
||||||
expect(execMock).toHaveBeenCalledTimes(1)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
expect(execMock).toHaveBeenCalledWith(
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
|
`"${tarPath}"`,
|
||||||
[
|
[
|
||||||
`"${tarPath}"`,
|
|
||||||
'--posix',
|
'--posix',
|
||||||
'-cf',
|
'-cf',
|
||||||
IS_WINDOWS ? CacheFilename.Zstd.replace(/\\/g, '/') : CacheFilename.Zstd,
|
IS_WINDOWS ? CacheFilename.Zstd.replace(/\\/g, '/') : CacheFilename.Zstd,
|
||||||
@@ -210,16 +194,14 @@ test('zstd create tar', async () => {
|
|||||||
'-C',
|
'-C',
|
||||||
IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace,
|
IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace,
|
||||||
'--files-from',
|
'--files-from',
|
||||||
ManifestFilename
|
'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([
|
.concat([
|
||||||
'--use-compress-program',
|
'--use-compress-program',
|
||||||
IS_WINDOWS ? '"zstd -T0 --long=30"' : 'zstdmt --long=30'
|
IS_WINDOWS ? 'zstd -T0 --long=30' : 'zstdmt --long=30'
|
||||||
])
|
]),
|
||||||
.join(' '),
|
|
||||||
undefined, // args
|
|
||||||
{
|
{
|
||||||
cwd: archiveFolder
|
cwd: archiveFolder
|
||||||
}
|
}
|
||||||
@@ -236,6 +218,7 @@ test('zstd create tar with windows BSDtar', async () => {
|
|||||||
const archiveFolder = getTempDir()
|
const archiveFolder = getTempDir()
|
||||||
const workspace = process.env['GITHUB_WORKSPACE']
|
const workspace = process.env['GITHUB_WORKSPACE']
|
||||||
const sourceDirectories = ['~/.npm/cache', `${workspace}/dist`]
|
const sourceDirectories = ['~/.npm/cache', `${workspace}/dist`]
|
||||||
|
const tarFilename = 'cache.tar'
|
||||||
|
|
||||||
await fs.promises.mkdir(archiveFolder, {recursive: true})
|
await fs.promises.mkdir(archiveFolder, {recursive: true})
|
||||||
|
|
||||||
@@ -247,37 +230,25 @@ test('zstd create tar with windows BSDtar', async () => {
|
|||||||
|
|
||||||
const tarPath = SystemTarPathOnWindows
|
const tarPath = SystemTarPathOnWindows
|
||||||
|
|
||||||
expect(execMock).toHaveBeenCalledTimes(2)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
expect(execMock).toHaveBeenNthCalledWith(
|
`"${tarPath}"`,
|
||||||
1,
|
|
||||||
[
|
[
|
||||||
`"${tarPath}"`,
|
|
||||||
'--posix',
|
'--posix',
|
||||||
'-cf',
|
'-cf',
|
||||||
TarFilename.replace(/\\/g, '/'),
|
tarFilename.replace(/\\/g, '/'),
|
||||||
'--exclude',
|
'--exclude',
|
||||||
TarFilename.replace(/\\/g, '/'),
|
tarFilename.replace(/\\/g, '/'),
|
||||||
'-P',
|
'-P',
|
||||||
'-C',
|
'-C',
|
||||||
workspace?.replace(/\\/g, '/'),
|
workspace?.replace(/\\/g, '/'),
|
||||||
'--files-from',
|
'--files-from',
|
||||||
ManifestFilename
|
'manifest.txt',
|
||||||
].join(' '),
|
'&&',
|
||||||
undefined, // args
|
|
||||||
{
|
|
||||||
cwd: archiveFolder
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(execMock).toHaveBeenNthCalledWith(
|
|
||||||
2,
|
|
||||||
[
|
|
||||||
'zstd -T0 --long=30 -o',
|
'zstd -T0 --long=30 -o',
|
||||||
CacheFilename.Zstd.replace(/\\/g, '/'),
|
CacheFilename.Zstd.replace(/\\/g, '/'),
|
||||||
TarFilename.replace(/\\/g, '/')
|
tarFilename.replace(/\\/g, '/')
|
||||||
].join(' '),
|
],
|
||||||
undefined, // args
|
|
||||||
{
|
{
|
||||||
cwd: archiveFolder
|
cwd: archiveFolder
|
||||||
}
|
}
|
||||||
@@ -300,8 +271,8 @@ test('gzip create tar', async () => {
|
|||||||
|
|
||||||
expect(execMock).toHaveBeenCalledTimes(1)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
expect(execMock).toHaveBeenCalledWith(
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
|
`"${tarPath}"`,
|
||||||
[
|
[
|
||||||
`"${tarPath}"`,
|
|
||||||
'--posix',
|
'--posix',
|
||||||
'-cf',
|
'-cf',
|
||||||
IS_WINDOWS ? CacheFilename.Gzip.replace(/\\/g, '/') : CacheFilename.Gzip,
|
IS_WINDOWS ? CacheFilename.Gzip.replace(/\\/g, '/') : CacheFilename.Gzip,
|
||||||
@@ -311,13 +282,11 @@ test('gzip create tar', async () => {
|
|||||||
'-C',
|
'-C',
|
||||||
IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace,
|
IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace,
|
||||||
'--files-from',
|
'--files-from',
|
||||||
ManifestFilename
|
'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(['-z'])
|
.concat(['-z']),
|
||||||
.join(' '),
|
|
||||||
undefined, // args
|
|
||||||
{
|
{
|
||||||
cwd: archiveFolder
|
cwd: archiveFolder
|
||||||
}
|
}
|
||||||
@@ -336,20 +305,14 @@ test('zstd list tar', async () => {
|
|||||||
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : 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']
|
||||||
'-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([
|
.concat([
|
||||||
'--use-compress-program',
|
'--use-compress-program',
|
||||||
IS_WINDOWS ? '"zstd -d --long=30"' : 'unzstd --long=30'
|
IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30'
|
||||||
])
|
]),
|
||||||
.join(' '),
|
|
||||||
undefined,
|
|
||||||
{cwd: undefined}
|
{cwd: undefined}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -364,29 +327,20 @@ test('zstd list tar with windows BSDtar', async () => {
|
|||||||
|
|
||||||
await tar.listTar(archivePath, CompressionMethod.Zstd)
|
await tar.listTar(archivePath, CompressionMethod.Zstd)
|
||||||
|
|
||||||
|
const tarFilename = 'cache.tar'
|
||||||
const tarPath = SystemTarPathOnWindows
|
const tarPath = SystemTarPathOnWindows
|
||||||
expect(execMock).toHaveBeenCalledTimes(2)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
expect(execMock).toHaveBeenNthCalledWith(
|
'zstd -d --long=30 -o',
|
||||||
1,
|
|
||||||
[
|
[
|
||||||
'zstd -d --long=30 -o',
|
tarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
TarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/')
|
'&&',
|
||||||
].join(' '),
|
`${tarPath}`,
|
||||||
undefined,
|
|
||||||
{cwd: undefined}
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(execMock).toHaveBeenNthCalledWith(
|
|
||||||
2,
|
|
||||||
[
|
|
||||||
`"${tarPath}"`,
|
|
||||||
'-tf',
|
'-tf',
|
||||||
TarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
tarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
'-P'
|
'-P'
|
||||||
].join(' '),
|
],
|
||||||
undefined,
|
|
||||||
{cwd: undefined}
|
{cwd: undefined}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -404,17 +358,11 @@ test('zstdWithoutLong list tar', async () => {
|
|||||||
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : 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']
|
||||||
'-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'])
|
.concat(['--use-compress-program', IS_WINDOWS ? 'zstd -d' : 'unzstd']),
|
||||||
.join(' '),
|
|
||||||
undefined,
|
|
||||||
{cwd: undefined}
|
{cwd: undefined}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -430,17 +378,11 @@ test('gzip list tar', async () => {
|
|||||||
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : 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']
|
||||||
'-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(['-z'])
|
.concat(['-z']),
|
||||||
.join(' '),
|
|
||||||
undefined,
|
|
||||||
{cwd: undefined}
|
{cwd: undefined}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
+8
-8
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@actions/cache",
|
"name": "@actions/cache",
|
||||||
"version": "3.1.0-beta.1",
|
"version": "3.0.6",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@actions/cache",
|
"name": "@actions/cache",
|
||||||
"version": "3.1.0-beta.1",
|
"version": "3.0.6",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.0",
|
"@actions/core": "^1.10.0",
|
||||||
@@ -457,9 +457,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/minimatch": {
|
"node_modules/minimatch": {
|
||||||
"version": "3.1.2",
|
"version": "3.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
|
||||||
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
|
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"brace-expansion": "^1.1.7"
|
"brace-expansion": "^1.1.7"
|
||||||
},
|
},
|
||||||
@@ -998,9 +998,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"minimatch": {
|
"minimatch": {
|
||||||
"version": "3.1.2",
|
"version": "3.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
|
||||||
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
|
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"brace-expansion": "^1.1.7"
|
"brace-expansion": "^1.1.7"
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@actions/cache",
|
"name": "@actions/cache",
|
||||||
"version": "3.1.0-beta.1",
|
"version": "3.0.6",
|
||||||
"preview": true,
|
"preview": true,
|
||||||
"description": "Actions cache lib",
|
"description": "Actions cache lib",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|||||||
Vendored
+5
-25
@@ -4,8 +4,6 @@ import * as utils from './internal/cacheUtils'
|
|||||||
import * as cacheHttpClient from './internal/cacheHttpClient'
|
import * as cacheHttpClient from './internal/cacheHttpClient'
|
||||||
import {createTar, extractTar, listTar} from './internal/tar'
|
import {createTar, extractTar, listTar} from './internal/tar'
|
||||||
import {DownloadOptions, UploadOptions} from './options'
|
import {DownloadOptions, UploadOptions} from './options'
|
||||||
import {CompressionMethod} from './internal/constants'
|
|
||||||
import {ArtifactCacheEntry} from './internal/contracts'
|
|
||||||
|
|
||||||
export class ValidationError extends Error {
|
export class ValidationError extends Error {
|
||||||
constructor(message: string) {
|
constructor(message: string) {
|
||||||
@@ -87,35 +85,17 @@ export async function restoreCache(
|
|||||||
checkKey(key)
|
checkKey(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
let cacheEntry: ArtifactCacheEntry | null
|
const compressionMethod = await utils.getCompressionMethod()
|
||||||
let compressionMethod = await utils.getCompressionMethod()
|
|
||||||
let archivePath = ''
|
let archivePath = ''
|
||||||
try {
|
try {
|
||||||
// path are needed to compute version
|
// path are needed to compute version
|
||||||
cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, {
|
const cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, {
|
||||||
compressionMethod
|
compressionMethod
|
||||||
})
|
})
|
||||||
if (!cacheEntry?.archiveLocation) {
|
|
||||||
// This is to support the old cache entry created by gzip on windows.
|
|
||||||
if (
|
|
||||||
process.platform === 'win32' &&
|
|
||||||
compressionMethod !== CompressionMethod.Gzip
|
|
||||||
) {
|
|
||||||
compressionMethod = CompressionMethod.Gzip
|
|
||||||
cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, {
|
|
||||||
compressionMethod
|
|
||||||
})
|
|
||||||
if (!cacheEntry?.archiveLocation) {
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
core.debug(
|
if (!cacheEntry?.archiveLocation) {
|
||||||
"Couldn't find cache entry with zstd compression, falling back to gzip compression."
|
// Cache not found
|
||||||
)
|
return undefined
|
||||||
} else {
|
|
||||||
// Cache not found
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
archivePath = path.join(
|
archivePath = path.join(
|
||||||
|
|||||||
@@ -104,7 +104,6 @@ export async function getCacheEntry(
|
|||||||
httpClient.getJson<ArtifactCacheEntry>(getCacheApiUrl(resource))
|
httpClient.getJson<ArtifactCacheEntry>(getCacheApiUrl(resource))
|
||||||
)
|
)
|
||||||
if (response.statusCode === 204) {
|
if (response.statusCode === 204) {
|
||||||
// Cache not found
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
if (!isSuccessStatusCode(response.statusCode)) {
|
if (!isSuccessStatusCode(response.statusCode)) {
|
||||||
@@ -114,7 +113,6 @@ export async function getCacheEntry(
|
|||||||
const cacheResult = response.result
|
const cacheResult = response.result
|
||||||
const cacheDownloadUrl = cacheResult?.archiveLocation
|
const cacheDownloadUrl = cacheResult?.archiveLocation
|
||||||
if (!cacheDownloadUrl) {
|
if (!cacheDownloadUrl) {
|
||||||
// Cache achiveLocation not found. This should never happen, and hence bail out.
|
|
||||||
throw new Error('Cache not found.')
|
throw new Error('Cache not found.')
|
||||||
}
|
}
|
||||||
core.setSecret(cacheDownloadUrl)
|
core.setSecret(cacheDownloadUrl)
|
||||||
|
|||||||
+1
-1
@@ -71,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 {
|
||||||
|
|||||||
-10
@@ -11,11 +11,6 @@ export enum CompressionMethod {
|
|||||||
Zstd = 'zstd'
|
Zstd = 'zstd'
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum ArchiveToolType {
|
|
||||||
GNU = 'gnu',
|
|
||||||
BSD = 'bsd'
|
|
||||||
}
|
|
||||||
|
|
||||||
// The default number of retry attempts.
|
// The default number of retry attempts.
|
||||||
export const DefaultRetryAttempts = 2
|
export const DefaultRetryAttempts = 2
|
||||||
|
|
||||||
@@ -30,9 +25,4 @@ export const SocketTimeout = 5000
|
|||||||
// The default path of GNUtar on hosted Windows runners
|
// The default path of GNUtar on hosted Windows runners
|
||||||
export const GnuTarPathOnWindows = `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe`
|
export const GnuTarPathOnWindows = `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe`
|
||||||
|
|
||||||
// The default path of BSDtar on hosted Windows runners
|
|
||||||
export const SystemTarPathOnWindows = `${process.env['SYSTEMDRIVE']}\\Windows\\System32\\tar.exe`
|
export const SystemTarPathOnWindows = `${process.env['SYSTEMDRIVE']}\\Windows\\System32\\tar.exe`
|
||||||
|
|
||||||
export const TarFilename = 'cache.tar'
|
|
||||||
|
|
||||||
export const ManifestFilename = 'manifest.txt'
|
|
||||||
|
|||||||
-5
@@ -31,8 +31,3 @@ export interface InternalCacheOptions {
|
|||||||
compressionMethod?: CompressionMethod
|
compressionMethod?: CompressionMethod
|
||||||
cacheSize?: number
|
cacheSize?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ArchiveTool {
|
|
||||||
path: string
|
|
||||||
type: string
|
|
||||||
}
|
|
||||||
|
|||||||
Vendored
+255
-143
@@ -3,28 +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 {ArchiveTool} from './contracts'
|
import {CompressionMethod, SystemTarPathOnWindows} from './constants'
|
||||||
import {
|
|
||||||
CompressionMethod,
|
|
||||||
SystemTarPathOnWindows,
|
|
||||||
ArchiveToolType,
|
|
||||||
TarFilename,
|
|
||||||
ManifestFilename
|
|
||||||
} from './constants'
|
|
||||||
|
|
||||||
const IS_WINDOWS = process.platform === 'win32'
|
const IS_WINDOWS = process.platform === 'win32'
|
||||||
|
|
||||||
// Returns tar path and type: BSD or GNU
|
// Function also mutates the args array. For non-mutation call with passing an empty array.
|
||||||
async function getTarPath(): Promise<ArchiveTool> {
|
async function getTarPath(): Promise<string> {
|
||||||
switch (process.platform) {
|
switch (process.platform) {
|
||||||
case 'win32': {
|
case 'win32': {
|
||||||
const gnuTar = await utils.getGnuTarPathOnWindows()
|
const gnuTar = await utils.getGnuTarPathOnWindows()
|
||||||
const systemTar = SystemTarPathOnWindows
|
const systemTar = SystemTarPathOnWindows
|
||||||
if (gnuTar) {
|
if (gnuTar) {
|
||||||
// Use GNUtar as default on windows
|
// Use GNUtar as default on windows
|
||||||
return <ArchiveTool>{path: gnuTar, type: ArchiveToolType.GNU}
|
return gnuTar
|
||||||
} else if (existsSync(systemTar)) {
|
} else if (existsSync(systemTar)) {
|
||||||
return <ArchiveTool>{path: systemTar, type: ArchiveToolType.BSD}
|
return systemTar
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -32,40 +25,30 @@ async function getTarPath(): Promise<ArchiveTool> {
|
|||||||
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
|
||||||
return <ArchiveTool>{path: gnuTar, type: ArchiveToolType.GNU}
|
return gnuTar
|
||||||
} else {
|
|
||||||
return <ArchiveTool>{
|
|
||||||
path: await io.which('tar', true),
|
|
||||||
type: ArchiveToolType.BSD
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
// Default assumption is GNU tar is present in path
|
return await io.which('tar', true)
|
||||||
return <ArchiveTool>{
|
|
||||||
path: await io.which('tar', true),
|
|
||||||
type: ArchiveToolType.GNU
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return arguments for tar as per tarPath, compressionMethod, method type and os
|
|
||||||
async function getTarArgs(
|
async function getTarArgs(
|
||||||
tarPath: ArchiveTool,
|
|
||||||
compressionMethod: CompressionMethod,
|
compressionMethod: CompressionMethod,
|
||||||
type: string,
|
type: string,
|
||||||
archivePath = ''
|
archivePath = ''
|
||||||
): Promise<string[]> {
|
): Promise<string[]> {
|
||||||
const args = [`"${tarPath.path}"`]
|
const args = []
|
||||||
|
const manifestFilename = 'manifest.txt'
|
||||||
const cacheFileName = utils.getCacheFileName(compressionMethod)
|
const cacheFileName = utils.getCacheFileName(compressionMethod)
|
||||||
const tarFile = 'cache.tar'
|
const tarFile = 'cache.tar'
|
||||||
|
const tarPath = await getTarPath()
|
||||||
const workingDirectory = getWorkingDirectory()
|
const workingDirectory = getWorkingDirectory()
|
||||||
// Speficic args for BSD tar on windows for workaround
|
|
||||||
const BSD_TAR_ZSTD =
|
const BSD_TAR_ZSTD =
|
||||||
tarPath.type === ArchiveToolType.BSD &&
|
tarPath === SystemTarPathOnWindows &&
|
||||||
compressionMethod !== CompressionMethod.Gzip &&
|
compressionMethod !== CompressionMethod.Gzip
|
||||||
IS_WINDOWS
|
|
||||||
|
|
||||||
// Method specific args
|
// Method specific args
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -84,7 +67,7 @@ async function getTarArgs(
|
|||||||
'-C',
|
'-C',
|
||||||
workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
'--files-from',
|
'--files-from',
|
||||||
ManifestFilename
|
manifestFilename
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
case 'extract':
|
case 'extract':
|
||||||
@@ -110,55 +93,46 @@ async function getTarArgs(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Platform specific args
|
// Platform specific args
|
||||||
if (tarPath.type === ArchiveToolType.GNU) {
|
switch (process.platform) {
|
||||||
switch (process.platform) {
|
case 'win32': {
|
||||||
case 'win32':
|
const gnuTar = await utils.getGnuTarPathOnWindows()
|
||||||
|
if (gnuTar) {
|
||||||
|
// Use GNUtar as default on windows
|
||||||
args.push('--force-local')
|
args.push('--force-local')
|
||||||
break
|
}
|
||||||
case 'darwin':
|
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')
|
args.push('--delay-directory-restore')
|
||||||
break
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns commands to run tar and compression program
|
async function execTar(args: string[], cwd?: string): Promise<void> {
|
||||||
async function getCommands(
|
try {
|
||||||
compressionMethod: CompressionMethod,
|
await exec(`"${await getTarPath()}"`, args, {cwd})
|
||||||
type: string,
|
} catch (error) {
|
||||||
archivePath = ''
|
throw new Error(`Tar failed with error: ${error?.message}`)
|
||||||
): Promise<string[]> {
|
|
||||||
let args
|
|
||||||
|
|
||||||
const tarPath = await getTarPath()
|
|
||||||
const tarArgs = await getTarArgs(
|
|
||||||
tarPath,
|
|
||||||
compressionMethod,
|
|
||||||
type,
|
|
||||||
archivePath
|
|
||||||
)
|
|
||||||
const compressionArgs =
|
|
||||||
type !== 'create'
|
|
||||||
? await getDecompressionProgram(tarPath, compressionMethod, archivePath)
|
|
||||||
: await getCompressionProgram(tarPath, compressionMethod)
|
|
||||||
const BSD_TAR_ZSTD =
|
|
||||||
tarPath.type === ArchiveToolType.BSD &&
|
|
||||||
compressionMethod !== CompressionMethod.Gzip &&
|
|
||||||
IS_WINDOWS
|
|
||||||
|
|
||||||
if (BSD_TAR_ZSTD && type !== 'create') {
|
|
||||||
args = [[...compressionArgs].join(' '), [...tarArgs].join(' ')]
|
|
||||||
} else {
|
|
||||||
args = [[...tarArgs].join(' '), [...compressionArgs].join(' ')]
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (BSD_TAR_ZSTD) {
|
async function execCommand(
|
||||||
return args
|
command: string,
|
||||||
|
args: string[],
|
||||||
|
cwd?: string
|
||||||
|
): Promise<void> {
|
||||||
|
try {
|
||||||
|
await exec(command, args, {cwd})
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(`Tar failed with error: ${error?.message}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return [args.join(' ')]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWorkingDirectory(): string {
|
function getWorkingDirectory(): string {
|
||||||
@@ -166,8 +140,7 @@ 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
|
||||||
async function getDecompressionProgram(
|
async function getCompressionProgram(
|
||||||
tarPath: ArchiveTool,
|
|
||||||
compressionMethod: CompressionMethod,
|
compressionMethod: CompressionMethod,
|
||||||
archivePath: string
|
archivePath: string
|
||||||
): Promise<string[]> {
|
): Promise<string[]> {
|
||||||
@@ -175,120 +148,259 @@ async function getDecompressionProgram(
|
|||||||
// 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 =
|
const BSD_TAR_ZSTD =
|
||||||
tarPath.type === ArchiveToolType.BSD &&
|
tarPath === SystemTarPathOnWindows &&
|
||||||
compressionMethod !== CompressionMethod.Gzip &&
|
compressionMethod !== CompressionMethod.Gzip
|
||||||
IS_WINDOWS
|
|
||||||
switch (compressionMethod) {
|
switch (compressionMethod) {
|
||||||
case CompressionMethod.Zstd:
|
case CompressionMethod.Zstd:
|
||||||
return BSD_TAR_ZSTD
|
return BSD_TAR_ZSTD
|
||||||
? [
|
? [
|
||||||
'zstd -d --long=30 -o',
|
'zstd -d --long=30 -o',
|
||||||
TarFilename,
|
tarFile,
|
||||||
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/')
|
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
|
'&&'
|
||||||
]
|
]
|
||||||
: [
|
: [
|
||||||
'--use-compress-program',
|
'--use-compress-program',
|
||||||
IS_WINDOWS ? '"zstd -d --long=30"' : 'unzstd --long=30'
|
IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30'
|
||||||
]
|
]
|
||||||
case CompressionMethod.ZstdWithoutLong:
|
case CompressionMethod.ZstdWithoutLong:
|
||||||
return BSD_TAR_ZSTD
|
return BSD_TAR_ZSTD
|
||||||
? [
|
? [
|
||||||
'zstd -d -o',
|
'zstd -d -o',
|
||||||
TarFilename,
|
tarFile,
|
||||||
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/')
|
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
|
'&&'
|
||||||
]
|
]
|
||||||
: ['--use-compress-program', IS_WINDOWS ? '"zstd -d"' : 'unzstd']
|
: ['--use-compress-program', IS_WINDOWS ? 'zstd -d' : 'unzstd']
|
||||||
default:
|
default:
|
||||||
return ['-z']
|
return ['-z']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used for creating the archive
|
|
||||||
// -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'
|
|
||||||
// --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.
|
|
||||||
// Long range mode is added to zstd in v1.3.2 release, so we will not use --long in older version of zstd.
|
|
||||||
async function getCompressionProgram(
|
|
||||||
tarPath: ArchiveTool,
|
|
||||||
compressionMethod: CompressionMethod
|
|
||||||
): Promise<string[]> {
|
|
||||||
const cacheFileName = utils.getCacheFileName(compressionMethod)
|
|
||||||
const BSD_TAR_ZSTD =
|
|
||||||
tarPath.type === ArchiveToolType.BSD &&
|
|
||||||
compressionMethod !== CompressionMethod.Gzip &&
|
|
||||||
IS_WINDOWS
|
|
||||||
switch (compressionMethod) {
|
|
||||||
case CompressionMethod.Zstd:
|
|
||||||
return BSD_TAR_ZSTD
|
|
||||||
? [
|
|
||||||
'zstd -T0 --long=30 -o',
|
|
||||||
cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
|
||||||
TarFilename
|
|
||||||
]
|
|
||||||
: [
|
|
||||||
'--use-compress-program',
|
|
||||||
IS_WINDOWS ? '"zstd -T0 --long=30"' : 'zstdmt --long=30'
|
|
||||||
]
|
|
||||||
case CompressionMethod.ZstdWithoutLong:
|
|
||||||
return BSD_TAR_ZSTD
|
|
||||||
? [
|
|
||||||
'zstd -T0 -o',
|
|
||||||
cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
|
||||||
TarFilename
|
|
||||||
]
|
|
||||||
: ['--use-compress-program', IS_WINDOWS ? '"zstd -T0"' : 'zstdmt']
|
|
||||||
default:
|
|
||||||
return ['-z']
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Executes all commands as separate processes
|
|
||||||
async function execCommands(commands: string[], cwd?: string): Promise<void> {
|
|
||||||
for (const command of commands) {
|
|
||||||
try {
|
|
||||||
await exec(command, undefined, {cwd})
|
|
||||||
} catch (error) {
|
|
||||||
throw new Error(
|
|
||||||
`${command.split(' ')[0]} failed with error: ${error?.message}`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// List the contents of a tar
|
|
||||||
export async function listTar(
|
export async function listTar(
|
||||||
archivePath: string,
|
archivePath: string,
|
||||||
compressionMethod: CompressionMethod
|
compressionMethod: CompressionMethod
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const commands = await getCommands(compressionMethod, 'list', archivePath)
|
const tarPath = await getTarPath()
|
||||||
await execCommands(commands)
|
const BSD_TAR_ZSTD =
|
||||||
|
tarPath === SystemTarPathOnWindows &&
|
||||||
|
compressionMethod !== CompressionMethod.Gzip
|
||||||
|
const compressionArgs = await getCompressionProgram(
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract a tar
|
|
||||||
export async function extractTar(
|
export async function extractTar(
|
||||||
archivePath: string,
|
archivePath: string,
|
||||||
compressionMethod: CompressionMethod
|
compressionMethod: CompressionMethod
|
||||||
): 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 commands = await getCommands(compressionMethod, 'extract', archivePath)
|
const tarArgs = await getTarArgs(compressionMethod, 'extract', archivePath)
|
||||||
await execCommands(commands)
|
const compressionArgs = await getCompressionProgram(
|
||||||
|
compressionMethod,
|
||||||
|
archivePath
|
||||||
|
)
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a tar
|
|
||||||
export async function createTar(
|
export async function createTar(
|
||||||
archiveFolder: string,
|
archiveFolder: string,
|
||||||
sourceDirectories: string[],
|
sourceDirectories: string[],
|
||||||
compressionMethod: CompressionMethod
|
compressionMethod: CompressionMethod
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// 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 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 commands = await getCommands(compressionMethod, 'create')
|
|
||||||
await execCommands(commands, archiveFolder)
|
// -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'
|
||||||
|
// --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.
|
||||||
|
// Long range mode is added to zstd in v1.3.2 release, so we will not use --long in older version of zstd.
|
||||||
|
function getCompressionProgram(): string[] {
|
||||||
|
switch (compressionMethod) {
|
||||||
|
case CompressionMethod.Zstd:
|
||||||
|
return BSD_TAR_ZSTD
|
||||||
|
? [
|
||||||
|
'&&',
|
||||||
|
'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:
|
||||||
|
return BSD_TAR_ZSTD
|
||||||
|
? [
|
||||||
|
'&&',
|
||||||
|
'zstd -T0 -o',
|
||||||
|
cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
|
tarFile
|
||||||
|
]
|
||||||
|
: ['--use-compress-program', IS_WINDOWS ? 'zstd -T0' : 'zstdmt']
|
||||||
|
default:
|
||||||
|
return ['-z']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const tarArgs = await getTarArgs(compressionMethod, 'create')
|
||||||
|
const compressionArgs = getCompressionProgram()
|
||||||
|
const args = tarArgs.concat(compressionArgs)
|
||||||
|
await execTar(args, 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