-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
64 lines (56 loc) · 1.74 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
const core = require("@actions/core");
const exec = require("@actions/exec");
const setupPython = require("./src/setup-python");
async function run() {
try {
// Allows ncc to find assets to be included in the distribution
const src = __dirname + "/src";
core.debug(`src: ${src}`);
// Setup Python from the tool cache
setupPython("3.8.x", "x64");
// Install requirements
await exec.exec("pip", [
"install",
"-r",
`${src}/requirements.txt`,
"--no-index",
`--find-links=${__dirname}/vendor`
]);
// Fetch action inputs
const inputs = {
token: core.getInput("token") || process.env.GITHUB_TOKEN,
repository: core.getInput("repository") || process.env.GITHUB_REPOSITORY,
version: core.getInput("version") || process.env.VERSION,
path: core.getInput("path") || "./CHANGELOG.md",
action: core.getInput("action") || "release"
};
core.debug(`Inputs: ${JSON.stringify(inputs)}`);
// Set environment variables from inputs.
if (inputs.token) process.env.GITHUB_TOKEN = inputs.token;
if (inputs.repository) process.env.GITHUB_REPOSITORY = inputs.repository;
// Execute python script
const options = {};
let pythonOutput = "";
options.listeners = {
stdout: data => {
pythonOutput += data.toString();
}
};
await exec.exec(
"python",
[`${src}/main.py`, "-v", inputs.version],
options
);
// Process output
core.debug("OUTPUT");
core.debug(pythonOutput);
let outputJSON = JSON.parse(pythonOutput);
Object.keys(outputJSON).forEach(key => {
let value = outputJSON[key];
core.setOutput(key, value);
});
} catch (error) {
core.setFailed(error.message);
}
}
run();