Exit early if exitCode is 0 or 2

This commit is contained in:
James Pogran 2022-04-27 10:32:28 -04:00
parent 5cd44b38b7
commit 46ea660108
2 changed files with 32 additions and 21 deletions

24
dist/index1.js vendored
View file

@ -3040,7 +3040,7 @@ async function checkTerraform () {
return io.which(pathToCLI, check);
}
(async () => {
async () => {
// This will fail if Terraform isn't found, which is what we want
await checkTerraform();
@ -3049,14 +3049,14 @@ async function checkTerraform () {
const stderr = new OutputListener();
const listeners = {
stdout: stdout.listener,
stderr: stderr.listener
stderr: stderr.listener,
};
// Execute terraform and capture output
const args = process.argv.slice(2);
const options = {
listeners,
ignoreReturnCode: true
ignoreReturnCode: true,
};
const exitCode = await exec(pathToCLI, args, options);
core.debug(`Terraform exited with code ${exitCode}.`);
@ -3065,15 +3065,21 @@ async function checkTerraform () {
core.debug(`exitcode: ${exitCode}`);
// Set outputs, result, exitcode, and stderr
core.setOutput('stdout', stdout.contents);
core.setOutput('stderr', stderr.contents);
core.setOutput('exitcode', exitCode.toString(10));
core.setOutput("stdout", stdout.contents);
core.setOutput("stderr", stderr.contents);
core.setOutput("exitcode", exitCode.toString(10));
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;
}
// A non-zero exitCode is considered an error
if (exitCode !== 0) {
core.setFailed(`Terraform exited with code ${exitCode}.`);
}
})();
};
})();

View file

@ -12,7 +12,7 @@ async function checkTerraform () {
return io.which(pathToCLI, check);
}
(async () => {
async () => {
// This will fail if Terraform isn't found, which is what we want
await checkTerraform();
@ -21,14 +21,14 @@ async function checkTerraform () {
const stderr = new OutputListener();
const listeners = {
stdout: stdout.listener,
stderr: stderr.listener
stderr: stderr.listener,
};
// Execute terraform and capture output
const args = process.argv.slice(2);
const options = {
listeners,
ignoreReturnCode: true
ignoreReturnCode: true,
};
const exitCode = await exec(pathToCLI, args, options);
core.debug(`Terraform exited with code ${exitCode}.`);
@ -37,13 +37,18 @@ async function checkTerraform () {
core.debug(`exitcode: ${exitCode}`);
// Set outputs, result, exitcode, and stderr
core.setOutput('stdout', stdout.contents);
core.setOutput('stderr', stderr.contents);
core.setOutput('exitcode', exitCode.toString(10));
core.setOutput("stdout", stdout.contents);
core.setOutput("stderr", stderr.contents);
core.setOutput("exitcode", exitCode.toString(10));
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;
}
// A non-zero exitCode is considered an error
// An exit-code 2 may be returned when the '-detailed-exitcode' option is passed to plan. This denotes Success with non-empty diff (changes present).
if (exitCode !== 0 || exitCode !== 2 ) {
core.setFailed(`Terraform exited with code ${exitCode}.`);
}
})();
};