-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.mjs
More file actions
46 lines (41 loc) · 1.3 KB
/
Copy pathindex.mjs
File metadata and controls
46 lines (41 loc) · 1.3 KB
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
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import fs from 'node:fs';
import {dirname, join} from 'node:path';
import {fileURLToPath} from 'node:url';
import tmp from 'tmp';
const __dirname = dirname(fileURLToPath(import.meta.url));
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(join(__dirname, "util.py"), "utf8");
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();