fix: only cache if in ci

This commit is contained in:
Amin Yahyaabadi 2021-09-18 11:27:15 -05:00
parent d81b44b112
commit 418fa80b65
1 changed files with 14 additions and 11 deletions

View File

@ -5,6 +5,7 @@ import { join } from "path"
import { existsSync } from "fs"
import * as hasha from "hasha"
import { tmpdir } from "os"
import { isCI } from "../env/isci"
/** A type that describes a package */
export type PackageInfo = {
@ -47,6 +48,7 @@ export async function setupBin(
const { url, binRelativeDir, extractedFolderName, extractFunction } = await getPackageInfo(version, process.platform)
// Restore from cache (if found).
if (isCI()) {
try {
const dir = find(name, version)
if (dir) {
@ -59,6 +61,7 @@ export async function setupBin(
} catch {
// fails on a local machine?
}
}
// Get an unique output directory name from the URL.
const key: string = await hasha.async(url, { algorithm: "md5" })
@ -80,7 +83,7 @@ export async function setupBin(
await addPath(binDir)
// check if inside Github Actions. If so, cache the installation
if (typeof process.env.RUNNER_TOOL_CACHE === "string") {
if (isCI() && typeof process.env.RUNNER_TOOL_CACHE === "string") {
await cacheDir(rootDir, name, version)
}