Repository navigation
Expand file tree
/
Copy pathutils.js
More file actions
86 lines (74 loc) · 1.95 KB
/
Copy pathutils.js
File metadata and controls
86 lines (74 loc) · 1.95 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
function setupAuth(core) {
const fs = require("fs");
let auth;
const fileName = process.env.AUTH_FILE_PATH;
const authStr = process.env.AUTH_STR;
if (!checkEnvVarValid(fileName) && !checkEnvVarValid(authStr)) {
core.setFailed("Either AUTH_FILE_PATH or AUTH_STR must be set.");
return;
}
if (checkEnvVarValid(fileName)) {
try {
// Read the contents of the JSON file into a string
auth = fs.readFileSync(fileName, "utf-8");
} catch (error) {
core.error(error);
core.setFailed(`Cannot find auth file ${fileName}`);
return;
}
}
if (checkEnvVarValid(authStr)) {
auth = authStr
}
core.info("Setting AUTH environment variable...");
core.exportVariable("AUTH", auth);
}
async function getStackqlCommand(core) {
if (!checkEnvVarValid(process.env.AUTH)) {
core.setFailed("Cannot find AUTH environment variable when executing stackql");
return;
}
let [query, queryFilePath, auth, output = "json"] = [
process.env.QUERY,
process.env.QUERY_FILE_PATH,
process.env.AUTH,
process.env.OUTPUT,
];
if (!checkEnvVarValid(query) && !checkEnvVarValid(queryFilePath)) {
core.setFailed("Either query or query_file_path need to be set");
return;
}
let args = [];
if (queryFilePath) {
args = [
"exec",
"-i",
queryFilePath,
`--auth='${auth}'`,
`--output='${output}'`
];
}
if (query) {
args = ["exec", `"${query}"`, `--auth='${auth}'`, `--output='${output}'`];
}
try {
core.exportVariable('STACKQL_COMMAND', `stackql ${args.join(" ")}`)
} catch (error) {
core.error(error);
core.setFailed("Error when executing stackql");
}
}
/**
* Checking if environment variable is not empty or undefined
* @param {*} variable
*/
const checkEnvVarValid = (variable) => {
if (!variable || variable === "" || variable === "undefined") {
return false;
}
return true;
};
module.exports = {
setupAuth,
getStackqlCommand,
};