@@ -10,24 +10,34 @@ const cache = require('@actions/cache')
10
10
const core = require ( '@actions/core' )
11
11
const exec = require ( '@actions/exec' )
12
12
13
- const MAMBA_PLATFORM = { darwin : 'osx' , linux : 'linux' , win32 : 'win' } [ process . platform ]
14
- if ( ! MAMBA_PLATFORM ) {
15
- throw Error ( `Platform ${ process . platform } not supported.` )
16
- }
17
13
const PATHS = {
18
14
condarc : path . join ( os . homedir ( ) , '.condarc' ) ,
19
15
bashprofile : path . join ( os . homedir ( ) , '.bash_profile' ) ,
20
16
bashrc : path . join ( os . homedir ( ) , '.bashrc' ) ,
21
17
bashrcBak : path . join ( os . homedir ( ) , '.bashrc.actionbak' ) ,
22
18
micromambaBinFolder : path . join ( os . homedir ( ) , 'micromamba-bin' ) ,
23
- micromambaExe : path . join ( os . homedir ( ) , 'micromamba-bin' , MAMBA_PLATFORM === 'win ' ? 'micromamba.exe' : 'micromamba' ) ,
19
+ micromambaExe : path . join ( os . homedir ( ) , 'micromamba-bin' , process . platform === 'win32 ' ? 'micromamba.exe' : 'micromamba' ) ,
24
20
micromambaRoot : path . join ( os . homedir ( ) , 'micromamba' ) ,
25
21
micromambaPkgs : path . join ( os . homedir ( ) , 'micromamba' , 'pkgs' ) ,
26
22
micromambaEnvs : path . join ( os . homedir ( ) , 'micromamba' , 'envs' )
27
23
}
28
24
29
25
// --- Utils ---
30
26
27
+ function getCondaArch ( ) {
28
+ const arch = {
29
+ [ [ 'darwin' , 'arm64' ] ] : 'osx-arm64' ,
30
+ [ [ 'darwin' , 'x64' ] ] : 'osx-64' ,
31
+ [ [ 'linux' , 'x64' ] ] : 'linux-64' ,
32
+ [ [ 'linux' , 'arm64' ] ] : 'linux-aarch64' ,
33
+ [ [ 'win32' , 'x64' ] ] : 'win-64'
34
+ } [ [ process . platform , process . arch ] ]
35
+ if ( ! arch ) {
36
+ throw Error ( `Platform ${ process . platform } /${ process . arch } not supported.` )
37
+ }
38
+ return arch
39
+ }
40
+
31
41
function getInputAsArray ( name ) {
32
42
// From https://github.com/actions/cache/blob/main/src/utils/actionUtils.ts
33
43
return core
@@ -57,7 +67,7 @@ function executePwsh (command) {
57
67
return executeShell ( 'powershell' , '-command' , `${ command } ; exit $LASTEXITCODE` )
58
68
}
59
69
60
- const executeLoginShell = MAMBA_PLATFORM === 'win ' ? executePwsh : executeBashLogin
70
+ const executeLoginShell = process . platform === 'win32 ' ? executePwsh : executeBashLogin
61
71
62
72
function micromambaCmd ( command , logLevel , micromambaExe = 'micromamba' ) {
63
73
return `${ micromambaExe } ${ command } ` + ( logLevel ? ` --log-level ${ logLevel } ` : '' )
@@ -137,7 +147,7 @@ async function installMicromambaPosix (micromambaUrl, logLevel) {
137
147
}
138
148
139
149
await executeBash ( `chmod u+x ${ PATHS . micromambaExe } ` )
140
- if ( MAMBA_PLATFORM === 'osx ' ) {
150
+ if ( process . platform === 'darwin ' ) {
141
151
// macos
142
152
await executeBash ( micromambaCmd ( 'shell init -s bash -p ~/micromamba -y' , logLevel , PATHS . micromambaExe ) )
143
153
// TODO need to fix a check in micromamba so that this works
@@ -237,11 +247,11 @@ async function installMicromamba (inputs, extraChannels) {
237
247
if ( ! fs . existsSync ( PATHS . micromambaBinFolder ) ) {
238
248
core . startGroup ( 'Install micromamba ...' )
239
249
const installer = {
240
- win : installMicromambaWindows ,
250
+ win32 : installMicromambaWindows ,
241
251
linux : installMicromambaPosix ,
242
- osx : installMicromambaPosix
243
- } [ MAMBA_PLATFORM ]
244
- const micromambaUrl = `${ inputs . installerUrl } /${ MAMBA_PLATFORM } -64 /${ inputs . micromambaVersion } `
252
+ darwin : installMicromambaPosix
253
+ } [ process . platform ]
254
+ const micromambaUrl = `${ inputs . installerUrl } /${ getCondaArch ( ) } /${ inputs . micromambaVersion } `
245
255
await installer ( micromambaUrl , inputs . logLevel )
246
256
core . exportVariable ( 'MAMBA_ROOT_PREFIX' , PATHS . micromambaRoot )
247
257
core . exportVariable ( 'MAMBA_EXE' , PATHS . micromambaExe )
@@ -256,7 +266,8 @@ async function installMicromamba (inputs, extraChannels) {
256
266
257
267
function isSelected ( item ) {
258
268
if ( / s e l \( .* \) : .* / gi. test ( item ) ) {
259
- return new RegExp ( 'sel\\(' + MAMBA_PLATFORM + '\\):.*' , 'gi' ) . test ( item )
269
+ const condaPlatform = getCondaArch ( ) . split ( '-' ) [ 0 ]
270
+ return new RegExp ( `sel\\(${ condaPlatform } \\):.*` , 'gi' ) . test ( item )
260
271
}
261
272
return true
262
273
}
@@ -283,7 +294,7 @@ async function createOrUpdateEnv (envName, envFilePath, extraSpecs, logLevel) {
283
294
if ( envFilePath ) {
284
295
cmd += ' -f ' + envFilePath
285
296
}
286
- if ( MAMBA_PLATFORM === 'win ' ) {
297
+ if ( process . platform === 'win32 ' ) {
287
298
await executePwsh ( cmd )
288
299
} else {
289
300
await executeBash ( cmd )
@@ -323,13 +334,14 @@ function determineEnvironmentName (inputs, envFilePath, envYaml) {
323
334
324
335
async function installEnvironment ( inputs , envFilePath , envYaml ) {
325
336
const envName = determineEnvironmentName ( inputs , envFilePath , envYaml )
337
+ const defaultCacheKey = `${ getCondaArch ( ) } ${ today ( ) } `
326
338
327
339
core . startGroup ( `Install environment ${ envName } from ${ envFilePath || '' } ${ inputs . extraSpecs || '' } ...` )
328
340
let downloadCacheHit , downloadCacheArgs , envCacheHit , envCacheArgs
329
341
330
342
// Try to load the entire env from cache.
331
343
if ( inputs . cacheEnv ) {
332
- let key = inputs . cacheEnvKey || ` ${ MAMBA_PLATFORM } - ${ process . arch } ${ today ( ) } `
344
+ let key = inputs . cacheEnvKey || defaultCacheKey
333
345
if ( envFilePath ) {
334
346
key += ' file: ' + sha256Short ( fs . readFileSync ( envFilePath ) )
335
347
}
@@ -344,7 +356,7 @@ async function installEnvironment (inputs, envFilePath, envYaml) {
344
356
if ( shouldTryDownloadCache ) {
345
357
// Try to restore the download cache.
346
358
if ( inputs . cacheDownloads ) {
347
- const key = inputs . cacheDownloadsKey || ` ${ MAMBA_PLATFORM } - ${ process . arch } ${ today ( ) } `
359
+ const key = inputs . cacheDownloadsKey || defaultCacheKey
348
360
downloadCacheArgs = [ PATHS . micromambaPkgs , `micromamba-pkgs ${ key } ` ]
349
361
downloadCacheHit = await tryRestoreCache ( ...downloadCacheArgs )
350
362
}
@@ -353,7 +365,7 @@ async function installEnvironment (inputs, envFilePath, envYaml) {
353
365
354
366
// Add micromamba activate to profile
355
367
const autoactivateCmd = `micromamba activate ${ envName } ;`
356
- if ( MAMBA_PLATFORM === 'win ' ) {
368
+ if ( process . platform === 'win32 ' ) {
357
369
const powershellAutoActivateEnv = `if (!(Test-Path $profile))
358
370
{
359
371
New-Item -path $profile -type "file" -value "${ autoactivateCmd } "
0 commit comments