diff --git a/packages/cache/__tests__/tar.test.ts b/packages/cache/__tests__/tar.test.ts index 31af266e..6983d5f7 100644 --- a/packages/cache/__tests__/tar.test.ts +++ b/packages/cache/__tests__/tar.test.ts @@ -28,6 +28,10 @@ beforeAll(async () => { await jest.requireActual('@actions/io').rmRF(getTempDir()) }) +beforeEach(async () => { + jest.restoreAllMocks() +}) + afterAll(async () => { delete process.env['GITHUB_WORKSPACE'] await jest.requireActual('@actions/io').rmRF(getTempDir()) @@ -41,13 +45,16 @@ test('zstd extract tar', async () => { ? `${process.env['windir']}\\fakepath\\cache.tar` : 'cache.tar' const workspace = process.env['GITHUB_WORKSPACE'] + const tarPath = IS_WINDOWS + ? `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe` + : defaultTarPath await tar.extractTar(archivePath, CompressionMethod.Zstd) expect(mkdirMock).toHaveBeenCalledWith(workspace) expect(execMock).toHaveBeenCalledTimes(1) expect(execMock).toHaveBeenCalledWith( - `"${defaultTarPath}"`, + `"${tarPath}"`, [ '--use-compress-program', IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30', @@ -75,7 +82,7 @@ test('gzip extract tar', async () => { expect(mkdirMock).toHaveBeenCalledWith(workspace) const tarPath = IS_WINDOWS - ? `${process.env['windir']}\\System32\\tar.exe` + ? `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe` : defaultTarPath expect(execMock).toHaveBeenCalledTimes(1) expect(execMock).toHaveBeenCalledWith( @@ -87,7 +94,9 @@ test('gzip extract tar', async () => { '-P', '-C', IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace - ].concat(IS_MAC ? ['--delay-directory-restore'] : []), + ] + .concat(IS_WINDOWS ? ['--force-local'] : []) + .concat(IS_MAC ? ['--delay-directory-restore'] : []), {cwd: undefined} ) }) @@ -134,9 +143,13 @@ test('zstd create tar', async () => { await tar.createTar(archiveFolder, sourceDirectories, CompressionMethod.Zstd) + const tarPath = IS_WINDOWS + ? `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe` + : defaultTarPath + expect(execMock).toHaveBeenCalledTimes(1) expect(execMock).toHaveBeenCalledWith( - `"${defaultTarPath}"`, + `"${tarPath}"`, [ '--posix', '--use-compress-program', @@ -171,7 +184,7 @@ test('gzip create tar', async () => { await tar.createTar(archiveFolder, sourceDirectories, CompressionMethod.Gzip) const tarPath = IS_WINDOWS - ? `${process.env['windir']}\\System32\\tar.exe` + ? `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe` : defaultTarPath expect(execMock).toHaveBeenCalledTimes(1) @@ -189,7 +202,9 @@ test('gzip create tar', async () => { IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace, '--files-from', 'manifest.txt' - ].concat(IS_MAC ? ['--delay-directory-restore'] : []), + ] + .concat(IS_WINDOWS ? ['--force-local'] : []) + .concat(IS_MAC ? ['--delay-directory-restore'] : []), { cwd: archiveFolder } @@ -205,9 +220,12 @@ test('zstd list tar', async () => { await tar.listTar(archivePath, CompressionMethod.Zstd) + const tarPath = IS_WINDOWS + ? `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe` + : defaultTarPath expect(execMock).toHaveBeenCalledTimes(1) expect(execMock).toHaveBeenCalledWith( - `"${defaultTarPath}"`, + `"${tarPath}"`, [ '--use-compress-program', IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30', @@ -230,9 +248,12 @@ test('zstdWithoutLong list tar', async () => { await tar.listTar(archivePath, CompressionMethod.ZstdWithoutLong) + const tarPath = IS_WINDOWS + ? `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe` + : defaultTarPath expect(execMock).toHaveBeenCalledTimes(1) expect(execMock).toHaveBeenCalledWith( - `"${defaultTarPath}"`, + `"${tarPath}"`, [ '--use-compress-program', IS_WINDOWS ? 'zstd -d' : 'unzstd', @@ -255,7 +276,7 @@ test('gzip list tar', async () => { await tar.listTar(archivePath, CompressionMethod.Gzip) const tarPath = IS_WINDOWS - ? `${process.env['windir']}\\System32\\tar.exe` + ? `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe` : defaultTarPath expect(execMock).toHaveBeenCalledTimes(1) expect(execMock).toHaveBeenCalledWith( @@ -265,7 +286,9 @@ test('gzip list tar', async () => { '-tf', IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, '-P' - ].concat(IS_MAC ? ['--delay-directory-restore'] : []), + ] + .concat(IS_WINDOWS ? ['--force-local'] : []) + .concat(IS_MAC ? ['--delay-directory-restore'] : []), {cwd: undefined} ) }) diff --git a/packages/cache/src/internal/cacheUtils.ts b/packages/cache/src/internal/cacheUtils.ts index da4b8d81..30538e24 100644 --- a/packages/cache/src/internal/cacheUtils.ts +++ b/packages/cache/src/internal/cacheUtils.ts @@ -67,7 +67,7 @@ export async function unlinkFile(filePath: fs.PathLike): Promise { return util.promisify(fs.unlink)(filePath) } -async function getVersion(app: string): Promise { +export async function getVersion(app: string): Promise { core.debug(`Checking ${app} --version`) let versionOutput = '' try { diff --git a/packages/cache/src/internal/tar.ts b/packages/cache/src/internal/tar.ts index 9e140fe0..1941afd1 100644 --- a/packages/cache/src/internal/tar.ts +++ b/packages/cache/src/internal/tar.ts @@ -16,17 +16,18 @@ async function getTarPath( const systemTar = `${process.env['windir']}\\System32\\tar.exe` const gnuTar = `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe` if (existsSync(gnuTar)) { - // Making GNUtar + zstd as default on windows + // Use GNUtar as default on windows args.push('--force-local') return gnuTar - } else if (compressionMethod !== CompressionMethod.Gzip) { + } else if ( + compressionMethod !== CompressionMethod.Gzip || + (await utils.isGnuTarInstalled()) + ) { // We only use zstandard compression on windows when gnu tar is installed due to // a bug with compressing large files with bsdtar + zstd args.push('--force-local') } else if (existsSync(systemTar)) { return systemTar - } else if (await utils.isGnuTarInstalled()) { - args.push('--force-local') } break }