From 882d0f7013bdb3d22592b84ef7febc82c22923b2 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 17 Sep 2021 21:17:21 -0500 Subject: [PATCH] feat: catch the addPath failure --- src/cppcheck/cppcheck.ts | 2 +- src/doxygen/doxygen.ts | 2 +- src/gcc/gcc.ts | 3 ++- src/opencppcoverage/opencppcoverage.ts | 2 +- src/utils/path/addPath.ts | 15 +++++++++++++++ src/utils/setup/setupBin.ts | 3 ++- src/utils/setup/setupChocoPack.ts | 2 +- src/utils/setup/setupPipPack.ts | 3 ++- 8 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 src/utils/path/addPath.ts diff --git a/src/cppcheck/cppcheck.ts b/src/cppcheck/cppcheck.ts index ea6bdfd8..604572f8 100644 --- a/src/cppcheck/cppcheck.ts +++ b/src/cppcheck/cppcheck.ts @@ -1,4 +1,4 @@ -import { addPath } from "@actions/core" +import { addPath } from "../utils/path/addPath" import { setupAptPack } from "../utils/setup/setupAptPack" import { setupBrewPack } from "../utils/setup/setupBrewPack" import { setupChocoPack } from "../utils/setup/setupChocoPack" diff --git a/src/doxygen/doxygen.ts b/src/doxygen/doxygen.ts index 00597450..d285e505 100644 --- a/src/doxygen/doxygen.ts +++ b/src/doxygen/doxygen.ts @@ -1,4 +1,4 @@ -import { addPath } from "@actions/core" +import { addPath } from "../utils/path/addPath" import { setupAptPack } from "../utils/setup/setupAptPack" import { setupBrewPack } from "../utils/setup/setupBrewPack" import { setupChocoPack } from "../utils/setup/setupChocoPack" diff --git a/src/gcc/gcc.ts b/src/gcc/gcc.ts index 6bb5047f..eef9ad82 100644 --- a/src/gcc/gcc.ts +++ b/src/gcc/gcc.ts @@ -1,4 +1,5 @@ -import { addPath, exportVariable, info } from "@actions/core" +import { exportVariable, info } from "@actions/core" +import { addPath } from "../utils/path/addPath" import { existsSync } from "fs" import { setupAptPack } from "../utils/setup/setupAptPack" import { setupBrewPack } from "../utils/setup/setupBrewPack" diff --git a/src/opencppcoverage/opencppcoverage.ts b/src/opencppcoverage/opencppcoverage.ts index 526d27f3..0da064ee 100644 --- a/src/opencppcoverage/opencppcoverage.ts +++ b/src/opencppcoverage/opencppcoverage.ts @@ -1,4 +1,4 @@ -import { addPath } from "@actions/core" +import { addPath } from "../utils/path/addPath" import { setupChocoPack } from "../utils/setup/setupChocoPack" // eslint-disable-next-line @typescript-eslint/no-unused-vars diff --git a/src/utils/path/addPath.ts b/src/utils/path/addPath.ts new file mode 100644 index 00000000..3df9e9a6 --- /dev/null +++ b/src/utils/path/addPath.ts @@ -0,0 +1,15 @@ +import { addPath as ghAddPath } from "@actions/core" +import { delimiter } from "path" +import * as core from "@actions/core" + +/** An add path function that works locally or inside GitHub Actions */ +export function addPath(path: string) { + try { + ghAddPath(path) + } catch (err) { + core.error(err as Error) + core.error(`Failed to add ${path} to the percistent PATH. You should add it manually.`) + process.env.PATH = `${path}${delimiter}${process.env.PATH}` + // TODO shell out to add path + } +} diff --git a/src/utils/setup/setupBin.ts b/src/utils/setup/setupBin.ts index 54a771b7..b7a590b8 100644 --- a/src/utils/setup/setupBin.ts +++ b/src/utils/setup/setupBin.ts @@ -1,5 +1,6 @@ import { find, downloadTool, cacheDir } from "@actions/tool-cache" -import { addPath, info } from "@actions/core" +import { info } from "@actions/core" +import { addPath } from "../path/addPath" import { join } from "path" import { existsSync } from "fs" import * as hasha from "hasha" diff --git a/src/utils/setup/setupChocoPack.ts b/src/utils/setup/setupChocoPack.ts index 668f8f2d..c55bbad3 100644 --- a/src/utils/setup/setupChocoPack.ts +++ b/src/utils/setup/setupChocoPack.ts @@ -1,5 +1,5 @@ /* eslint-disable require-atomic-updates */ -import { addPath } from "@actions/core" +import { addPath } from "../path/addPath" import which from "which" import { setupChocolatey } from "../../chocolatey/chocolatey" import { InstallationInfo } from "./setupBin" diff --git a/src/utils/setup/setupPipPack.ts b/src/utils/setup/setupPipPack.ts index e393a51f..511b3ce3 100644 --- a/src/utils/setup/setupPipPack.ts +++ b/src/utils/setup/setupPipPack.ts @@ -2,7 +2,8 @@ import { getExecOutput } from "@actions/exec" import spawn from "cross-spawn" import which from "which" -import { addPath, info } from "@actions/core" +import { info } from "@actions/core" +import { addPath } from "../path/addPath" import { setupPython } from "../../python/python" import { isBinUptoDate } from "./version" import { join } from "path"