-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
67 lines (58 loc) · 1.96 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
const core = require('@actions/core');
const github = require('@actions/github');
const createPlugin = require("@extism/extism");
async function actism(input, steps, wasi, outputType, test) {
// get the input and all the steps to run, pass the input to the first and start the pipeline
if (!input) {
input = core.getInput('input');
}
if (!steps) {
steps = core.getInput('steps');
}
if (!wasi) {
wasi = core.getBooleanInput('wasi');
}
if (!outputType) {
outputType = core.getInput('output_type');
}
steps = steps.trim();
outputType = outputType.trim();
// for each step, run the step() function in the module with the input from the previous step
let pipelineData = input;
for (const step of Steps(steps)) {
step.entrypoint = step.entrypoint.trim();
step.name = step.name.trim();
step.source = step.source.trim();
if (test) {
console.log("DEBUG:", step);
}
console.log(`Starting step: ${step.name} from ${step.source}`)
const plugin = await createPlugin(step.source, { useWasi: wasi });
const output = await plugin.call(step.entrypoint, pipelineData);
pipelineData = output.bytes();
}
// set the output from the final step to return from the action
let output = pipelineData;
if (outputType === "text") {
output = new TextDecoder().decode(pipelineData);
}
if (test) {
console.log(output);
} else {
core.setOutput('output', output);
}
}
const Steps = (input) => {
return input.split(/\r|\n/).map(line => {
if (line.length < 1) { return }
const [name, source, entrypoint = 'run' ] = line.split('|');
if (!name || !source) {
throw new Error(`Invalid step: ${line}. Must follow "name | source" format, where source can be URL or path. Optionally set a third "| entrypoint" to specify the export function called.`);
}
return { name, source, entrypoint };
})
}
actism().catch(e => {
core.setFailed(`Actism error: ${e}`);
});
module.exports = actism;