From 54d4d5980e1a4aa7cdc8b050cf2d19b7e262ce18 Mon Sep 17 00:00:00 2001 From: Pavel Zwerschke Date: Wed, 11 Oct 2023 22:31:35 +0200 Subject: [PATCH] Add micromamba to PATH (#161) --- .github/workflows/test.yml | 14 ++++++++++++++ README.md | 2 +- dist/index.js | 11 ++++++----- dist/post.js | 7 ++++--- package.json | 2 +- src/main.ts | 5 +++-- src/options.ts | 10 ++++++---- src/post.ts | 4 ++-- 8 files changed, 37 insertions(+), 18 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8d57298..aefe85b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/README.md b/README.md index 614b02a..af664e2 100644 --- a/README.md +++ b/README.md @@ -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 -n ` with `` 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 -n ` with `` 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] diff --git a/dist/index.js b/dist/index.js index c8279b4..06cb844 100644 --- a/dist/index.js +++ b/dist/index.js @@ -83152,7 +83152,6 @@ var core2 = process.env.MOCKING ? coreMocked : coreDefault; var PATHS = { micromambaBin: path.join(os2.homedir(), "micromamba-bin", `micromamba${os2.platform() === "win32" ? ".exe" : ""}`), micromambaRoot: path.join(os2.homedir(), "micromamba"), - micromambaRunShell: "/usr/local/bin/micromamba-shell", bashProfile: path.join(os2.homedir(), ".bash_profile"), bashrc: path.join(os2.homedir(), ".bashrc") }; @@ -83193,6 +83192,7 @@ var inferOptions = (inputs) => { const micromambaSource = inputs.micromambaUrl ? (0, import_Either.right)(inputs.micromambaUrl) : (0, import_Either.left)(inputs.micromambaVersion || "latest"); const writeToCondarc = inputs.condarcFile === void 0; const initShell = !inputs.initShell ? ["bash"] : inputs.initShell.includes("none") ? [] : inputs.initShell; + const micromambaBinPath = inputs.micromambaBinPath ? path.resolve(untildify(inputs.micromambaBinPath)) : PATHS.micromambaBin; return { ...inputs, writeToCondarc, @@ -83208,7 +83208,8 @@ var inferOptions = (inputs) => { // use a different path than ~/.condarc to avoid messing up the user's condarc 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 }; }; @@ -83551,7 +83552,7 @@ var core6 = process.env.MOCKING ? coreMocked : coreDefault5; var downloadMicromamba = (url2) => { core6.startGroup("Install micromamba"); core6.debug(`Downloading micromamba from ${url2} ...`); - return import_promises.default.mkdir(import_path3.default.dirname(options.micromambaBinPath), { recursive: true }).then(() => (0, import_tool_cache.downloadTool)(url2, options.micromambaBinPath)).then((_downloadPath) => import_promises.default.chmod(options.micromambaBinPath, 493)).then(() => core6.info(`micromamba installed to ${options.micromambaBinPath}`)).catch((err) => { + return import_promises.default.mkdir(import_path3.default.dirname(options.micromambaBinPath), { recursive: true }).then(() => (0, import_tool_cache.downloadTool)(url2, options.micromambaBinPath)).then((_downloadPath) => import_promises.default.chmod(options.micromambaBinPath, 493)).then(() => core6.addPath(import_path3.default.dirname(options.micromambaBinPath))).then(() => core6.info(`micromamba installed to ${options.micromambaBinPath}`)).catch((err) => { core6.error(`Error installing micromamba: ${err.message}`); throw err; }).finally(core6.endGroup); @@ -83644,10 +83645,10 @@ $MAMBA_EXE run -r $MAMBA_ROOT_PREFIX -n $MAMBA_DEFAULT_ENV $1 `; return determineEnvironmentName(options.environmentName, options.environmentFile).then((environmentName) => { const file = micromambaRunShellContents.replace(/\$MAMBA_EXE/g, options.micromambaBinPath).replace(/\$MAMBA_ROOT_PREFIX/g, options.micromambaRootPath).replace(/\$MAMBA_DEFAULT_ENV/g, environmentName); - core6.debug(`Writing micromamba run shell to ${PATHS.micromambaRunShell}`); + core6.debug(`Writing micromamba run shell to ${options.micromambaRunShellPath}`); core6.debug(`File contents: "${file}"`); - return import_promises.default.writeFile(PATHS.micromambaRunShell, file, { encoding: "utf8", mode: 493 }); + return import_promises.default.writeFile(options.micromambaRunShellPath, file, { encoding: "utf8", mode: 493 }); }).finally(core6.endGroup); }; var addEnvironmentPathToOutput = () => { diff --git a/dist/post.js b/dist/post.js index 4914b33..62ced82 100644 --- a/dist/post.js +++ b/dist/post.js @@ -78415,7 +78415,6 @@ var core = process.env.MOCKING ? coreMocked : coreDefault; var PATHS = { micromambaBin: path.join(os2.homedir(), "micromamba-bin", `micromamba${os2.platform() === "win32" ? ".exe" : ""}`), micromambaRoot: path.join(os2.homedir(), "micromamba"), - micromambaRunShell: "/usr/local/bin/micromamba-shell", bashProfile: path.join(os2.homedir(), ".bash_profile"), bashrc: path.join(os2.homedir(), ".bashrc") }; @@ -78456,6 +78455,7 @@ var inferOptions = (inputs) => { const micromambaSource = inputs.micromambaUrl ? (0, import_Either.right)(inputs.micromambaUrl) : (0, import_Either.left)(inputs.micromambaVersion || "latest"); const writeToCondarc = inputs.condarcFile === void 0; const initShell = !inputs.initShell ? ["bash"] : inputs.initShell.includes("none") ? [] : inputs.initShell; + const micromambaBinPath = inputs.micromambaBinPath ? path.resolve(untildify(inputs.micromambaBinPath)) : PATHS.micromambaBin; return { ...inputs, writeToCondarc, @@ -78471,7 +78471,8 @@ var inferOptions = (inputs) => { // use a different path than ~/.condarc to avoid messing up the user's condarc 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 }; }; @@ -81409,7 +81410,7 @@ var removeMicromambaRunShell = () => { return Promise.resolve(); } core6.info("Removing micromamba run shell ..."); - return fs5.rm(PATHS.micromambaRunShell); + return fs5.rm(options.micromambaRunShellPath); }; var uninstallEnvironment = () => { return determineEnvironmentName(options.environmentName, options.environmentFile).then((environmentName) => { diff --git a/package.json b/package.json index e0b96a4..1b564e8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "setup-micromamba", - "version": "1.4.4", + "version": "1.5.0", "private": true, "description": "Action to setup micromamba", "scripts": { diff --git a/src/main.ts b/src/main.ts index 3e3651e..9b32944 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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}`) @@ -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) } diff --git a/src/options.ts b/src/options.ts index 8416c93..8904e34 100644 --- a/src/options.ts +++ b/src/options.ts @@ -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') } @@ -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']) @@ -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, @@ -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 diff --git a/src/post.ts b/src/post.ts index c796e55..6a9f7e3 100644 --- a/src/post.ts +++ b/src/post.ts @@ -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' @@ -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 = () => {