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,17 +48,19 @@ export async function setupBin(
const { url, binRelativeDir, extractedFolderName, extractFunction } = await getPackageInfo(version, process.platform)
// Restore from cache (if found).
try {
const dir = find(name, version)
if (dir) {
info(`${name} ${version} was found in the cache.`)
const installDir = join(dir, extractedFolderName)
const binDir = join(installDir, binRelativeDir)
await addPath(binDir)
return { installDir, binDir }
if (isCI()) {
try {
const dir = find(name, version)
if (dir) {
info(`${name} ${version} was found in the cache.`)
const installDir = join(dir, extractedFolderName)
const binDir = join(installDir, binRelativeDir)
await addPath(binDir)
return { installDir, binDir }
}
} catch {
// fails on a local machine?
}
} catch {
// fails on a local machine?
}
// Get an unique output directory name from the URL.
@ -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)
}