Split shell init and activation of test environment to remove spurious warning

This commit is contained in:
Gonzalo Peña-Castellanos
2026-04-01 21:49:04 -05:00
parent 685db287e3
commit 9c73b9ac1b
5 changed files with 253 additions and 190 deletions
+1
View File
@@ -1 +1,2 @@
dist/
coverage/
-1
View File
@@ -19,7 +19,6 @@ npm-check-updates
- Create a new release via "Draft a new release" button at the
[Release page](https://github.com/conda-incubator/setup-miniconda/releases):
- Choose a new tag like `vX.Y.Z` that targets the current main branch and that
is created on publish of the release
- Choose the title `Version X.Y.Z`
Generated Vendored
+106 -76
View File
@@ -54029,14 +54029,15 @@ function isDefaultEnvironment(envName, inputs, options) {
});
}
/**
* Initialize Conda
* Initialize conda shell integration for all shells, fix folder ownership
* on bundled installs, and remove/rename profile files.
*
* @param inputs - The parsed action inputs.
* @param options - The current dynamic options.
*/
function condaInit(inputs, options) {
return conda_awaiter(this, void 0, void 0, function* () {
let ownPath;
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 (IS_MAC) {
@@ -54103,81 +54104,106 @@ function condaInit(inputs, options) {
}
}
}
// PowerShell profiles
// NOTE: Using array.join() to prevent auto-formatters from adding indentation
const powerLines = [
"",
"# ----------------------------------------------------------------------------",
];
if (isValidActivate) {
powerLines.push("# Conda Setup Action: Custom activation", `conda activate "${inputs.activateEnvironment}"`);
}
powerLines.push("# ----------------------------------------------------------------------------");
const powerExtraText = powerLines.join("\n");
// Bash profiles
// NOTE: Using array.join() to prevent auto-formatters from adding indentation
const bashLines = [
"",
"# ----------------------------------------------------------------------------",
"# Conda Setup Action: Basic configuration",
"set -eo pipefail",
];
if (isValidActivate) {
bashLines.push("# Conda Setup Action: Custom activation", `conda activate "${inputs.activateEnvironment}"`, "# ----------------------------------------------------------------------------");
}
const bashExtraText = bashLines.join("\n");
// Xonsh profiles
// NOTE: Using array.join() to prevent auto-formatters from adding indentation
const xonshLines = [
"",
"# ----------------------------------------------------------------------------",
"# Conda Setup Action: Basic configuration",
"$RAISE_SUBPROC_ERROR = True", // equivalent to: set -e
"$XONSH_PIPEFAIL = True", // equivalent to: set -o pipefail
];
if (isValidActivate) {
xonshLines.push("# Conda Setup Action: Custom activation", `conda activate "${inputs.activateEnvironment}"`, "# ----------------------------------------------------------------------------");
}
const xonshExtraText = xonshLines.join("\n");
// Batch profiles
// NOTE: Using array.join() to prevent auto-formatters from adding indentation
const batchLines = [
"",
":: ---------------------------------------------------------------------------",
];
if (autoActivateDefault) {
batchLines.push(":: Conda Setup Action: Activate default environment", '@CALL "%CONDA_BAT%" activate');
}
if (isValidActivate) {
batchLines.push(":: Conda Setup Action: Custom activation", `@CALL "%CONDA_BAT%" activate "${inputs.activateEnvironment}"`);
}
batchLines.push(":: Conda Setup Action: Basic configuration", "@SETLOCAL EnableExtensions", "@SETLOCAL DisableDelayedExpansion", ":: ---------------------------------------------------------------------------");
const batchExtraText = batchLines.join("\n");
const shells = {
"~/.bash_profile": bashExtraText,
"~/.profile": bashExtraText,
"~/.zshrc": bashExtraText,
"~/.config/fish/config.fish": bashExtraText,
"~/.tcshrc": bashExtraText,
"~/.xonshrc": xonshExtraText,
"~/.config/powershell/profile.ps1": powerExtraText,
"~/Documents/PowerShell/profile.ps1": powerExtraText,
"~/Documents/WindowsPowerShell/profile.ps1": powerExtraText,
[external_path_namespaceObject.join(installationDirectory, "etc", "profile.d", "conda.sh")]: bashExtraText,
[external_path_namespaceObject.join(installationDirectory, "etc", "fish", "conf.d", "conda.fish")]: bashExtraText,
[external_path_namespaceObject.join(installationDirectory, "condabin", "conda_hook.bat")]: batchExtraText,
};
Object.keys(shells).forEach((key) => {
let filePath = key.replace("~", external_os_namespaceObject.homedir());
const text = shells[key];
if (external_fs_namespaceObject.existsSync(filePath)) {
info(`Append to "${filePath}":\n ${text} \n`);
external_fs_namespaceObject.appendFileSync(filePath, text);
}
});
}
});
}
/**
* Append activation commands to all shell profile files so that
* subsequent workflow steps start with the correct environment active.
*
* This must be called AFTER the target environment has been created,
* otherwise `.bat` wrappers (which source `conda_hook.bat`) would try
* to activate a non-existent environment during setup and emit false
* warnings (see #474).
*
* @param inputs - The parsed action inputs.
* @param options - The current dynamic options.
*/
function condaInitActivation(inputs, options) {
return conda_awaiter(this, void 0, void 0, function* () {
// Skip profile modifications when run-init is false (mirrors condaInit guard)
if (inputs.runInit == "false") {
info("Skipping activation profile modifications (run-init=false)");
return;
}
const isValidActivate = !!inputs.activateEnvironment &&
!(yield isDefaultEnvironment(inputs.activateEnvironment, inputs, options));
const autoActivateDefault = options.condaConfig.auto_activate === "true";
const installationDirectory = condaBasePath(inputs, options);
// PowerShell profiles
// NOTE: Using array.join() to prevent auto-formatters from adding indentation
const powerLines = [
"",
"# ----------------------------------------------------------------------------",
];
if (isValidActivate) {
powerLines.push("# Conda Setup Action: Custom activation", `conda activate "${inputs.activateEnvironment}"`);
}
powerLines.push("# ----------------------------------------------------------------------------");
const powerExtraText = powerLines.join("\n");
// Bash profiles
// NOTE: Using array.join() to prevent auto-formatters from adding indentation
const bashLines = [
"",
"# ----------------------------------------------------------------------------",
"# Conda Setup Action: Basic configuration",
"set -eo pipefail",
];
if (isValidActivate) {
bashLines.push("# Conda Setup Action: Custom activation", `conda activate "${inputs.activateEnvironment}"`, "# ----------------------------------------------------------------------------");
}
const bashExtraText = bashLines.join("\n");
// Xonsh profiles
// NOTE: Using array.join() to prevent auto-formatters from adding indentation
const xonshLines = [
"",
"# ----------------------------------------------------------------------------",
"# Conda Setup Action: Basic configuration",
"$RAISE_SUBPROC_ERROR = True", // equivalent to: set -e
"$XONSH_PIPEFAIL = True", // equivalent to: set -o pipefail
];
if (isValidActivate) {
xonshLines.push("# Conda Setup Action: Custom activation", `conda activate "${inputs.activateEnvironment}"`, "# ----------------------------------------------------------------------------");
}
const xonshExtraText = xonshLines.join("\n");
// Batch profiles
// NOTE: Using array.join() to prevent auto-formatters from adding indentation
const batchLines = [
"",
":: ---------------------------------------------------------------------------",
];
if (autoActivateDefault) {
batchLines.push(":: Conda Setup Action: Activate default environment", '@CALL "%CONDA_BAT%" activate');
}
if (isValidActivate) {
batchLines.push(":: Conda Setup Action: Custom activation", `@CALL "%CONDA_BAT%" activate "${inputs.activateEnvironment}"`);
}
batchLines.push(":: Conda Setup Action: Basic configuration", "@SETLOCAL EnableExtensions", "@SETLOCAL DisableDelayedExpansion", ":: ---------------------------------------------------------------------------");
const batchExtraText = batchLines.join("\n");
const shells = {
"~/.bash_profile": bashExtraText,
"~/.profile": bashExtraText,
"~/.zshrc": bashExtraText,
"~/.config/fish/config.fish": bashExtraText,
"~/.tcshrc": bashExtraText,
"~/.xonshrc": xonshExtraText,
"~/.config/powershell/profile.ps1": powerExtraText,
"~/Documents/PowerShell/profile.ps1": powerExtraText,
"~/Documents/WindowsPowerShell/profile.ps1": powerExtraText,
[external_path_namespaceObject.join(installationDirectory, "etc", "profile.d", "conda.sh")]: bashExtraText,
[external_path_namespaceObject.join(installationDirectory, "etc", "fish", "conf.d", "conda.fish")]: bashExtraText,
[external_path_namespaceObject.join(installationDirectory, "condabin", "conda_hook.bat")]: batchExtraText,
};
Object.keys(shells).forEach((key) => {
let filePath = key.replace("~", external_os_namespaceObject.homedir());
const text = shells[key];
if (external_fs_namespaceObject.existsSync(filePath)) {
info(`Append to "${filePath}":\n ${text} \n`);
external_fs_namespaceObject.appendFileSync(filePath, text);
}
});
});
}
;// CONCATENATED MODULE: ./src/outputs.ts
var outputs_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -59829,6 +59855,10 @@ function setupMiniconda(inputs) {
if (inputs.activateEnvironment && inputs.activateEnvironment !== "base") {
yield group("Ensuring environment...", () => ensureEnvironment(inputs, options));
}
// Activation profiles must be written AFTER the environment exists,
// otherwise .bat wrappers source conda_hook.bat and try to activate
// a non-existent environment, producing false warnings (#474).
yield group("Writing activation commands to shell profiles...", () => condaInitActivation(inputs, options));
if (getState(OUTPUT_ENV_FILE_WAS_PATCHED)) {
yield group("Maybe cleaning up patched environment-file...", () => setup_awaiter(this, void 0, void 0, function* () {
const patchedEnv = getState(OUTPUT_ENV_FILE_PATH);
+139 -113
View File
@@ -352,21 +352,17 @@ async function isDefaultEnvironment(
}
/**
* Initialize Conda
* Initialize conda shell integration for all shells, fix folder ownership
* on bundled installs, and remove/rename profile files.
*
* @param inputs - The parsed action inputs.
* @param options - The current dynamic options.
*/
export async function condaInit(
inputs: types.IActionInputs,
options: types.IDynamicOptions,
): Promise<void> {
let ownPath: string;
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) {
@@ -433,109 +429,139 @@ export async function condaInit(
}
}
}
// PowerShell profiles
// NOTE: Using array.join() to prevent auto-formatters from adding indentation
const powerLines: string[] = [
"",
"# ----------------------------------------------------------------------------",
];
if (isValidActivate) {
powerLines.push(
"# Conda Setup Action: Custom activation",
`conda activate "${inputs.activateEnvironment}"`,
);
}
powerLines.push(
"# ----------------------------------------------------------------------------",
);
const powerExtraText = powerLines.join("\n");
// Bash profiles
// NOTE: Using array.join() to prevent auto-formatters from adding indentation
const bashLines: string[] = [
"",
"# ----------------------------------------------------------------------------",
"# Conda Setup Action: Basic configuration",
"set -eo pipefail",
];
if (isValidActivate) {
bashLines.push(
"# Conda Setup Action: Custom activation",
`conda activate "${inputs.activateEnvironment}"`,
"# ----------------------------------------------------------------------------",
);
}
const bashExtraText = bashLines.join("\n");
// Xonsh profiles
// NOTE: Using array.join() to prevent auto-formatters from adding indentation
const xonshLines: string[] = [
"",
"# ----------------------------------------------------------------------------",
"# Conda Setup Action: Basic configuration",
"$RAISE_SUBPROC_ERROR = True", // equivalent to: set -e
"$XONSH_PIPEFAIL = True", // equivalent to: set -o pipefail
];
if (isValidActivate) {
xonshLines.push(
"# Conda Setup Action: Custom activation",
`conda activate "${inputs.activateEnvironment}"`,
"# ----------------------------------------------------------------------------",
);
}
const xonshExtraText = xonshLines.join("\n");
// Batch profiles
// NOTE: Using array.join() to prevent auto-formatters from adding indentation
const batchLines: string[] = [
"",
":: ---------------------------------------------------------------------------",
];
if (autoActivateDefault) {
batchLines.push(
":: Conda Setup Action: Activate default environment",
'@CALL "%CONDA_BAT%" activate',
);
}
if (isValidActivate) {
batchLines.push(
":: Conda Setup Action: Custom activation",
`@CALL "%CONDA_BAT%" activate "${inputs.activateEnvironment}"`,
);
}
batchLines.push(
":: Conda Setup Action: Basic configuration",
"@SETLOCAL EnableExtensions",
"@SETLOCAL DisableDelayedExpansion",
":: ---------------------------------------------------------------------------",
);
const batchExtraText = batchLines.join("\n");
const shells: types.IShells = {
"~/.bash_profile": bashExtraText,
"~/.profile": bashExtraText,
"~/.zshrc": bashExtraText,
"~/.config/fish/config.fish": bashExtraText,
"~/.tcshrc": bashExtraText,
"~/.xonshrc": xonshExtraText,
"~/.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,
};
Object.keys(shells).forEach((key) => {
let filePath: string = key.replace("~", os.homedir());
const text = shells[key];
if (fs.existsSync(filePath)) {
core.info(`Append to "${filePath}":\n ${text} \n`);
fs.appendFileSync(filePath, text);
}
});
}
}
/**
* Append activation commands to all shell profile files so that
* subsequent workflow steps start with the correct environment active.
*
* This must be called AFTER the target environment has been created,
* otherwise `.bat` wrappers (which source `conda_hook.bat`) would try
* to activate a non-existent environment during setup and emit false
* warnings (see #474).
*
* @param inputs - The parsed action inputs.
* @param options - The current dynamic options.
*/
export async function condaInitActivation(
inputs: types.IActionInputs,
options: types.IDynamicOptions,
): Promise<void> {
// Skip profile modifications when run-init is false (mirrors condaInit guard)
if (inputs.runInit == "false") {
core.info("Skipping activation profile modifications (run-init=false)");
return;
}
const isValidActivate =
!!inputs.activateEnvironment &&
!(await isDefaultEnvironment(inputs.activateEnvironment, inputs, options));
const autoActivateDefault: boolean =
options.condaConfig.auto_activate === "true";
const installationDirectory = condaBasePath(inputs, options);
// PowerShell profiles
// NOTE: Using array.join() to prevent auto-formatters from adding indentation
const powerLines: string[] = [
"",
"# ----------------------------------------------------------------------------",
];
if (isValidActivate) {
powerLines.push(
"# Conda Setup Action: Custom activation",
`conda activate "${inputs.activateEnvironment}"`,
);
}
powerLines.push(
"# ----------------------------------------------------------------------------",
);
const powerExtraText = powerLines.join("\n");
// Bash profiles
// NOTE: Using array.join() to prevent auto-formatters from adding indentation
const bashLines: string[] = [
"",
"# ----------------------------------------------------------------------------",
"# Conda Setup Action: Basic configuration",
"set -eo pipefail",
];
if (isValidActivate) {
bashLines.push(
"# Conda Setup Action: Custom activation",
`conda activate "${inputs.activateEnvironment}"`,
"# ----------------------------------------------------------------------------",
);
}
const bashExtraText = bashLines.join("\n");
// Xonsh profiles
// NOTE: Using array.join() to prevent auto-formatters from adding indentation
const xonshLines: string[] = [
"",
"# ----------------------------------------------------------------------------",
"# Conda Setup Action: Basic configuration",
"$RAISE_SUBPROC_ERROR = True", // equivalent to: set -e
"$XONSH_PIPEFAIL = True", // equivalent to: set -o pipefail
];
if (isValidActivate) {
xonshLines.push(
"# Conda Setup Action: Custom activation",
`conda activate "${inputs.activateEnvironment}"`,
"# ----------------------------------------------------------------------------",
);
}
const xonshExtraText = xonshLines.join("\n");
// Batch profiles
// NOTE: Using array.join() to prevent auto-formatters from adding indentation
const batchLines: string[] = [
"",
":: ---------------------------------------------------------------------------",
];
if (autoActivateDefault) {
batchLines.push(
":: Conda Setup Action: Activate default environment",
'@CALL "%CONDA_BAT%" activate',
);
}
if (isValidActivate) {
batchLines.push(
":: Conda Setup Action: Custom activation",
`@CALL "%CONDA_BAT%" activate "${inputs.activateEnvironment}"`,
);
}
batchLines.push(
":: Conda Setup Action: Basic configuration",
"@SETLOCAL EnableExtensions",
"@SETLOCAL DisableDelayedExpansion",
":: ---------------------------------------------------------------------------",
);
const batchExtraText = batchLines.join("\n");
const shells: types.IShells = {
"~/.bash_profile": bashExtraText,
"~/.profile": bashExtraText,
"~/.zshrc": bashExtraText,
"~/.config/fish/config.fish": bashExtraText,
"~/.tcshrc": bashExtraText,
"~/.xonshrc": xonshExtraText,
"~/.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,
};
Object.keys(shells).forEach((key) => {
let filePath: string = key.replace("~", os.homedir());
const text = shells[key];
if (fs.existsSync(filePath)) {
core.info(`Append to "${filePath}":\n ${text} \n`);
fs.appendFileSync(filePath, text);
}
});
}
+7
View File
@@ -90,6 +90,13 @@ async function setupMiniconda(inputs: types.IActionInputs): Promise<void> {
);
}
// Activation profiles must be written AFTER the environment exists,
// otherwise .bat wrappers source conda_hook.bat and try to activate
// a non-existent environment, producing false warnings (#474).
await core.group("Writing activation commands to shell profiles...", () =>
conda.condaInitActivation(inputs, options),
);
if (core.getState(constants.OUTPUT_ENV_FILE_WAS_PATCHED)) {
await core.group(
"Maybe cleaning up patched environment-file...",