From 6047eb2b0c7e072785c3d5a8693c715df6708104 Mon Sep 17 00:00:00 2001 From: arnol377 Date: Thu, 27 Mar 2025 17:21:26 -0400 Subject: [PATCH] fix: improve error handling and output management in Terraform Validate action --- action.yml | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/action.yml b/action.yml index 6b4e0f1..d49456e 100644 --- a/action.yml +++ b/action.yml @@ -42,29 +42,37 @@ runs: id: validate shell: bash run: | + cd ${{ inputs.working-directory }} terraform validate - if [[ $? -ne 0 ]]; then + VALIDATE_EXIT_CODE=$? + if [[ $VALIDATE_EXIT_CODE -ne 0 ]]; then echo "Terraform validation failed" echo "is_valid=false" >> $GITHUB_OUTPUT + exit $VALIDATE_EXIT_CODE + else + echo "Terraform validation passed" + echo "is_valid=true" >> $GITHUB_OUTPUT fi - echo "Terraform validation passed" - echo "is_valid=true" >> $GITHUB_OUTPUT - name: Terraform Test id: test shell: bash + if: steps.validate.outcome == 'success' run: | + cd ${{ inputs.working-directory }} terraform test - if [[ $? -ne 0 ]]; then + TEST_EXIT_CODE=$? + if [[ $TEST_EXIT_CODE -ne 0 ]]; then echo "Terraform tests failed" echo "tests_passed=false" >> $GITHUB_OUTPUT + else + echo "Terraform tests passed" + echo "tests_passed=true" >> $GITHUB_OUTPUT fi - echo "Terraform tests passed" - echo "tests_passed=true" >> $GITHUB_OUTPUT - name: Set Outputs id: set_outputs shell: bash run: | - echo "is_valid=${{ steps.validate.outputs.is_valid }}" >> $GITHUB_ENV - echo "tests_passed=${{ steps.test.outputs.tests_passed }}" >> $GITHUB_ENV \ No newline at end of file + echo "is_valid=$(cat $GITHUB_OUTPUT | grep is_valid | cut -d= -f2)" >> $GITHUB_OUTPUT + echo "tests_passed=$(cat $GITHUB_OUTPUT | grep tests_passed | cut -d= -f2)" >> $GITHUB_OUTPUT \ No newline at end of file