mirror of
https://github.com/hashicorp/setup-terraform.git
synced 2025-12-27 21:43:38 +00:00
Exit early if exitCode is 0 or 2
This commit is contained in:
parent
5cd44b38b7
commit
46ea660108
2 changed files with 32 additions and 21 deletions
24
dist/index1.js
vendored
24
dist/index1.js
vendored
|
|
@ -3040,7 +3040,7 @@ async function checkTerraform () {
|
||||||
return io.which(pathToCLI, check);
|
return io.which(pathToCLI, check);
|
||||||
}
|
}
|
||||||
|
|
||||||
(async () => {
|
async () => {
|
||||||
// This will fail if Terraform isn't found, which is what we want
|
// This will fail if Terraform isn't found, which is what we want
|
||||||
await checkTerraform();
|
await checkTerraform();
|
||||||
|
|
||||||
|
|
@ -3049,14 +3049,14 @@ async function checkTerraform () {
|
||||||
const stderr = new OutputListener();
|
const stderr = new OutputListener();
|
||||||
const listeners = {
|
const listeners = {
|
||||||
stdout: stdout.listener,
|
stdout: stdout.listener,
|
||||||
stderr: stderr.listener
|
stderr: stderr.listener,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Execute terraform and capture output
|
// Execute terraform and capture output
|
||||||
const args = process.argv.slice(2);
|
const args = process.argv.slice(2);
|
||||||
const options = {
|
const options = {
|
||||||
listeners,
|
listeners,
|
||||||
ignoreReturnCode: true
|
ignoreReturnCode: true,
|
||||||
};
|
};
|
||||||
const exitCode = await exec(pathToCLI, args, options);
|
const exitCode = await exec(pathToCLI, args, options);
|
||||||
core.debug(`Terraform exited with code ${exitCode}.`);
|
core.debug(`Terraform exited with code ${exitCode}.`);
|
||||||
|
|
@ -3065,15 +3065,21 @@ async function checkTerraform () {
|
||||||
core.debug(`exitcode: ${exitCode}`);
|
core.debug(`exitcode: ${exitCode}`);
|
||||||
|
|
||||||
// Set outputs, result, exitcode, and stderr
|
// Set outputs, result, exitcode, and stderr
|
||||||
core.setOutput('stdout', stdout.contents);
|
core.setOutput("stdout", stdout.contents);
|
||||||
core.setOutput('stderr', stderr.contents);
|
core.setOutput("stderr", stderr.contents);
|
||||||
core.setOutput('exitcode', exitCode.toString(10));
|
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
|
// A non-zero exitCode is considered an error
|
||||||
if (exitCode !== 0) {
|
|
||||||
core.setFailed(`Terraform exited with code ${exitCode}.`);
|
core.setFailed(`Terraform exited with code ${exitCode}.`);
|
||||||
}
|
};
|
||||||
})();
|
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ async function checkTerraform () {
|
||||||
return io.which(pathToCLI, check);
|
return io.which(pathToCLI, check);
|
||||||
}
|
}
|
||||||
|
|
||||||
(async () => {
|
async () => {
|
||||||
// This will fail if Terraform isn't found, which is what we want
|
// This will fail if Terraform isn't found, which is what we want
|
||||||
await checkTerraform();
|
await checkTerraform();
|
||||||
|
|
||||||
|
|
@ -21,14 +21,14 @@ async function checkTerraform () {
|
||||||
const stderr = new OutputListener();
|
const stderr = new OutputListener();
|
||||||
const listeners = {
|
const listeners = {
|
||||||
stdout: stdout.listener,
|
stdout: stdout.listener,
|
||||||
stderr: stderr.listener
|
stderr: stderr.listener,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Execute terraform and capture output
|
// Execute terraform and capture output
|
||||||
const args = process.argv.slice(2);
|
const args = process.argv.slice(2);
|
||||||
const options = {
|
const options = {
|
||||||
listeners,
|
listeners,
|
||||||
ignoreReturnCode: true
|
ignoreReturnCode: true,
|
||||||
};
|
};
|
||||||
const exitCode = await exec(pathToCLI, args, options);
|
const exitCode = await exec(pathToCLI, args, options);
|
||||||
core.debug(`Terraform exited with code ${exitCode}.`);
|
core.debug(`Terraform exited with code ${exitCode}.`);
|
||||||
|
|
@ -37,13 +37,18 @@ async function checkTerraform () {
|
||||||
core.debug(`exitcode: ${exitCode}`);
|
core.debug(`exitcode: ${exitCode}`);
|
||||||
|
|
||||||
// Set outputs, result, exitcode, and stderr
|
// Set outputs, result, exitcode, and stderr
|
||||||
core.setOutput('stdout', stdout.contents);
|
core.setOutput("stdout", stdout.contents);
|
||||||
core.setOutput('stderr', stderr.contents);
|
core.setOutput("stderr", stderr.contents);
|
||||||
core.setOutput('exitcode', exitCode.toString(10));
|
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
|
// 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}.`);
|
core.setFailed(`Terraform exited with code ${exitCode}.`);
|
||||||
}
|
};
|
||||||
})();
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue