@@ -25,7 +25,7 @@ async function execute (command) {
2525 }
2626}
2727
28- async function exec_pwsh ( command ) {
28+ async function execPwsh ( command ) {
2929 try {
3030 await exec ( 'powershell' , [ '-command' , command ] )
3131 } catch ( error ) {
@@ -46,7 +46,7 @@ function touch (filename) {
4646
4747async function run ( ) {
4848 try {
49- const base_url = 'https://micro.mamba.pm/api/micromamba'
49+ const baseUrl = 'https://micro.mamba.pm/api/micromamba'
5050 const envFileName = core . getInput ( 'environment-file' )
5151 const envFilePath = path . join ( process . env . GITHUB_WORKSPACE || '' , envFileName )
5252 const envYaml = yaml . safeLoad ( fs . readFileSync ( envFilePath , 'utf8' ) )
@@ -55,9 +55,9 @@ async function run () {
5555 const profile = path . join ( os . homedir ( ) , '.bash_profile' )
5656 const bashrc = path . join ( os . homedir ( ) , '.bashrc' )
5757 const bashrcBak = path . join ( os . homedir ( ) , '.bashrc.actionbak' )
58+ const micromambaLoc = path . join ( os . homedir ( ) , 'micromamba-bin/micromamba' )
5859
59- if ( process . platform !== 'win32' )
60- {
60+ if ( process . platform !== 'win32' ) {
6161 core . startGroup ( 'Configuring conda...' )
6262 touch ( condarc )
6363 fs . appendFileSync ( condarc , 'always_yes: true\n' )
@@ -73,40 +73,39 @@ async function run () {
7373
7474 touch ( profile )
7575
76- if ( process . platform === 'darwin' )
77- {
76+ await execute ( 'mkdir -p ' + path . join ( os . homedir ( ) , 'micromamba-bin/' ) )
77+
78+ if ( process . platform === 'darwin' ) {
7879 // macos
7980 try {
80- await executeNoCatch ( `curl -Ls ${ base_url } /osx-64/latest | tar -xvj bin/micromamba` )
81+ await executeNoCatch ( `curl -Ls ${ baseUrl } /osx-64/latest | tar -xvjO bin/micromamba > ${ micromambaLoc } ` )
8182 } catch ( error ) {
82- await execute ( `curl -Ls ${ base_url } /osx-64/latest | tar -xvz bin/micromamba` )
83+ await execute ( `curl -Ls ${ baseUrl } /osx-64/latest | tar -xvzO bin/micromamba > ${ micromambaLoc } ` )
8384 }
84- await execute ( 'mv ./bin/micromamba ./micromamba' )
85- await execute ( 'rm -rf ./bin' )
86- await execute ( './micromamba shell init -s bash -p ~/micromamba' )
87- }
88- else if ( process . platform === 'linux' )
89- {
85+ await execute ( `chmod u+x ${ micromambaLoc } ` )
86+ await execute ( `${ micromambaLoc } shell init -s bash -p ~/micromamba` )
87+ } else if ( process . platform === 'linux' ) {
9088 // linux
9189 try {
92- await executeNoCatch ( `wget -qO- ${ base_url } /linux-64/latest | tar -xvj bin/micromamba --strip-components=1 ` )
90+ await executeNoCatch ( `wget -qO- ${ baseUrl } /linux-64/latest | tar -xvjO bin/micromamba > ${ micromambaLoc } ` )
9391 } catch ( error ) {
94- await execute ( `wget -qO- ${ base_url } /linux-64/latest | tar -xvz bin/micromamba --strip-components=1 ` )
92+ await execute ( `wget -qO- ${ baseUrl } /linux-64/latest | tar -xvzO bin/micromamba > ${ micromambaLoc } ` )
9593 }
94+ await execute ( `chmod u+x ${ micromambaLoc } ` )
9695
9796 // on linux we move the bashrc to a backup and then restore
9897 await execute ( 'mv ' + bashrc + ' ' + bashrcBak )
9998 touch ( bashrc )
10099 try {
101- await execute ( './micromamba shell init -s bash -p ~/micromamba' )
100+ await execute ( ` ${ micromambaLoc } shell init -s bash -p ~/micromamba` )
102101 fs . appendFileSync ( profile , '\n' + fs . readFileSync ( bashrc , 'utf8' ) , 'utf8' )
103102 await execute ( 'mv ' + bashrcBak + ' ' + bashrc )
104103 } catch ( error ) {
105104 await execute ( 'mv ' + bashrcBak + ' ' + bashrc )
106105 core . setFailed ( error . message )
107106 }
108107 } else {
109- throw 'Platform ' + process . platform + ' not supported.' ;
108+ core . setFailed ( 'Platform ' + process . platform + ' not supported.' )
110109 }
111110
112111 // final bits of the install
@@ -117,11 +116,9 @@ async function run () {
117116 core . endGroup ( )
118117
119118 await execute ( 'source ' + profile + ' && micromamba list' )
120- }
121- else
122- {
119+ } else {
123120 // handle win32!
124- const powershell_auto_activate_env = `if (!(Test-Path $profile))
121+ const powershellAutoActivateEnv = `if (!(Test-Path $profile))
125122{
126123 New-Item -path $profile -type "file" -value "CONTENTPLACEHOLDER"
127124 Write-Host "Created new profile and content added"
@@ -130,27 +127,27 @@ else
130127{
131128 Add-Content -path $profile -value "CONTENTPLACEHOLDER"
132129 Write-Host "Profile already exists and new content added"
133- }` ;
134- const autoactivate = powershell_auto_activate_env . replace ( / C O N T E N T P L A C E H O L D E R / g, `micromamba activate ${ envName } ` ) ;
135- core . startGroup ( `Installing environment ${ envName } from ${ envFilePath } ...` ) ;
130+ }`
131+ const autoactivate = powershellAutoActivateEnv . replace ( / C O N T E N T P L A C E H O L D E R / g, `micromamba activate ${ envName } ` )
132+ core . startGroup ( `Installing environment ${ envName } from ${ envFilePath } ...` )
136133 touch ( profile )
137134
138- await exec_pwsh ( `Invoke-Webrequest -URI ${ base_url } /win-64/latest -OutFile micromamba.tar.bz2` ) ;
139- await exec_pwsh ( " C:\\PROGRA~1\\7-Zip\\7z.exe x micromamba.tar.bz2 -aoa" ) ;
140- await exec_pwsh ( " C:\\PROGRA~1\\7-Zip\\7z.exe x micromamba.tar -ttar -aoa -r Library\\bin\\micromamba.exe" ) ;
141- await exec_pwsh ( " MOVE -Force Library\\bin\\micromamba.exe micromamba.exe" ) ;
142- await exec_pwsh ( " .\\micromamba.exe --help" ) ;
143- await exec_pwsh ( " .\\micromamba.exe shell init -s powershell -p $HOME\\micromamba" ) ;
135+ await execPwsh ( `Invoke-Webrequest -URI ${ baseUrl } /win-64/latest -OutFile micromamba.tar.bz2` )
136+ await execPwsh ( ' C:\\PROGRA~1\\7-Zip\\7z.exe x micromamba.tar.bz2 -aoa' )
137+ await execPwsh ( ' C:\\PROGRA~1\\7-Zip\\7z.exe x micromamba.tar -ttar -aoa -r Library\\bin\\micromamba.exe' )
138+ await execPwsh ( ' MOVE -Force Library\\bin\\micromamba.exe micromamba.exe' )
139+ await execPwsh ( ' .\\micromamba.exe --help' )
140+ await execPwsh ( ' .\\micromamba.exe shell init -s powershell -p $HOME\\micromamba' )
144141 // Can only init once right now ...
145- // await exec_pwsh (".\\micromamba.exe shell init -s bash -p $HOME\\micromamba");
146- await exec_pwsh ( " MD $HOME\\micromamba\\pkgs -ea 0" ) ;
147- await exec_pwsh ( `.\\micromamba.exe create --strict-channel-priority -y -f ${ envFilePath } ` ) ;
148- await exec_pwsh ( autoactivate ) ;
142+ // await execPwsh (".\\micromamba.exe shell init -s bash -p $HOME\\micromamba")
143+ await execPwsh ( ' MD $HOME\\micromamba\\pkgs -ea 0' )
144+ await execPwsh ( `.\\micromamba.exe create --strict-channel-priority -y -f ${ envFilePath } ` )
145+ await execPwsh ( autoactivate )
149146
150147 fs . appendFileSync ( profile , `micromamba activate ${ envName } \n` )
151148
152149 core . endGroup ( )
153- await exec_pwsh ( 'micromamba list' )
150+ await execPwsh ( 'micromamba list' )
154151 }
155152 } catch ( error ) {
156153 core . setFailed ( error . message )
0 commit comments