From 75391f1ed99e7970c58202883dfd7efa130b2044 Mon Sep 17 00:00:00 2001 From: arnol377 Date: Thu, 27 Mar 2025 17:38:44 -0400 Subject: [PATCH] fix: enhance output handling and error reporting in Terraform Validate action --- action.yml | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/action.yml b/action.yml index f8a383a..9a8999a 100644 --- a/action.yml +++ b/action.yml @@ -16,12 +16,16 @@ inputs: outputs: is_valid: description: 'Whether the Terraform configuration is valid (true/false)' + value: ${{ steps.validate.outputs.is_valid }} tests_passed: description: 'Whether the Terraform tests passed (true/false)' + value: ${{ steps.test.outputs.tests_passed }} stdout: description: 'Output from terraform validate and test commands' + value: ${{ steps.set_outputs.outputs.stdout }} stderr: description: 'Any error output from terraform validate or test commands' + value: ${{ steps.set_outputs.outputs.stderr }} runs: using: "composite" @@ -46,11 +50,11 @@ runs: terraform validate VALIDATE_EXIT_CODE=$? if [[ $VALIDATE_EXIT_CODE -ne 0 ]]; then - echo "Terraform validation failed" echo "is_valid=false" >> $GITHUB_OUTPUT + echo "Terraform validation failed" else - echo "Terraform validation passed" echo "is_valid=true" >> $GITHUB_OUTPUT + echo "Terraform validation passed" fi - name: Terraform Test @@ -61,17 +65,20 @@ runs: terraform test TEST_EXIT_CODE=$? if [[ $TEST_EXIT_CODE -ne 0 ]]; then - echo "Terraform tests failed" echo "tests_passed=false" >> $GITHUB_OUTPUT + echo "Terraform tests failed" else - echo "Terraform tests passed" echo "tests_passed=true" >> $GITHUB_OUTPUT + echo "Terraform tests passed" fi - name: Set Final Outputs id: set_outputs shell: bash run: | - echo "is_valid=${{ steps.validate.outputs.is_valid || 'false' }}" >> $GITHUB_OUTPUT - echo "tests_passed=${{ steps.test.outputs.tests_passed || 'false' }}" >> $GITHUB_OUTPUT - echo "stdout=Successfully ran terraform validate and test" >> $GITHUB_OUTPUT \ No newline at end of file + echo "stdout=Terraform validate and test complete" >> $GITHUB_OUTPUT + if [[ "${{ steps.validate.outputs.is_valid }}" != "true" || "${{ steps.test.outputs.tests_passed }}" != "true" ]]; then + echo "stderr=Validation or tests failed" >> $GITHUB_OUTPUT + else + echo "stderr=" >> $GITHUB_OUTPUT + fi \ No newline at end of file