-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
68 lines (61 loc) · 1.66 KB
/
index.js
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
const core = require("@actions/core");
const exec = require("@actions/exec");
async function run() {
// set up listeners
let myOutput = "";
let myError = "";
const options = {};
options.listeners = {
stdout: (data) => {
myOutput += data.toString();
core.info(data.toString());
},
stderr: (data) => {
myError += data.toString();
}
};
// set up workdir
const workdir = core.getInput("project_directory");
if (workdir) {
options.cwd = workdir;
}
// fetch arguments for command
// skip "parallel"
// todo: can I extract these inputNames from the action.yml?
const inputNames = [
"query", "query_namespace", "query_name", "config", "src", "runner", "engine",
"platform", "parallel", "config_mod", "target", "setup"
]
const booleanInputs = ["parallel"]
const multilineInputs = ["config_mod"]
const inputArgs = inputNames.flatMap(function(argName) {
const value = core.getInput(argName)
if (value == "") {
return [];
} else if (booleanInputs.indexOf(argName) >= 0) {
if (value.toLowerCase() == "true") {
return ["--" + argName];
} else {
return [];
}
} else if (multilineInputs.indexOf(argName) >= 0) {
const values = core.getMultilineInput(argName)
return values.flatMap(function(value) {
return ["--" + argName, value];
})
} else {
return ["--" + argName, value];
}
})
let args = ["ns", "build"].concat(inputArgs);
// run command
try {
await exec.exec("viash", args, options);
} catch (error) {
core.setFailed(myError);
return;
}
// pass output
core.setOutput("output", myOutput);
}
run();