forked from jannekem/run-python-script-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (38 loc) · 1.16 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
const core = require('@actions/core');
const exec = require('@actions/exec');
const fs = require('fs');
const tmp = require('tmp');
async function run() {
const script = core.getInput("script");
const util = core.getInput("util") === "true";
const failOnError = core.getInput("fail-on-error") === "true";
const utilityFunctions = fs.readFileSync(`${__dirname}/util.py`);
let stdout = "";
let stderr = "";
let errorStatus = "false";
const options = {};
options.listeners = {
stdout: (data) => {
stdout += data.toString();
},
stderr: (data) => {
stderr += data.toString();
}
};
tmp.setGracefulCleanup();
const filename = tmp.tmpNameSync({postfix: '.py'});
fs.writeFileSync(filename, util ? utilityFunctions + script : script);
try {
await exec.exec('python', [filename], options);
} catch (error) {
errorStatus = "true";
if (failOnError) {
core.setFailed(error);
}
} finally {
core.setOutput("stdout", stdout);
core.setOutput("stderr", stderr);
core.setOutput("error", errorStatus);
}
}
run();