Merge pull request #189 from aminya/path [skip ci]

This commit is contained in:
Amin Yahyaabadi 2023-09-01 02:03:33 -07:00 committed by GitHub
commit e0bca0a01d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 59 additions and 44 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -61,12 +61,27 @@ function escapeString(valGiven: string, shouldEscapeSpace: boolean = false) {
return escapeQuote(spaceEscaped, '"', "\\") return escapeQuote(spaceEscaped, '"', "\\")
} }
const ignoredPaths = [/\/usr\/bin\/?/, /\/usr\/local\/bin\/?/]
/** Skip adding /usr/bin to PATH if it is already there */
function isIgnoredPath(path: string) {
if (ignoredPaths.some((checkedPath) => checkedPath.test(path))) {
const paths = process.env.PATH?.split(delimiter) ?? []
return paths.includes(path)
}
return false
}
/** /**
* Add a path to the PATH environment variable. * Add a path to the PATH environment variable.
* *
* This function is cross-platforms and works in all the local or CI systems. * This function is cross-platforms and works in all the local or CI systems.
*/ */
export async function addPath(path: string) { export async function addPath(path: string) {
if (isIgnoredPath(path)) {
return
}
process.env.PATH = `${path}${delimiter}${process.env.PATH}` process.env.PATH = `${path}${delimiter}${process.env.PATH}`
try { try {
if (GITHUB_ACTIONS) { if (GITHUB_ACTIONS) {