From b7f47871d922c75346e6fd5264cbf72ecff5a369 Mon Sep 17 00:00:00 2001 From: danilo Date: Mon, 16 Jan 2023 11:27:47 +0100 Subject: [PATCH] Fix Terraform plan group output (#50) * fix group * seperate group * move end --- dist/index.js | 4 ++++ index.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/dist/index.js b/dist/index.js index 32a44e4b..b462670c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -23957,6 +23957,7 @@ async function terraform(terraformDirectory, args) { core.startGroup('Run terraform plan'); const tfp = await terraform(terraformDirectory, ['plan', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, `-refresh=${terraformRefresh}`, '-out=terraform.plan', '-detailed-exitcode'].concat(terraformTargets).concat(terraformVariableFiles).concat(terraformPlanDestroy)); core.endGroup(); + if (tfp.status == 1) { // 0 = no error no changes, 1 = error, 2 = no error with changes (from -detailed-exitcode documentation) tf_plan = status_failed; core.setFailed(`Failed to prepare the terraform plan [err:${tfp.status}]`); @@ -23965,6 +23966,7 @@ async function terraform(terraformDirectory, args) { tf_plan = status_success; } + core.startGroup('Save terraform change status'); core.setOutput('changes', tfp.status == 2 ? 'true' : 'false'); // write to file and upload to artifact storage @@ -23979,6 +23981,8 @@ async function terraform(terraformDirectory, args) { }; const artifactClient = artifact.create(); const uploadResponse = await artifactClient.uploadArtifact('terraform', [fileName], '.', options); + core.endGroup(); + if (uploadResponse.failedItems.length > 0) { core.setFailed('Failed to upload artfiact'); } diff --git a/index.js b/index.js index e60cdeb3..d79eaa3e 100644 --- a/index.js +++ b/index.js @@ -233,6 +233,7 @@ async function terraform(terraformDirectory, args) { core.startGroup('Run terraform plan'); const tfp = await terraform(terraformDirectory, ['plan', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, `-refresh=${terraformRefresh}`, '-out=terraform.plan', '-detailed-exitcode'].concat(terraformTargets).concat(terraformVariableFiles).concat(terraformPlanDestroy)); core.endGroup(); + if (tfp.status == 1) { // 0 = no error no changes, 1 = error, 2 = no error with changes (from -detailed-exitcode documentation) tf_plan = status_failed; core.setFailed(`Failed to prepare the terraform plan [err:${tfp.status}]`); @@ -241,6 +242,7 @@ async function terraform(terraformDirectory, args) { tf_plan = status_success; } + core.startGroup('Save terraform change status'); core.setOutput('changes', tfp.status == 2 ? 'true' : 'false'); // write to file and upload to artifact storage @@ -255,6 +257,8 @@ async function terraform(terraformDirectory, args) { }; const artifactClient = artifact.create(); const uploadResponse = await artifactClient.uploadArtifact('terraform', [fileName], '.', options); + core.endGroup(); + if (uploadResponse.failedItems.length > 0) { core.setFailed('Failed to upload artfiact'); }