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 { existsSync } from "fs"
import * as hasha from "hasha" import * as hasha from "hasha"
import { tmpdir } from "os" import { tmpdir } from "os"
import { isCI } from "../env/isci"
/** A type that describes a package */ /** A type that describes a package */
export type PackageInfo = { export type PackageInfo = {
@ -47,17 +48,19 @@ export async function setupBin(
const { url, binRelativeDir, extractedFolderName, extractFunction } = await getPackageInfo(version, process.platform) const { url, binRelativeDir, extractedFolderName, extractFunction } = await getPackageInfo(version, process.platform)
// Restore from cache (if found). // Restore from cache (if found).
try { if (isCI()) {
const dir = find(name, version) try {
if (dir) { const dir = find(name, version)
info(`${name} ${version} was found in the cache.`) if (dir) {
const installDir = join(dir, extractedFolderName) info(`${name} ${version} was found in the cache.`)
const binDir = join(installDir, binRelativeDir) const installDir = join(dir, extractedFolderName)
await addPath(binDir) const binDir = join(installDir, binRelativeDir)
return { installDir, binDir } 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. // Get an unique output directory name from the URL.
@ -80,7 +83,7 @@ export async function setupBin(
await addPath(binDir) await addPath(binDir)
// check if inside Github Actions. If so, cache the installation // 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) await cacheDir(rootDir, name, version)
} }