Skip to content

Commit

Permalink
Fix output swallowed when wrapper enabled
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
OJFord committed Oct 25, 2023
1 parent 599d383 commit 0d847da
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dist/index1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions wrapper/terraform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0d847da

Please sign in to comment.