Skip to content

Commit

Permalink
Add micromamba to PATH (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelzw authored Oct 11, 2023
1 parent e82a3fc commit 54d4d59
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 18 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,20 @@ jobs:
- run: |
test "${{ steps.setup-micromamba.outputs.environment-path }}" = ""
check-micromamba-on-path:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./
with:
init-shell: none
environment-file: test/environment.yml
- run: |
which micromamba | grep /home/runner/micromamba-bin/micromamba
type micromamba | grep "micromamba is /home/runner/micromamba-bin/micromamba"
which micromamba-shell | grep /home/runner/micromamba-bin/micromamba-shell
shell: bash -el {0}
# not properly testable
# https://github.com/actions/runner/issues/2347
# https://github.com/orgs/community/discussions/15452
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ With this, you don't need to initialize your shell and activate the environment
You can set this behavior by specifying the `generate-run-shell` input (defaults to `true`).

> [!NOTE]
> Under the hood, this shell wrapper runs `micromamba run -r <root-prefix-path> -n <env-name> <command>` with `<command>` being a file containing the part that you specify in the `run:` section of your workflow.
> Under the hood, this shell wrapper runs `micromamba run -r <root-prefix-path> -n <env-name> <command>` with `<command>` being a file containing the part that you specify in the `run:` section of your workflow.
> See the [official documentation](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#custom-shell) and [ADR 0277](https://github.com/actions/runner/blob/main/docs/adrs/0277-run-action-shell-options.md) for more information about how the `shell:` input works in GitHub Actions.

> [!WARNING]
Expand Down
11 changes: 6 additions & 5 deletions dist/index.js

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

7 changes: 4 additions & 3 deletions dist/post.js

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "setup-micromamba",
"version": "1.4.4",
"version": "1.5.0",
"private": true,
"description": "Action to setup micromamba",
"scripts": {
Expand Down
5 changes: 3 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const downloadMicromamba = (url: string) => {
.mkdir(path.dirname(options.micromambaBinPath), { recursive: true })
.then(() => downloadTool(url, options.micromambaBinPath))
.then((_downloadPath) => fs.chmod(options.micromambaBinPath, 0o755))
.then(() => core.addPath(path.dirname(options.micromambaBinPath)))
.then(() => core.info(`micromamba installed to ${options.micromambaBinPath}`))
.catch((err) => {
core.error(`Error installing micromamba: ${err.message}`)
Expand Down Expand Up @@ -135,9 +136,9 @@ $MAMBA_EXE run -r $MAMBA_ROOT_PREFIX -n $MAMBA_DEFAULT_ENV $1
.replace(/\$MAMBA_EXE/g, options.micromambaBinPath)
.replace(/\$MAMBA_ROOT_PREFIX/g, options.micromambaRootPath)
.replace(/\$MAMBA_DEFAULT_ENV/g, environmentName)
core.debug(`Writing micromamba run shell to ${PATHS.micromambaRunShell}`)
core.debug(`Writing micromamba run shell to ${options.micromambaRunShellPath}`)
core.debug(`File contents:\n"${file}"`)
return fs.writeFile(PATHS.micromambaRunShell, file, { encoding: 'utf8', mode: 0o755 })
return fs.writeFile(options.micromambaRunShellPath, file, { encoding: 'utf8', mode: 0o755 })
})
.finally(core.endGroup)
}
Expand Down
10 changes: 6 additions & 4 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const core = process.env.MOCKING ? coreMocked : coreDefault
export const PATHS = {
micromambaBin: path.join(os.homedir(), 'micromamba-bin', `micromamba${os.platform() === 'win32' ? '.exe' : ''}`),
micromambaRoot: path.join(os.homedir(), 'micromamba'),
micromambaRunShell: '/usr/local/bin/micromamba-shell',
bashProfile: path.join(os.homedir(), '.bash_profile'),
bashrc: path.join(os.homedir(), '.bashrc')
}
Expand Down Expand Up @@ -55,6 +54,7 @@ export type Options = Readonly<{
postCleanup: PostCleanupType
micromambaRootPath: string
micromambaBinPath: string
micromambaRunShellPath: string
}>

const postCleanupSchema = z.enum(['none', 'shell-init', 'environment', 'all'])
Expand Down Expand Up @@ -126,6 +126,9 @@ const inferOptions = (inputs: Inputs): Options => {
: inputs.initShell.includes('none')
? []
: (inputs.initShell as ShellType[])
const micromambaBinPath = inputs.micromambaBinPath
? path.resolve(untildify(inputs.micromambaBinPath))
: PATHS.micromambaBin

return {
...inputs,
Expand All @@ -144,9 +147,8 @@ const inferOptions = (inputs: Inputs): Options => {
condarcFile: inputs.condarcFile
? path.resolve(untildify(inputs.condarcFile))
: path.join(path.dirname(PATHS.micromambaBin), '.condarc'), // next to the micromamba binary -> easier cleanup
micromambaBinPath: inputs.micromambaBinPath
? path.resolve(untildify(inputs.micromambaBinPath))
: PATHS.micromambaBin,
micromambaBinPath,
micromambaRunShellPath: path.join(path.dirname(micromambaBinPath), 'micromamba-shell'),
micromambaRootPath: inputs.micromambaRootPath
? path.resolve(untildify(inputs.micromambaRootPath))
: PATHS.micromambaRoot
Expand Down
4 changes: 2 additions & 2 deletions src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as os from 'os'
import path from 'path'
import * as coreDefault from '@actions/core'
import { coreMocked } from './mocking'
import { PATHS, options } from './options'
import { options } from './options'
import { determineEnvironmentName } from './util'
import { shellDeinit } from './shell-init'
import { saveCacheDownloads } from './cache'
Expand All @@ -15,7 +15,7 @@ const removeMicromambaRunShell = () => {
return Promise.resolve()
}
core.info('Removing micromamba run shell ...')
return fs.rm(PATHS.micromambaRunShell)
return fs.rm(options.micromambaRunShellPath)
}

const uninstallEnvironment = () => {
Expand Down

0 comments on commit 54d4d59

Please sign in to comment.