Skip to content

Commit

Permalink
Add warning for older micromamba versions (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelzw authored Jul 23, 2023
1 parent 0aaa0e4 commit b0afe4e
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 6 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
micromamba info | grep -q "environment : None (not found)"
shell: bash -el {0}
micromamba-old-version:
micromamba-old-version-1:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -53,6 +53,17 @@ jobs:
- run: test "$(micromamba --version)" = 1.4.5
shell: bash -el {0}

micromamba-old-version-2:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./
with:
micromamba-version: 1.2.0-1 # this will throw a warning
environment-file: 'test/environment.yml'
- run: test "$(micromamba --version)" = 1.2.0
shell: bash -el {0}

micromamba-shell:
strategy:
matrix:
Expand Down
21 changes: 20 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion dist/post.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,24 @@ const assertOptions = (options: Options) => {
assert(!options.createEnvironment || options.environmentFile !== undefined || options.environmentName !== undefined)
}

export const getRootPrefixFlagForInit = (options: Options) => {
// latest is always > 1.4.5-0
if (options.micromambaSource._tag === 'Left' && options.micromambaSource.left < '1.4.5-0') {
return '-p'
}
return '-r'
}

const checkForKnownIssues = (options: Options) => {
// micromamba 1.4.5 now uses -r for shell init instead of -p
// https://github.com/mamba-org/mamba/pull/2538
if (options.initShell && getRootPrefixFlagForInit(options) === '-p') {
core.warning(
'You are using a micromamba version < 1.4.5-0 and initialize the shell. This is behavior is deprecated. Please update the micromamba version. For further informations, see https://github.com/mamba-org/setup-micromamba/pull/107'
)
}
}

const getOptions = () => {
const inputs: Inputs = {
condarcFile: parseOrUndefined('condarc-file', z.string()),
Expand Down Expand Up @@ -209,6 +227,7 @@ const getOptions = () => {
validateInputs(inputs)
const options = inferOptions(inputs)
core.debug(`Inferred options: ${JSON.stringify(options)}`)
checkForKnownIssues(options)
assertOptions(options)
return options
}
Expand Down
16 changes: 13 additions & 3 deletions src/shell-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path'
import * as coreDefault from '@actions/core'
import { coreMocked } from './mocking'
import { execute, mambaRegexBlock, micromambaCmd } from './util'
import { PATHS, options } from './options'
import { PATHS, getRootPrefixFlagForInit, options } from './options'
import type { ShellType } from './options'

const core = process.env.MOCKING ? coreMocked : coreDefault
Expand Down Expand Up @@ -38,8 +38,13 @@ const removeMambaInitBlockFromBashProfile = () => {

export const shellInit = (shell: string) => {
core.startGroup(`Initialize micromamba for ${shell}.`)
const rootPrefixFlag = getRootPrefixFlagForInit(options)
const command = execute(
micromambaCmd(`shell init -s ${shell} -r ${options.micromambaRootPath}`, options.logLevel, options.condarcFile)
micromambaCmd(
`shell init -s ${shell} ${rootPrefixFlag} ${options.micromambaRootPath}`,
options.logLevel,
options.condarcFile
)
)
if (os.platform() === 'linux' && shell === 'bash') {
return command.then(copyMambaInitBlockToBashProfile).finally(core.endGroup)
Expand All @@ -49,8 +54,13 @@ export const shellInit = (shell: string) => {

export const shellDeinit = (shell: string) => {
core.startGroup(`Deinitialize micromamba for ${shell}`)
const rootPrefixFlag = getRootPrefixFlagForInit(options)
const command = execute(
micromambaCmd(`shell deinit -s ${shell} -r ${options.micromambaRootPath}`, options.logLevel, options.condarcFile)
micromambaCmd(
`shell deinit -s ${shell} ${rootPrefixFlag} ${options.micromambaRootPath}`,
options.logLevel,
options.condarcFile
)
)
if (os.platform() === 'linux' && shell === 'bash') {
return command.then(removeMambaInitBlockFromBashProfile).finally(core.endGroup)
Expand Down

0 comments on commit b0afe4e

Please sign in to comment.