mirror of https://github.com/aminya/setup-cpp
fix: prevent adding /usr/bin if it is already on the PATH
This commit is contained in:
parent
511e70eef5
commit
307b9178a3
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
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue