Skip to content

Commit 21e0d20

Browse files
authored
Merge pull request #71 from mamba-org/aarch64
Fix #70: Support linux-aarch64 and osx-arm64
2 parents 34071ca + 23fc0a3 commit 21e0d20

File tree

2 files changed

+56
-32
lines changed

2 files changed

+56
-32
lines changed

dist/main/index.js

Lines changed: 28 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,34 @@ const cache = require('@actions/cache')
1010
const core = require('@actions/core')
1111
const exec = require('@actions/exec')
1212

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-
}
1713
const PATHS = {
1814
condarc: path.join(os.homedir(), '.condarc'),
1915
bashprofile: path.join(os.homedir(), '.bash_profile'),
2016
bashrc: path.join(os.homedir(), '.bashrc'),
2117
bashrcBak: path.join(os.homedir(), '.bashrc.actionbak'),
2218
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'),
2420
micromambaRoot: path.join(os.homedir(), 'micromamba'),
2521
micromambaPkgs: path.join(os.homedir(), 'micromamba', 'pkgs'),
2622
micromambaEnvs: path.join(os.homedir(), 'micromamba', 'envs')
2723
}
2824

2925
// --- Utils ---
3026

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+
3141
function getInputAsArray (name) {
3242
// From https://github.com/actions/cache/blob/main/src/utils/actionUtils.ts
3343
return core
@@ -57,7 +67,7 @@ function executePwsh (command) {
5767
return executeShell('powershell', '-command', `${command}; exit $LASTEXITCODE`)
5868
}
5969

60-
const executeLoginShell = MAMBA_PLATFORM === 'win' ? executePwsh : executeBashLogin
70+
const executeLoginShell = process.platform === 'win32' ? executePwsh : executeBashLogin
6171

6272
function micromambaCmd (command, logLevel, micromambaExe = 'micromamba') {
6373
return `${micromambaExe} ${command}` + (logLevel ? ` --log-level ${logLevel}` : '')
@@ -137,7 +147,7 @@ async function installMicromambaPosix (micromambaUrl, logLevel) {
137147
}
138148

139149
await executeBash(`chmod u+x ${PATHS.micromambaExe}`)
140-
if (MAMBA_PLATFORM === 'osx') {
150+
if (process.platform === 'darwin') {
141151
// macos
142152
await executeBash(micromambaCmd('shell init -s bash -p ~/micromamba -y', logLevel, PATHS.micromambaExe))
143153
// TODO need to fix a check in micromamba so that this works
@@ -237,11 +247,11 @@ async function installMicromamba (inputs, extraChannels) {
237247
if (!fs.existsSync(PATHS.micromambaBinFolder)) {
238248
core.startGroup('Install micromamba ...')
239249
const installer = {
240-
win: installMicromambaWindows,
250+
win32: installMicromambaWindows,
241251
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}`
245255
await installer(micromambaUrl, inputs.logLevel)
246256
core.exportVariable('MAMBA_ROOT_PREFIX', PATHS.micromambaRoot)
247257
core.exportVariable('MAMBA_EXE', PATHS.micromambaExe)
@@ -256,7 +266,8 @@ async function installMicromamba (inputs, extraChannels) {
256266

257267
function isSelected (item) {
258268
if (/sel\(.*\):.*/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)
260271
}
261272
return true
262273
}
@@ -283,7 +294,7 @@ async function createOrUpdateEnv (envName, envFilePath, extraSpecs, logLevel) {
283294
if (envFilePath) {
284295
cmd += ' -f ' + envFilePath
285296
}
286-
if (MAMBA_PLATFORM === 'win') {
297+
if (process.platform === 'win32') {
287298
await executePwsh(cmd)
288299
} else {
289300
await executeBash(cmd)
@@ -323,13 +334,14 @@ function determineEnvironmentName (inputs, envFilePath, envYaml) {
323334

324335
async function installEnvironment (inputs, envFilePath, envYaml) {
325336
const envName = determineEnvironmentName(inputs, envFilePath, envYaml)
337+
const defaultCacheKey = `${getCondaArch()} ${today()}`
326338

327339
core.startGroup(`Install environment ${envName} from ${envFilePath || ''} ${inputs.extraSpecs || ''}...`)
328340
let downloadCacheHit, downloadCacheArgs, envCacheHit, envCacheArgs
329341

330342
// Try to load the entire env from cache.
331343
if (inputs.cacheEnv) {
332-
let key = inputs.cacheEnvKey || `${MAMBA_PLATFORM}-${process.arch} ${today()}`
344+
let key = inputs.cacheEnvKey || defaultCacheKey
333345
if (envFilePath) {
334346
key += ' file: ' + sha256Short(fs.readFileSync(envFilePath))
335347
}
@@ -344,7 +356,7 @@ async function installEnvironment (inputs, envFilePath, envYaml) {
344356
if (shouldTryDownloadCache) {
345357
// Try to restore the download cache.
346358
if (inputs.cacheDownloads) {
347-
const key = inputs.cacheDownloadsKey || `${MAMBA_PLATFORM}-${process.arch} ${today()}`
359+
const key = inputs.cacheDownloadsKey || defaultCacheKey
348360
downloadCacheArgs = [PATHS.micromambaPkgs, `micromamba-pkgs ${key}`]
349361
downloadCacheHit = await tryRestoreCache(...downloadCacheArgs)
350362
}
@@ -353,7 +365,7 @@ async function installEnvironment (inputs, envFilePath, envYaml) {
353365

354366
// Add micromamba activate to profile
355367
const autoactivateCmd = `micromamba activate ${envName};`
356-
if (MAMBA_PLATFORM === 'win') {
368+
if (process.platform === 'win32') {
357369
const powershellAutoActivateEnv = `if (!(Test-Path $profile))
358370
{
359371
New-Item -path $profile -type "file" -value "${autoactivateCmd}"

0 commit comments

Comments
 (0)