From aa8f43eb5cb0116f9c7eb77b7affd4d818dd18f7 Mon Sep 17 00:00:00 2001 From: Uzaeir Khan Date: Tue, 14 Nov 2023 12:41:27 +0100 Subject: [PATCH] BC-5468 add error reading in json file --- .github/workflows/main.yml | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e965e382..58e70c3f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -99,16 +99,21 @@ jobs: file_paths+=("$file_path") - while IFS="=" read -r key value; do - key_value_pairs["$key"]=$value - done < <(jq -r 'to_entries | map("\(.key)=\(.value|tostring)") | .[]' "$file_path") + result=$(jq -c . < "$file_path") + if [ $? -eq 0 ]; then + key_value_pairs+=($(jq -c '. | to_entries | .[]' < "$file_path")) + else + echo "Error reading JSON file: $file_path" + cat "$file_path" + exit 1 + fi # while IFS="=" read -r key value; do # key_value_pairs["$key"]=$value # done < <(jq -r 'to_entries | .[] | "\(.key)=\(.value)"' "$file_path") done - json_output=$(declare -p key_value_pairs | jq -r 'from_entries') + json_output=$(jq -n -c 'reduce inputs as $item ({}; . * $item)') # json_output="{" # for key in "${!key_value_pairs[@]}"; do @@ -117,7 +122,15 @@ jobs: # json_output="${json_output%,}" # json_output+="}" - echo "$json_output" > ${{ github.workspace }}/e2e-system-tests/env_variables/combined_credentials.json + if [ $? -eq 0 ]; then + # Write JSON output to file if successful + echo "$json_output" > "${{ github.workspace }}/e2e-system-tests/env_variables/combined_credentials.json" + else + echo "Error occurred during JSON concatenation." + # Print the merged JSON content + echo "$json_output" + exit 1 + fi - name: Clean up previous report uses: cypress-io/github-action@v5