diff --git a/.github/workflows/example-16.yml b/.github/workflows/example-16.yml new file mode 100644 index 00000000..12978059 --- /dev/null +++ b/.github/workflows/example-16.yml @@ -0,0 +1,157 @@ +name: "Example 16: Default environment activation" + +on: + pull_request: + push: + branches: + - main + schedule: + # Note that cronjobs run on master/main by default + - cron: "0 0 * * *" + +jobs: + example-16-build: + # prevent cronjobs from running on forks + if: + (github.event_name == 'schedule' && github.repository == + 'conda-incubator/setup-miniconda') || (github.event_name != 'schedule') + name: + Build Ex16 (os=${{matrix.os}}, default env=${{ matrix.add-activation-env + == 'true' && 'default' || 'base' }}) + runs-on: ${{ matrix.os }}-latest + strategy: + fail-fast: false + matrix: + add-activation-env: ["false", "true"] + os: ["ubuntu", "windows"] + steps: + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + with: + persist-credentials: false + + - name: Set up Miniconda for installer builds + uses: ./ + with: + activate-environment: "" + auto-activate: false + + - name: Create installer + uses: conda-incubator/installer@2d2df0b03c6795f70e128c56403c7d084cca4fb8 # v0.1.0 + id: create-installer + with: + conda-root: ${{ env.CONDA }} + environment-yaml-string: | + channels: + - conda-forge + dependencies: + - constructor + variables: + ADD_ACTIVATION_ENV: '${{ matrix.add-activation-env }}' + EXT: ${{ matrix.os == 'windows' && 'exe' || 'sh' }} + input-directory: etc/example-installers/default-environment/ + + - name: Upload installer to Github artifact + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + path: ${{ steps.create-installer.outputs.artifacts-directory }}/* + name: + ex16-${{ matrix.os }}-${{ matrix.add-activation-env == 'false' && + 'no-' }}-activation-env + + example-16-test: + needs: [example-16-build] + name: + Test Ex16 (os=${{matrix.os}}, default env=${{ matrix.add-activation-env == + 'true' && 'default' || 'base' }}, auto-activate-base=${{ + matrix.auto-activate-base }}) + runs-on: ${{ matrix.os }}-latest + strategy: + fail-fast: false + matrix: + auto-activate-base: ["false", "true"] + add-activation-env: ["false", "true"] + os: ["ubuntu", "windows"] + steps: + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + with: + persist-credentials: false + + - name: Obtain artifact + uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 + with: + name: + ex16-${{ matrix.os }}-${{ matrix.add-activation-env == 'false' && + 'no-' }}-activation-env + path: ${{ runner.temp }}/_installer + + - name: Determine installer file name + id: installer-file + env: + ARTIFACTS_DIRECTORY: ${{ runner.temp }}/_installer + EXT: ${{ matrix.os == 'windows' && 'exe' || 'sh' }} + run: | + INSTALLER_FILE=$(find "${ARTIFACTS_DIRECTORY}" -name "*.${EXT}" | head -n 1) + echo "installer-file=${INSTALLER_FILE}" >> ${GITHUB_OUTPUT} + shell: bash + + - name: Run installation + uses: ./ + with: + activate-environment: "" + auto-activate-base: + ${{ matrix.auto-activate-base == 'true' && 'true' || + 'legacy-placeholder' }} + auto-activate: + ${{ matrix.auto-activate-base == 'true' && '' || 'true' }} + installation-dir: ${{ runner.temp }}/installer_test + installer-url: + file://${{ steps.installer-file.outputs.installer-file }} + + - name: Output conda info (bash) + env: + DEFAULT_ENV: ${{ matrix.add-activation-env && 'default' || 'base' }} + TEST_DIR: ${{ runner.temp }}/installer_output + run: | + mkdir -p ${TEST_DIR} + conda info --json > "${TEST_DIR}/bash.json" + shell: bash -el {0} + + - name: Output conda info (cmd.exe) + if: matrix.os == 'windows' + env: + TEST_DIR: ${{ runner.temp }}\installer_output + run: | + conda info --json > "%TEST_DIR%\cmd.exe.json" + shell: cmd /C CALL {0} + + - name: Output conda info (PowerShell) + if: matrix.os == 'windows' + env: + TEST_DIR: ${{ runner.temp }}\installer_output + run: conda info --json > "${env:TEST_DIR}\pwsh.json" + shell: pwsh + + - name: Test default environments + env: + DEFAULT_ENV: + ${{ matrix.add-activation-env == 'true' && matrix.auto-activate-base + == 'false' && 'default' || 'base' }} + TEST_DIR: ${{ runner.temp }}/installer_output + run: | + import json + import os + from pathlib import Path + + json_dir = Path(os.environ["TEST_DIR"]) + default_env_expected = os.environ["DEFAULT_ENV"] + incorrect_environments = {} + for file in json_dir.iterdir(): + conda_info = json.loads(file.read_text()) + default_env = conda_info.get("active_prefix_name") + if default_env != default_env_expected: + incorrect_environments[str(file.name).removesuffix(".json")] = default_env + if incorrect_environments: + raise AssertionError( + f"Found incorrect default environments: {incorrect_environments}" + ) + shell: python diff --git a/.github/workflows/example-3.yml b/.github/workflows/example-3.yml index c113cfd1..915373f6 100644 --- a/.github/workflows/example-3.yml +++ b/.github/workflows/example-3.yml @@ -38,7 +38,7 @@ jobs: environment-file: etc/example-environment.yml python-version: 3.8 condarc-file: etc/example-condarc.yml - auto-activate-base: false + auto-activate: false auto-update-conda: true - run: | conda info @@ -60,7 +60,7 @@ jobs: environment-file: etc/example-environment-no-name.yml python-version: 3.8 condarc-file: etc/example-condarc.yml - auto-activate-base: false + auto-activate: false auto-update-conda: true - run: | conda info diff --git a/README.md b/README.md index 3d03620d..e0c98830 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ possibility of automatically activating the `test` environment on all shells. | [Apple Silicon](#example-13-apple-silicon) | [![Apple Silicon][ex13-badge]][ex13] | | [Remove defaults](#example-14-remove-defaults-channel) | [![Remove defaults][ex14-badge]][ex14] | | [Linux ARM](#example-15-linux-arm) | [![Linux ARM][ex15-badge]][ex15] | +| Default environments | [![Default environments][ex16-badge]][ex16] | [ex1]: https://github.com/conda-incubator/setup-miniconda/actions/workflows/example-1.yml @@ -122,6 +123,10 @@ possibility of automatically activating the `test` environment on all shells. https://github.com/conda-incubator/setup-miniconda/actions/workflows/example-15.yml [ex15-badge]: https://github.com/conda-incubator/setup-miniconda/actions/workflows/example-15.yml/badge.svg?branch=main +[ex16]: + https://github.com/conda-incubator/setup-miniconda/actions/workflows/example-16.yml +[ex16-badge]: + https://github.com/conda-incubator/setup-miniconda/actions/workflows/example-16.yml/badge.svg?branch=main ## Other Workflows @@ -180,16 +185,16 @@ Miniconda installation. ### Activate `base` environment -If your specific workflow still needs to activate and use `base` you will need -to do **both** of: +If your specific workflow still needs to activate and use the default +environment, you will need to do **both**: - set `activate-environment` to an empty string -- set `auto-activate-base` to `true` +- set `auto-activate` to `true` ```yaml - uses: conda-incubator/setup-miniconda@v3 with: - auto-activate-base: true + auto-activate: true activate-environment: "" ``` @@ -330,7 +335,7 @@ jobs: environment-file: etc/example-environment.yml python-version: 3.5 condarc-file: etc/example-condarc.yml - auto-activate-base: false + auto-activate: false - run: | conda info conda list diff --git a/action.yml b/action.yml index 280bd608..808553d0 100644 --- a/action.yml +++ b/action.yml @@ -134,16 +134,27 @@ inputs: for more information.' required: false default: "" - auto-activate-base: + auto-activate: description: - 'Conda configuration. If you’d prefer that conda’s base environment not be - activated on startup, set the to "false". Default is "true". This setting - always overrides if set to "true" or "false". If you want to use the - "condarc-file" setting pass and empty string. See + 'Conda configuration. If you’d prefer that conda’s default environment not + be activated on startup, set the to "false". Default is "true". This + setting always overrides if set to "true" or "false". If you want to use + the "condarc-file" setting pass an empty string. See https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/ for more information.' required: false default: "true" + auto-activate-base: + description: + (deprecated in favor of `auto-activate`) 'Conda configuration. If you’d + prefer that conda’s base environment not be activated on startup, set the + to "false". Default is "true". This setting always overrides if set to + "true" or "false". If you want to use the "condarc-file" setting pass an + empty string. See + https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/ + for more information.' + required: false + default: "legacy-placeholder" auto-update-conda: description: 'Conda configuration. When "true", conda updates itself any time a user diff --git a/dist/delete/index.js b/dist/delete/index.js index b5c85339..23a60680 100644 --- a/dist/delete/index.js +++ b/dist/delete/index.js @@ -28667,7 +28667,7 @@ const RULES = [ (i, c) => !!(i.condaVersion && c.auto_update_conda === "true") && `only one of 'conda-version: ${i.condaVersion}' or 'auto-update-conda: true' may be provided`, (i) => !!(i.pythonVersion && !i.activateEnvironment) && - `'python-version: ${i.pythonVersion}' requires 'activate-environment: true'`, + `'python-version: ${i.pythonVersion}' requires 'activate-environment' to be set`, (i) => !!(i.minicondaVersion && i.miniforgeVersion) && `only one of 'miniconda-version: ${i.minicondaVersion}' or 'miniforge-version: ${i.miniforgeVersion}' may be provided`, (i) => !!(i.installerUrl && i.minicondaVersion) && @@ -28693,8 +28693,16 @@ function parseInputs() { // https://github.com/conda-incubator/setup-miniconda/issues/385 arch = "aarch64"; } + if (core.getInput("auto-activate-base") !== "legacy-placeholder") { + core.warning("`auto-activate-base` is deprecated. Please use `auto-activate`. " + + "If your installer does not use the `base` environment as the default environment, " + + "also add `activate-environment: base`."); + } const inputs = Object.freeze({ - activateEnvironment: core.getInput("activate-environment"), + activateEnvironment: core.getInput("auto-activate-base") === "true" && + core.getInput("activate-environment") === "" + ? "base" + : core.getInput("activate-environment"), architecture: arch, condaBuildVersion: core.getInput("conda-build-version"), condaConfigFile: core.getInput("condarc-file"), @@ -28714,11 +28722,14 @@ function parseInputs() { add_anaconda_token: core.getInput("add-anaconda-token"), add_pip_as_python_dependency: core.getInput("add-pip-as-python-dependency"), allow_softlinks: core.getInput("allow-softlinks"), - auto_activate_base: core.getInput("auto-activate-base"), + auto_activate: core.getInput("auto-activate-base") === "legacy-placeholder" + ? core.getInput("auto-activate") + : core.getInput("auto-activate-base"), auto_update_conda: core.getInput("auto-update-conda"), channel_alias: core.getInput("channel-alias"), channel_priority: core.getInput("channel-priority"), channels: core.getInput("channels"), + default_activation_env: "", // Needed for type definition show_channel_urls: core.getInput("show-channel-urls"), use_only_tar_bz2: core.getInput("use-only-tar-bz2"), solver: core.getInput("conda-solver"), diff --git a/dist/setup/index.js b/dist/setup/index.js index 4657164a..5bf76035 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -46959,25 +46959,19 @@ function applyCondaConfiguration(inputs, options) { yield condaCommand(["config", "--add", "pkgs_dirs", pkgsDir], inputs, options); } // auto_activate_base was renamed to auto_activate in 25.5.0 - core.info(`auto_activate: ${inputs.condaConfig.auto_activate_base}`); + core.info(`auto_activate: ${inputs.condaConfig.auto_activate}`); try { // 25.5.0+ - yield condaCommand([ - "config", - "--set", - "auto_activate", - inputs.condaConfig.auto_activate_base, - ], inputs, options); + yield condaCommand(["config", "--set", "auto_activate", inputs.condaConfig.auto_activate], inputs, options); } catch (err) { try { // <25.5.0 - core.warning("Using auto_activate_base is deprecated, please use auto_activate instead"); yield condaCommand([ "config", "--set", "auto_activate_base", - inputs.condaConfig.auto_activate_base, + inputs.condaConfig.auto_activate, ], inputs, options); } catch (err2) { @@ -46989,7 +46983,7 @@ function applyCondaConfiguration(inputs, options) { if (value.trim().length === 0 || key === "channels" || key === "pkgs_dirs" || - key === "auto_activate_base") { + key === "auto_activate") { continue; } core.info(`${key}: ${value}`); @@ -47006,15 +47000,47 @@ function applyCondaConfiguration(inputs, options) { }); } exports.applyCondaConfiguration = applyCondaConfiguration; +function _getFullEnvironmentPath(inputPathOrName, inputs, options) { + if (!inputPathOrName.includes("/")) { + // likely an environment name + const installationDirectory = condaBasePath(inputs, options); + if (utils.isBaseEnv(inputPathOrName)) { + return path.resolve(installationDirectory); + } + return path.resolve(installationDirectory, "envs", inputPathOrName); + } + if (inputPathOrName.startsWith("~/")) { + return path.resolve(os.homedir(), inputPathOrName.slice(2)); + } + return path.resolve(inputPathOrName); +} +/* + * Whether an environment is the default environment + */ +function isDefaultEnvironment(envName, inputs, options) { + return __awaiter(this, void 0, void 0, function* () { + if (envName === "") { + return false; + } + const configsOutput = (yield condaCommand(["config", "--show", "--json"], inputs, options, true)); + const config = JSON.parse(configsOutput); + if (config.default_activation_env) { + const defaultEnv = _getFullEnvironmentPath(config.default_activation_env, inputs, options); + const activationEnv = _getFullEnvironmentPath(envName, inputs, options); + return defaultEnv === activationEnv; + } + return utils.isBaseEnv(envName); + }); +} /** * Initialize Conda */ function condaInit(inputs, options) { return __awaiter(this, void 0, void 0, function* () { let ownPath; - const isValidActivate = !utils.isBaseEnv(inputs.activateEnvironment); - const autoActivateBase = options.condaConfig["auto_activate_base"] === "true" || - options.condaConfig["activate_environment"] === "base"; + const isValidActivate = !(yield isDefaultEnvironment(inputs.activateEnvironment, inputs, options)); + const autoActivateDefault = options.condaConfig.auto_activate === "true"; + const installationDirectory = condaBasePath(inputs, options); // Fix ownership of folders if (options.useBundled) { if (constants.IS_MAC) { @@ -47101,10 +47127,10 @@ function condaInit(inputs, options) { // Batch profiles let batchExtraText = ` :: ---------------------------------------------------------------------------`; - if (autoActivateBase) { + if (autoActivateDefault) { batchExtraText += ` - :: Conda Setup Action: Activate base - @CALL "%CONDA_BAT%" activate base`; + :: Conda Setup Action: Activate default environment + @CALL "%CONDA_BAT%" activate`; } if (isValidActivate) { batchExtraText += ` @@ -47116,7 +47142,6 @@ function condaInit(inputs, options) { @SETLOCAL EnableExtensions @SETLOCAL DisableDelayedExpansion :: ---------------------------------------------------------------------------`; - let extraShells; const shells = { "~/.bash_profile": bashExtraText, "~/.profile": bashExtraText, @@ -47127,25 +47152,13 @@ function condaInit(inputs, options) { "~/.config/powershell/profile.ps1": powerExtraText, "~/Documents/PowerShell/profile.ps1": powerExtraText, "~/Documents/WindowsPowerShell/profile.ps1": powerExtraText, + [path.join(installationDirectory, "etc", "profile.d", "conda.sh")]: bashExtraText, + [path.join(installationDirectory, "etc", "fish", "conf.d", "conda.fish")]: bashExtraText, + [path.join(installationDirectory, "condabin", "conda_hook.bat")]: batchExtraText, }; - if (options.useBundled) { - extraShells = { - "C:/Miniconda/etc/profile.d/conda.sh": bashExtraText, - "C:/Miniconda/etc/fish/conf.d/conda.fish": bashExtraText, - "C:/Miniconda/condabin/conda_hook.bat": batchExtraText, - }; - } - else { - extraShells = { - "~/miniconda3/etc/profile.d/conda.sh": bashExtraText, - "~/miniconda3/etc/fish/conf.d/conda.fish": bashExtraText, - "~/miniconda3/condabin/conda_hook.bat": batchExtraText, - }; - } - const allShells = Object.assign(Object.assign({}, shells), extraShells); - Object.keys(allShells).forEach((key) => { + Object.keys(shells).forEach((key) => { let filePath = key.replace("~", os.homedir()); - const text = allShells[key]; + const text = shells[key]; if (fs.existsSync(filePath)) { core.info(`Append to "${filePath}":\n ${text} \n`); fs.appendFileSync(filePath, text); @@ -47795,7 +47808,7 @@ const RULES = [ (i, c) => !!(i.condaVersion && c.auto_update_conda === "true") && `only one of 'conda-version: ${i.condaVersion}' or 'auto-update-conda: true' may be provided`, (i) => !!(i.pythonVersion && !i.activateEnvironment) && - `'python-version: ${i.pythonVersion}' requires 'activate-environment: true'`, + `'python-version: ${i.pythonVersion}' requires 'activate-environment' to be set`, (i) => !!(i.minicondaVersion && i.miniforgeVersion) && `only one of 'miniconda-version: ${i.minicondaVersion}' or 'miniforge-version: ${i.miniforgeVersion}' may be provided`, (i) => !!(i.installerUrl && i.minicondaVersion) && @@ -47821,8 +47834,16 @@ function parseInputs() { // https://github.com/conda-incubator/setup-miniconda/issues/385 arch = "aarch64"; } + if (core.getInput("auto-activate-base") !== "legacy-placeholder") { + core.warning("`auto-activate-base` is deprecated. Please use `auto-activate`. " + + "If your installer does not use the `base` environment as the default environment, " + + "also add `activate-environment: base`."); + } const inputs = Object.freeze({ - activateEnvironment: core.getInput("activate-environment"), + activateEnvironment: core.getInput("auto-activate-base") === "true" && + core.getInput("activate-environment") === "" + ? "base" + : core.getInput("activate-environment"), architecture: arch, condaBuildVersion: core.getInput("conda-build-version"), condaConfigFile: core.getInput("condarc-file"), @@ -47842,11 +47863,14 @@ function parseInputs() { add_anaconda_token: core.getInput("add-anaconda-token"), add_pip_as_python_dependency: core.getInput("add-pip-as-python-dependency"), allow_softlinks: core.getInput("allow-softlinks"), - auto_activate_base: core.getInput("auto-activate-base"), + auto_activate: core.getInput("auto-activate-base") === "legacy-placeholder" + ? core.getInput("auto-activate") + : core.getInput("auto-activate-base"), auto_update_conda: core.getInput("auto-update-conda"), channel_alias: core.getInput("channel-alias"), channel_priority: core.getInput("channel-priority"), channels: core.getInput("channels"), + default_activation_env: "", // Needed for type definition show_channel_urls: core.getInput("show-channel-urls"), use_only_tar_bz2: core.getInput("use-only-tar-bz2"), solver: core.getInput("conda-solver"), diff --git a/etc/example-installers/default-environment/construct.yaml b/etc/example-installers/default-environment/construct.yaml new file mode 100644 index 00000000..c1c8feed --- /dev/null +++ b/etc/example-installers/default-environment/construct.yaml @@ -0,0 +1,20 @@ +{% set ext = os.environ.get("EXT", "sh") %} +{% set add_default_activation_env = os.environ.get("ADD_ACTIVATION_ENV", "false") == "true" %} + +name: DefaultEnv +installer_type: {{ ext }} +version: 1.0.0 +channels: + - conda-forge +specs: + - conda >=25.5.0 +extra_envs: + default: + specs: + - python +condarc: + channels: + - conda-forge +{% if add_default_activation_env %} + default_activation_env: default +{% endif %} diff --git a/src/conda.ts b/src/conda.ts index 340d1c93..4bd37921 100644 --- a/src/conda.ts +++ b/src/conda.ts @@ -241,31 +241,23 @@ export async function applyCondaConfiguration( ); } // auto_activate_base was renamed to auto_activate in 25.5.0 - core.info(`auto_activate: ${inputs.condaConfig.auto_activate_base}`); + core.info(`auto_activate: ${inputs.condaConfig.auto_activate}`); try { // 25.5.0+ await condaCommand( - [ - "config", - "--set", - "auto_activate", - inputs.condaConfig.auto_activate_base, - ], + ["config", "--set", "auto_activate", inputs.condaConfig.auto_activate], inputs, options, ); } catch (err) { try { // <25.5.0 - core.warning( - "Using auto_activate_base is deprecated, please use auto_activate instead", - ); await condaCommand( [ "config", "--set", "auto_activate_base", - inputs.condaConfig.auto_activate_base, + inputs.condaConfig.auto_activate, ], inputs, options, @@ -281,7 +273,7 @@ export async function applyCondaConfiguration( value.trim().length === 0 || key === "channels" || key === "pkgs_dirs" || - key === "auto_activate_base" + key === "auto_activate" ) { continue; } @@ -298,6 +290,55 @@ export async function applyCondaConfiguration( await condaCommand(["config", "--show"], inputs, options); } +function _getFullEnvironmentPath( + inputPathOrName: string, + inputs: types.IActionInputs, + options: types.IDynamicOptions, +): string { + if (!inputPathOrName.includes("/")) { + // likely an environment name + const installationDirectory = condaBasePath(inputs, options); + if (utils.isBaseEnv(inputPathOrName)) { + return path.resolve(installationDirectory); + } + return path.resolve(installationDirectory, "envs", inputPathOrName); + } + if (inputPathOrName.startsWith("~/")) { + return path.resolve(os.homedir(), inputPathOrName.slice(2)); + } + return path.resolve(inputPathOrName); +} + +/* + * Whether an environment is the default environment + */ +async function isDefaultEnvironment( + envName: string, + inputs: types.IActionInputs, + options: types.IDynamicOptions, +): Promise { + if (envName === "") { + return false; + } + const configsOutput = (await condaCommand( + ["config", "--show", "--json"], + inputs, + options, + true, + )) as string; + const config = JSON.parse(configsOutput) as types.ICondaConfig; + if (config.default_activation_env) { + const defaultEnv = _getFullEnvironmentPath( + config.default_activation_env, + inputs, + options, + ); + const activationEnv = _getFullEnvironmentPath(envName, inputs, options); + return defaultEnv === activationEnv; + } + return utils.isBaseEnv(envName); +} + /** * Initialize Conda */ @@ -306,10 +347,14 @@ export async function condaInit( options: types.IDynamicOptions, ): Promise { let ownPath: string; - const isValidActivate = !utils.isBaseEnv(inputs.activateEnvironment); - const autoActivateBase: boolean = - options.condaConfig["auto_activate_base"] === "true" || - options.condaConfig["activate_environment"] === "base"; + const isValidActivate = !(await isDefaultEnvironment( + inputs.activateEnvironment, + inputs, + options, + )); + const autoActivateDefault: boolean = + options.condaConfig.auto_activate === "true"; + const installationDirectory = condaBasePath(inputs, options); // Fix ownership of folders if (options.useBundled) { @@ -400,10 +445,10 @@ export async function condaInit( // Batch profiles let batchExtraText = ` :: ---------------------------------------------------------------------------`; - if (autoActivateBase) { + if (autoActivateDefault) { batchExtraText += ` - :: Conda Setup Action: Activate base - @CALL "%CONDA_BAT%" activate base`; + :: Conda Setup Action: Activate default environment + @CALL "%CONDA_BAT%" activate`; } if (isValidActivate) { batchExtraText += ` @@ -416,7 +461,6 @@ export async function condaInit( @SETLOCAL DisableDelayedExpansion :: ---------------------------------------------------------------------------`; - let extraShells: types.IShells; const shells: types.IShells = { "~/.bash_profile": bashExtraText, "~/.profile": bashExtraText, @@ -427,24 +471,16 @@ export async function condaInit( "~/.config/powershell/profile.ps1": powerExtraText, "~/Documents/PowerShell/profile.ps1": powerExtraText, "~/Documents/WindowsPowerShell/profile.ps1": powerExtraText, + [path.join(installationDirectory, "etc", "profile.d", "conda.sh")]: + bashExtraText, + [path.join(installationDirectory, "etc", "fish", "conf.d", "conda.fish")]: + bashExtraText, + [path.join(installationDirectory, "condabin", "conda_hook.bat")]: + batchExtraText, }; - if (options.useBundled) { - extraShells = { - "C:/Miniconda/etc/profile.d/conda.sh": bashExtraText, - "C:/Miniconda/etc/fish/conf.d/conda.fish": bashExtraText, - "C:/Miniconda/condabin/conda_hook.bat": batchExtraText, - }; - } else { - extraShells = { - "~/miniconda3/etc/profile.d/conda.sh": bashExtraText, - "~/miniconda3/etc/fish/conf.d/conda.fish": bashExtraText, - "~/miniconda3/condabin/conda_hook.bat": batchExtraText, - }; - } - const allShells: types.IShells = { ...shells, ...extraShells }; - Object.keys(allShells).forEach((key) => { + Object.keys(shells).forEach((key) => { let filePath: string = key.replace("~", os.homedir()); - const text = allShells[key]; + const text = shells[key]; if (fs.existsSync(filePath)) { core.info(`Append to "${filePath}":\n ${text} \n`); fs.appendFileSync(filePath, text); diff --git a/src/input.ts b/src/input.ts index 293a182d..ff723834 100644 --- a/src/input.ts +++ b/src/input.ts @@ -51,7 +51,7 @@ const RULES: IRule[] = [ `only one of 'conda-version: ${i.condaVersion}' or 'auto-update-conda: true' may be provided`, (i) => !!(i.pythonVersion && !i.activateEnvironment) && - `'python-version: ${i.pythonVersion}' requires 'activate-environment: true'`, + `'python-version: ${i.pythonVersion}' requires 'activate-environment' to be set`, (i) => !!(i.minicondaVersion && i.miniforgeVersion) && `only one of 'miniconda-version: ${i.minicondaVersion}' or 'miniforge-version: ${i.miniforgeVersion}' may be provided`, @@ -93,8 +93,19 @@ export async function parseInputs(): Promise { // https://github.com/conda-incubator/setup-miniconda/issues/385 arch = "aarch64"; } + if (core.getInput("auto-activate-base") !== "legacy-placeholder") { + core.warning( + "`auto-activate-base` is deprecated. Please use `auto-activate`. " + + "If your installer does not use the `base` environment as the default environment, " + + "also add `activate-environment: base`.", + ); + } const inputs: types.IActionInputs = Object.freeze({ - activateEnvironment: core.getInput("activate-environment"), + activateEnvironment: + core.getInput("auto-activate-base") === "true" && + core.getInput("activate-environment") === "" + ? "base" + : core.getInput("activate-environment"), architecture: arch, condaBuildVersion: core.getInput("conda-build-version"), condaConfigFile: core.getInput("condarc-file"), @@ -116,11 +127,15 @@ export async function parseInputs(): Promise { "add-pip-as-python-dependency", ), allow_softlinks: core.getInput("allow-softlinks"), - auto_activate_base: core.getInput("auto-activate-base"), + auto_activate: + core.getInput("auto-activate-base") === "legacy-placeholder" + ? core.getInput("auto-activate") + : core.getInput("auto-activate-base"), auto_update_conda: core.getInput("auto-update-conda"), channel_alias: core.getInput("channel-alias"), channel_priority: core.getInput("channel-priority"), channels: core.getInput("channels"), + default_activation_env: "", // Needed for type definition show_channel_urls: core.getInput("show-channel-urls"), use_only_tar_bz2: core.getInput("use-only-tar-bz2"), solver: core.getInput("conda-solver"), diff --git a/src/types.ts b/src/types.ts index d0df6ea9..f79961d8 100644 --- a/src/types.ts +++ b/src/types.ts @@ -56,11 +56,12 @@ export interface ICondaConfig { add_anaconda_token: string; add_pip_as_python_dependency: string; allow_softlinks: string; - auto_activate_base: string; + auto_activate: string; auto_update_conda: string; channel_alias: string; channel_priority: string; channels: string; + default_activation_env: string; show_channel_urls: string; use_only_tar_bz2: string; always_yes: string;