mirror of
https://github.com/hashicorp/setup-terraform.git
synced 2025-12-24 20:27:06 +00:00
add support for fail_on_detected_diff
more logging -- is it working? more logging -- is it working? rerelease fix logging 2 more logging more logging add fail_on_detected_diff add fail_on_detected_diff 2 add fail_on_detected_diff 3 add fail_on_detected_diff 4 fix plan_fail id; two test more debug more debug - try getBooleanInput more debug - try getBooleanInput : add debug to raw js code more debug - try getBooleanInput : add debug stdout to raw js code try using "fail" as trigger instead of boolean
This commit is contained in:
parent
a75f1a3cce
commit
89704370b3
5 changed files with 170 additions and 30 deletions
|
|
@ -10,6 +10,8 @@ const { exec } = require('@actions/exec');
|
|||
|
||||
const OutputListener = require('./lib/output-listener');
|
||||
const pathToCLI = require('./lib/terraform-bin');
|
||||
const os = require("os");
|
||||
const releases = require("@hashicorp/js-releases");
|
||||
|
||||
async function checkTerraform () {
|
||||
// Setting check to `true` will cause `which` to throw if terraform isn't found
|
||||
|
|
@ -36,24 +38,51 @@ async function checkTerraform () {
|
|||
ignoreReturnCode: true,
|
||||
silent: true // avoid printing command in stdout: https://github.com/actions/toolkit/issues/649
|
||||
};
|
||||
|
||||
// TODO: remove
|
||||
core.setCommandEcho(true);
|
||||
|
||||
const exitCode = await exec(pathToCLI, args, options);
|
||||
|
||||
// Pass-through stdout/err as `exec` won't due to `silent: true` option
|
||||
process.stdout.write(stdout.contents);
|
||||
process.stderr.write(stderr.contents);
|
||||
|
||||
const fail_on_detected_diff2 = core.getInput('fail_on_detected_diff')
|
||||
core.debug(`fail_on_detected_diff2: ${fail_on_detected_diff2}`);
|
||||
|
||||
// Gather GitHub Actions inputs
|
||||
const version = core.getInput('terraform_version');
|
||||
core.debug(`TEST d Terraform version ${version}`);
|
||||
core.info(`TEST i Terraform version ${version}`);
|
||||
|
||||
// Set outputs, result, exitcode, and stderr
|
||||
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).
|
||||
// A exitCode of 0 is considered a success
|
||||
if (exitCode === 0) {
|
||||
core.info('Terraform completed successfully. (0)');
|
||||
return;
|
||||
}
|
||||
// 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).
|
||||
// The user may want to capture this and fail the job, so will set `fail_on_detected_diff: true`
|
||||
if (exitCode === 2) {
|
||||
const is_wrapper = core.getInput('terraform_wrapper')
|
||||
const terraform_version = core.getInput('terraform_version');
|
||||
const failOnDetectedDiffString = core.getInput('fail_on_detected_diff');
|
||||
// const failOnDetectedDiff = core.getBooleanInput('fail_on_detected_diff');
|
||||
//# getInput('my-input').toUpper() === 'true'
|
||||
const failOnDetectedDiff = (failOnDetectedDiffString.toLowerCase() === 'fail');
|
||||
core.debug(`Terraform detected a difference. (2) failOnDetectedDiffString=${failOnDetectedDiffString} failOnDetectedDiff=${failOnDetectedDiff}`);
|
||||
core.info(`Terraform detected a difference. 4 (2) is_wrapper=${is_wrapper} terraform_version=${terraform_version} failOnDetectedDiffString=${failOnDetectedDiffString} failOnDetectedDiff=${failOnDetectedDiff}`);
|
||||
if (!failOnDetectedDiff) {
|
||||
core.info('Terraform difference ignored.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// A non-zero exitCode is considered an error
|
||||
core.setFailed(`Terraform exited with code ${exitCode}.`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue