-
Notifications
You must be signed in to change notification settings - Fork 66
/
setup.ts
127 lines (105 loc) · 3.7 KB
/
setup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import * as fs from "fs";
import * as core from "@actions/core";
import * as types from "./types";
import * as constants from "./constants";
import * as input from "./input";
import * as outputs from "./outputs";
import * as installer from "./installer";
import * as conda from "./conda";
import * as env from "./env";
import * as baseTools from "./base-tools";
/**
* Main conda setup method to handle all configuration options
*/
async function setupMiniconda(inputs: types.IActionInputs): Promise<void> {
let options: types.IDynamicOptions = {
useBundled: true,
useMamba: false,
mambaInInstaller: false,
condaConfig: { ...inputs.condaConfig },
};
await core.group(
`Creating bootstrap condarc file in ${constants.CONDARC_PATH}...`,
conda.bootstrapConfig
);
const installerInfo = await core.group("Ensuring installer...", () =>
installer.getLocalInstallerPath(inputs, options)
);
// The desired installer may change the options
options = { ...options, ...installerInfo.options };
const basePath = conda.condaBasePath(options);
if (installerInfo.localInstallerPath && !options.useBundled) {
options = await core.group("Running installer...", () =>
installer.runInstaller(
installerInfo.localInstallerPath,
basePath,
inputs,
options
)
);
}
if (!fs.existsSync(basePath)) {
throw Error(`No installed conda 'base' environment found at ${basePath}!` +
'If you are using this action in a self-hosted runner that already provides ' +
'its own Miniconda installation, please specify its location with a `CONDA` ' +
'environment variable. If you want us to download and install Miniconda or ' +
'Miniforge for you, add `miniconda-version: "latest"` or `miniforge-version: "latest"`, ' +
'respectively, to the parameters for this action.');
}
await core.group("Setup environment variables...", () =>
outputs.setPathVariables(options)
);
if (inputs.condaConfigFile) {
await core.group("Copying condarc file...", () => conda.copyConfig(inputs));
}
// For potential 'channels' that may alter configuration
options.envSpec = await core.group("Parsing environment...", () =>
env.getEnvSpec(inputs)
);
await core.group("Configuring conda package cache...", () =>
outputs.setCacheVariable(options)
);
await core.group("Applying initial configuration...", () =>
conda.applyCondaConfiguration(inputs, options)
);
await core.group("Initializing conda shell integration...", () =>
conda.condaInit(inputs, options)
);
// New base tools may change options
options = await core.group("Adding tools to 'base' env...", () =>
baseTools.installBaseTools(inputs, options)
);
if (inputs.activateEnvironment) {
await core.group("Ensuring environment...", () =>
env.ensureEnvironment(inputs, options)
);
}
if (core.getState(constants.OUTPUT_ENV_FILE_WAS_PATCHED)) {
await core.group(
"Maybe cleaning up patched environment-file...",
async () => {
const patchedEnv = core.getState(constants.OUTPUT_ENV_FILE_PATH);
if (inputs.cleanPatchedEnvironmentFile === "true") {
fs.unlinkSync(patchedEnv);
core.info(`Cleaned ${patchedEnv}`);
} else {
core.info(`Leaving ${patchedEnv} in place`);
}
}
);
}
core.info("setup-miniconda ran successfully");
}
/**
* Main `setup-miniconda` entry point
*/
async function run(): Promise<void> {
try {
const inputs = await core.group("Gathering Inputs...", input.parseInputs);
await setupMiniconda(inputs);
} catch (err) {
core.setFailed(err.message);
}
}
void run();
export default run;