From 7c7ab7c49eb0375afcea5462ea2ddbf5a07bba0e Mon Sep 17 00:00:00 2001 From: BSKY Date: Sat, 21 Mar 2020 10:57:48 +0900 Subject: [PATCH] Use zstd instead of gzip --- __tests__/restore.test.ts | 8 ++++---- __tests__/tar.test.ts | 15 ++++++++++++--- src/constants.ts | 2 +- src/restore.ts | 4 ++-- src/tar.ts | 15 ++++++++++++--- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts index 8ad0cef..a2be636 100644 --- a/__tests__/restore.test.ts +++ b/__tests__/restore.test.ts @@ -2,7 +2,7 @@ import * as core from "@actions/core"; import * as path from "path"; import * as cacheHttpClient from "../src/cacheHttpClient"; -import { Events, Inputs } from "../src/constants"; +import { CacheFilename, Events, Inputs } from "../src/constants"; import { ArtifactCacheEntry } from "../src/contracts"; import run from "../src/restore"; import * as tar from "../src/tar"; @@ -227,7 +227,7 @@ test("restore with cache found", async () => { return Promise.resolve(tempPath); }); - const archivePath = path.join(tempPath, "cache.tgz"); + const archivePath = path.join(tempPath, CacheFilename); const setCacheStateMock = jest.spyOn(actionUtils, "setCacheState"); const downloadCacheMock = jest.spyOn(cacheHttpClient, "downloadCache"); @@ -297,7 +297,7 @@ test("restore with a pull request event and cache found", async () => { return Promise.resolve(tempPath); }); - const archivePath = path.join(tempPath, "cache.tgz"); + const archivePath = path.join(tempPath, CacheFilename); const setCacheStateMock = jest.spyOn(actionUtils, "setCacheState"); const downloadCacheMock = jest.spyOn(cacheHttpClient, "downloadCache"); @@ -364,7 +364,7 @@ test("restore with cache found for restore key", async () => { return Promise.resolve(tempPath); }); - const archivePath = path.join(tempPath, "cache.tgz"); + const archivePath = path.join(tempPath, CacheFilename); const setCacheStateMock = jest.spyOn(actionUtils, "setCacheState"); const downloadCacheMock = jest.spyOn(cacheHttpClient, "downloadCache"); diff --git a/__tests__/tar.test.ts b/__tests__/tar.test.ts index fdf637a..38012c9 100644 --- a/__tests__/tar.test.ts +++ b/__tests__/tar.test.ts @@ -45,7 +45,15 @@ test("extract tar", async () => { expect(execMock).toHaveBeenCalledTimes(1); expect(execMock).toHaveBeenCalledWith( `"${tarPath}"`, - ["-xz", "-f", archivePath, "-P", "-C", workspace], + [ + "--use-compress-program", + "zstd --long=31 -d", + "-xf", + archivePath, + "-P", + "-C", + workspace + ], { cwd: undefined } ); }); @@ -70,8 +78,9 @@ test("create tar", async () => { expect(execMock).toHaveBeenCalledWith( `"${tarPath}"`, [ - "-cz", - "-f", + "--use-compress-program", + "zstd -T0 --long=31", + "-cf", CacheFilename, "-C", workspace, diff --git a/src/constants.ts b/src/constants.ts index 2b78f62..ace35d9 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -19,4 +19,4 @@ export enum Events { PullRequest = "pull_request" } -export const CacheFilename = "cache.tgz"; +export const CacheFilename = "cache.tar.zst"; diff --git a/src/restore.ts b/src/restore.ts index 112e851..b26b260 100644 --- a/src/restore.ts +++ b/src/restore.ts @@ -2,7 +2,7 @@ import * as core from "@actions/core"; import * as path from "path"; import * as cacheHttpClient from "./cacheHttpClient"; -import { Events, Inputs, State } from "./constants"; +import { CacheFilename, Events, Inputs, State } from "./constants"; import { extractTar } from "./tar"; import * as utils from "./utils/actionUtils"; @@ -63,7 +63,7 @@ async function run(): Promise { const archivePath = path.join( await utils.createTempDirectory(), - "cache.tgz" + CacheFilename ); core.debug(`Archive Path: ${archivePath}`); diff --git a/src/tar.ts b/src/tar.ts index 3ca3019..154baca 100644 --- a/src/tar.ts +++ b/src/tar.ts @@ -39,7 +39,15 @@ export async function extractTar(archivePath: string): Promise { // Create directory to extract tar into const workingDirectory = getWorkingDirectory(); await io.mkdirP(workingDirectory); - const args = ["-xz", "-f", archivePath, "-P", "-C", workingDirectory]; + const args = [ + "--use-compress-program", + "zstd --long=31 -d", + "-xf", + archivePath, + "-P", + "-C", + workingDirectory + ]; await execTar(args); } @@ -56,8 +64,9 @@ export async function createTar( const workingDirectory = getWorkingDirectory(); const args = [ - "-cz", - "-f", + "--use-compress-program", + "zstd -T0 --long=31", + "-cf", CacheFilename, "-C", workingDirectory,