@@ -2,34 +2,47 @@ import { addPath as ghAddPath } from "@actions/core"
22import { delimiter } from "path"
33import * as core from "@actions/core"
44import execa from "execa"
5+ import { isGitHubCI } from "../env/isci"
6+ import untildify from "untildify"
7+ import { appendFileSync } from "fs"
8+ // import { spawnSync } from "child_process"
59
610/** An add path function that works locally or inside GitHub Actions */
711export function addPath ( path : string ) {
812 try {
9- ghAddPath ( path )
13+ if ( isGitHubCI ( ) ) {
14+ ghAddPath ( path )
15+ } else {
16+ addPathSystem ( path )
17+ }
1018 } catch ( err ) {
1119 try {
1220 core . error ( err as Error )
13- switch ( process . platform ) {
14- case "win32" : {
15- execa . sync ( `setx PATH=${ path } ;%PATH%` )
16- return
17- }
18- case "linux" :
19- case "darwin" : {
20- execa . commandSync ( `echo "export PATH=${ path } :$PATH" >> ~/.profile` )
21- execa . commandSync ( `source ~/.profile` )
22- core . info ( `${ path } was added to ~/.profile` )
23- return
24- }
25- default : {
26- // fall through shell path modification
27- }
28- }
21+ return addPathSystem ( path )
2922 } catch ( err2 ) {
3023 core . error ( err2 as Error )
3124 }
3225 core . error ( `Failed to add ${ path } to the percistent PATH. You should add it manually.` )
33- process . env . PATH = `${ path } ${ delimiter } ${ process . env . PATH } `
3426 }
3527}
28+
29+ function addPathSystem ( path : string ) {
30+ switch ( process . platform ) {
31+ case "win32" : {
32+ execa . sync ( `setx PATH=${ path } ;%PATH%` )
33+ return
34+ }
35+ case "linux" :
36+ case "darwin" : {
37+ const profile_path = untildify ( "~/.profile" )
38+ appendFileSync ( profile_path , `\nexport PATH=${ path } :$PATH\n` )
39+ // spawnSync(`source "${profile_path}"`, { shell: true })
40+ core . info ( `${ path } was added to "${ profile_path } "` )
41+ return
42+ }
43+ default : {
44+ // fall through shell path modification
45+ }
46+ }
47+ process . env . PATH = `${ path } ${ delimiter } ${ process . env . PATH } `
48+ }
0 commit comments