forked from antifree/json-to-variables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (31 loc) · 1017 Bytes
/
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
const fs = require("fs");
const path = require("path");
const core = require("@actions/core");
try {
const fileName = core.getInput("filename", { required: true });
const prefix = core.getInput("prefix") || "json";
const fullPath = path.resolve(fileName);
core.info(`Processing file: ${fullPath}`);
const rawdata = fs.readFileSync(fullPath);
const rootObj = JSON.parse(rawdata);
const processVariable = (variable, name) => {
if (typeof variable === "undefined" || variable === null) {
return;
}
if (Array.isArray(variable)) {
variable.forEach((value, index) => {
processVariable(value, index);
});
} else if (typeof variable === "object") {
for (const field in variable) {
processVariable(variable[field], field);
}
} else {
core.info(`SET ENV '${name}' = ${variable}`);
core.exportVariable(name, variable.toString());
}
};
processVariable(rootObj, prefix);
} catch (error) {
core.setFailed(error.message);
}