-
Notifications
You must be signed in to change notification settings - Fork 69
/
index.ts
76 lines (67 loc) · 2.22 KB
/
index.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
import * as types from "../types";
import * as core from "@actions/core";
import * as conda from "../conda";
import { updateConda } from "./update-conda";
import { updateMamba } from "./update-mamba";
import { updatePython } from "./update-python";
import { updateCondaBuild } from "./update-conda-build";
/**
* The providers of tool updates: order isn't _really_ important
*
* ### Note
* To add a new tool provider,
* - implement IToolProvider and add it here
* - probably add inputs to `../../action.yaml`
* - add any new RULEs in ../input.ts, for example if certain inputs make no sense
* - add a test!
*/
const TOOL_PROVIDERS: types.IToolProvider[] = [
updateConda,
updateMamba,
updatePython,
updateCondaBuild,
];
/**
* Update the 'base' env with relevant tools
*
* Do this in one step to avoid multiple solves
*/
export async function installBaseTools(
inputs: types.IActionInputs,
options: types.IDynamicOptions,
) {
let tools = [];
let postInstallOptions = { ...options };
let postInstallActions = [];
for (const provider of TOOL_PROVIDERS) {
core.info(`Do we need to ${provider.label}?`);
if (await provider.provides(inputs, options)) {
core.info(`... we will ${provider.label}.`);
const toolUpdates = await provider.toolPackages(inputs, options);
tools.push(...toolUpdates.tools);
postInstallOptions = { ...postInstallOptions, ...toolUpdates.options };
if (provider.postInstall) {
core.info(
`... we will perform post-install steps after we ${provider.label}.`,
);
postInstallActions.push(provider.postInstall);
}
}
}
if (tools.length) {
await conda.condaCommand(["install", "--name", "base", ...tools], options);
// *Now* use the new options, as we may have a new conda/mamba with more supported
// options that previously failed
await conda.applyCondaConfiguration(inputs, postInstallOptions);
} else {
core.info("No tools were installed in 'base' env.");
}
if (postInstallActions.length) {
for (const action of postInstallActions) {
await action(inputs, postInstallOptions);
}
} else {
core.info("No post-install actions were taken on 'base' env.");
}
return postInstallOptions;
}