Skip to content

Commit 46ea660

Browse files
committed
Exit early if exitCode is 0 or 2
1 parent 5cd44b3 commit 46ea660

File tree

2 files changed

+32
-21
lines changed

2 files changed

+32
-21
lines changed

dist/index1.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3040,7 +3040,7 @@ async function checkTerraform () {
30403040
return io.which(pathToCLI, check);
30413041
}
30423042

3043-
(async () => {
3043+
async () => {
30443044
// This will fail if Terraform isn't found, which is what we want
30453045
await checkTerraform();
30463046

@@ -3049,14 +3049,14 @@ async function checkTerraform () {
30493049
const stderr = new OutputListener();
30503050
const listeners = {
30513051
stdout: stdout.listener,
3052-
stderr: stderr.listener
3052+
stderr: stderr.listener,
30533053
};
30543054

30553055
// Execute terraform and capture output
30563056
const args = process.argv.slice(2);
30573057
const options = {
30583058
listeners,
3059-
ignoreReturnCode: true
3059+
ignoreReturnCode: true,
30603060
};
30613061
const exitCode = await exec(pathToCLI, args, options);
30623062
core.debug(`Terraform exited with code ${exitCode}.`);
@@ -3065,15 +3065,21 @@ async function checkTerraform () {
30653065
core.debug(`exitcode: ${exitCode}`);
30663066

30673067
// Set outputs, result, exitcode, and stderr
3068-
core.setOutput('stdout', stdout.contents);
3069-
core.setOutput('stderr', stderr.contents);
3070-
core.setOutput('exitcode', exitCode.toString(10));
3068+
core.setOutput("stdout", stdout.contents);
3069+
core.setOutput("stderr", stderr.contents);
3070+
core.setOutput("exitcode", exitCode.toString(10));
3071+
3072+
if (exitCode === 0 || exitCode === 2) {
3073+
// A exitCode of 0 is considered a success
3074+
// An exitCode of 2 may be returned when the '-detailed-exitcode' option
3075+
// is passed to plan. This denotes Success with non-empty
3076+
// diff (changes present).
3077+
return;
3078+
}
30713079

30723080
// A non-zero exitCode is considered an error
3073-
if (exitCode !== 0) {
3074-
core.setFailed(`Terraform exited with code ${exitCode}.`);
3075-
}
3076-
})();
3081+
core.setFailed(`Terraform exited with code ${exitCode}.`);
3082+
};
30773083

30783084
})();
30793085

wrapper/terraform.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async function checkTerraform () {
1212
return io.which(pathToCLI, check);
1313
}
1414

15-
(async () => {
15+
async () => {
1616
// This will fail if Terraform isn't found, which is what we want
1717
await checkTerraform();
1818

@@ -21,14 +21,14 @@ async function checkTerraform () {
2121
const stderr = new OutputListener();
2222
const listeners = {
2323
stdout: stdout.listener,
24-
stderr: stderr.listener
24+
stderr: stderr.listener,
2525
};
2626

2727
// Execute terraform and capture output
2828
const args = process.argv.slice(2);
2929
const options = {
3030
listeners,
31-
ignoreReturnCode: true
31+
ignoreReturnCode: true,
3232
};
3333
const exitCode = await exec(pathToCLI, args, options);
3434
core.debug(`Terraform exited with code ${exitCode}.`);
@@ -37,13 +37,18 @@ async function checkTerraform () {
3737
core.debug(`exitcode: ${exitCode}`);
3838

3939
// Set outputs, result, exitcode, and stderr
40-
core.setOutput('stdout', stdout.contents);
41-
core.setOutput('stderr', stderr.contents);
42-
core.setOutput('exitcode', exitCode.toString(10));
40+
core.setOutput("stdout", stdout.contents);
41+
core.setOutput("stderr", stderr.contents);
42+
core.setOutput("exitcode", exitCode.toString(10));
4343

44-
// A non-zero exitCode is considered an error
45-
// 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).
46-
if (exitCode !== 0 || exitCode !== 2 ) {
47-
core.setFailed(`Terraform exited with code ${exitCode}.`);
44+
if (exitCode === 0 || exitCode === 2) {
45+
// A exitCode of 0 is considered a success
46+
// An exitCode of 2 may be returned when the '-detailed-exitcode' option
47+
// is passed to plan. This denotes Success with non-empty
48+
// diff (changes present).
49+
return;
4850
}
49-
})();
51+
52+
// A non-zero exitCode is considered an error
53+
core.setFailed(`Terraform exited with code ${exitCode}.`);
54+
};

0 commit comments

Comments
 (0)