From 0d847da0b16613b73482e1725501f81a86c7da00 Mon Sep 17 00:00:00 2001 From: Oliver Ford Date: Wed, 25 Oct 2023 17:31:47 +0100 Subject: [PATCH] Fix output swallowed when wrapper enabled Presently using a command such as `terraform output -json | jq` does not work with the wrapper enabled, as it is by default. In order to consume terraform's output having set it up with this Action, it is necessary either to disable the wrapper (`with: terraform_wrapper: false`) or run it in its own Actions step with an explicit `id` (e.g. `id: foo`) so that it can be referred to and consumed (`${{steps.foo.outputs.stdout}}` et al.) in later steps. This seems to be the result of much confusion (issues passim) and is not at all easy (#338) to debug/diagnose and come to the realisation that it's due to the wrapper, or even that such a thing exists. This commit aims to address the issue by passing through stdout & stderr, so that they're available in Unix pipelines and variable assignment etc. as expected within a single step, while still retaining the wrapper's listening behaviour to provide them as Actions outputs. Closes #20, #80, #85, #149, #338, and probably more. --- dist/index1.js | 4 ++++ wrapper/terraform.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/dist/index1.js b/dist/index1.js index 73147cfd..4c68745b 100755 --- a/dist/index1.js +++ b/dist/index1.js @@ -4189,6 +4189,10 @@ async function checkTerraform () { core.setOutput('stderr', stderr.contents); core.setOutput('exitcode', exitCode.toString(10)); + // Pass-through stdout/err in case we're being used in a pipeline or variable assignment + process.stdout.write(stdout.contents); + process.stderr.write(stderr.contents); + 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 diff --git a/wrapper/terraform.js b/wrapper/terraform.js index eddcb35f..94a38497 100755 --- a/wrapper/terraform.js +++ b/wrapper/terraform.js @@ -46,6 +46,10 @@ async function checkTerraform () { core.setOutput('stderr', stderr.contents); core.setOutput('exitcode', exitCode.toString(10)); + // Pass-through stdout/err in case we're being used in a pipeline or variable assignment + process.stdout.write(stdout.contents); + process.stderr.write(stderr.contents); + 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