From 8d6737458adf9b01256a990dca84abdad3d9fc73 Mon Sep 17 00:00:00 2001 From: BSKY Date: Sat, 21 Mar 2020 11:42:29 +0900 Subject: [PATCH] Organize code --- __tests__/tar.test.ts | 20 +++++++++----------- src/constants.ts | 2 ++ src/tar.ts | 7 +++---- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/__tests__/tar.test.ts b/__tests__/tar.test.ts index 38012c9..fd59424 100644 --- a/__tests__/tar.test.ts +++ b/__tests__/tar.test.ts @@ -3,7 +3,7 @@ import * as io from "@actions/io"; import { promises as fs } from "fs"; import * as path from "path"; -import { CacheFilename } from "../src/constants"; +import { CacheFilename, ManifestFilename } from "../src/constants"; import * as tar from "../src/tar"; jest.mock("@actions/exec"); @@ -32,11 +32,11 @@ test("extract tar", async () => { const execMock = jest.spyOn(exec, "exec"); const archivePath = "cache.tar"; - const workspace = process.env["GITHUB_WORKSPACE"]; + const workingDirectory = process.env["GITHUB_WORKSPACE"]; await tar.extractTar(archivePath); - expect(mkdirMock).toHaveBeenCalledWith(workspace); + expect(mkdirMock).toHaveBeenCalledWith(workingDirectory); const IS_WINDOWS = process.platform === "win32"; const tarPath = IS_WINDOWS @@ -52,7 +52,7 @@ test("extract tar", async () => { archivePath, "-P", "-C", - workspace + workingDirectory ], { cwd: undefined } ); @@ -62,8 +62,8 @@ test("create tar", async () => { const execMock = jest.spyOn(exec, "exec"); const archiveFolder = getTempDir(); - const workspace = process.env["GITHUB_WORKSPACE"]; - const sourceDirectories = ["~/.npm/cache", `${workspace}/dist`]; + const workingDirectory = process.env["GITHUB_WORKSPACE"]; + const sourceDirectories = ["~/.npm/cache", `${workingDirectory}/dist`]; await fs.mkdir(archiveFolder, { recursive: true }); @@ -83,12 +83,10 @@ test("create tar", async () => { "-cf", CacheFilename, "-C", - workspace, + workingDirectory, "--files-from", - "manifest.txt" + ManifestFilename ], - { - cwd: archiveFolder - } + { cwd: archiveFolder } ); }); diff --git a/src/constants.ts b/src/constants.ts index ace35d9..c3ea1c9 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -20,3 +20,5 @@ export enum Events { } export const CacheFilename = "cache.tar.zst"; + +export const ManifestFilename = "manifest.txt"; diff --git a/src/tar.ts b/src/tar.ts index 154baca..b57af7f 100644 --- a/src/tar.ts +++ b/src/tar.ts @@ -3,7 +3,7 @@ import * as io from "@actions/io"; import { existsSync, writeFileSync } from "fs"; import * as path from "path"; -import { CacheFilename } from "./constants"; +import { CacheFilename, ManifestFilename } from "./constants"; async function getTarPath(): Promise { // Explicitly use BSD Tar on Windows @@ -56,9 +56,8 @@ export async function createTar( sourceDirectories: string[] ): Promise { // Write source directories to manifest.txt to avoid command length limits - const manifestFilename = "manifest.txt"; writeFileSync( - path.join(archiveFolder, manifestFilename), + path.join(archiveFolder, ManifestFilename), sourceDirectories.join("\n") ); @@ -71,7 +70,7 @@ export async function createTar( "-C", workingDirectory, "--files-from", - manifestFilename + ManifestFilename ]; await execTar(args, archiveFolder); }