-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstackql.js
More file actions
54 lines (46 loc) · 1.79 KB
/
stackql.js
File metadata and controls
54 lines (46 loc) · 1.79 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
#!/usr/bin/env node
const io = require('@actions/io');
const core = require('@actions/core');
const { exec } = require('@actions/exec');
const OutputListener = require('./lib/output-listener');
const pathToCLI = require('./lib/stackql-bin');
async function checkStackQL () {
// Setting check to `true` will cause `which` to throw if stackql isn't found
const check = true;
return io.which(pathToCLI, check);
}
(async () => {
// This will fail if StackQL isn't found, which is what we want
await checkStackQL();
// Create listeners to receive output (in memory) as well
const stdout = new OutputListener();
const stderr = new OutputListener();
const listeners = {
stdout: stdout.listener,
stderr: stderr.listener
};
// Execute stackql and capture output
const args = process.argv.slice(2);
const options = {
listeners,
ignoreReturnCode: true
};
const exitCode = await exec(pathToCLI, args, options);
core.debug(`StackQL exited with code ${exitCode}.`);
core.debug(`stdout: ${stdout.contents}`);
core.debug(`stderr: ${stderr.contents}`);
core.debug(`exitcode: ${exitCode}`);
// Set outputs, result, exitcode, and stderr
core.setOutput('stdout', stdout.contents);
core.setOutput('stderr', stderr.contents);
if (exitCode === 0 || exitCode === 2) {
// A exitCode of 0 is considered a success
// An exitCode of 2 may be returned when the '-detailed-exitcode' option
// is passed to plan. This denotes Success with non-empty
// diff (changes present).
return;
}
// If we reach this point, it means that the exitCode was neither 0 nor 2,
// which denotes an error. We can still use stderr.contents to provide more information about the error.
core.setFailed(`StackQL exited with error code ${exitCode}. Details: ${stderr.contents}.`);
})();