Skip to content

Commit

Permalink
updating print setup
Browse files Browse the repository at this point in the history
  • Loading branch information
patel-bhavin committed Jul 2, 2024
1 parent 20cba80 commit 25921b3
Showing 1 changed file with 33 additions and 42 deletions.
75 changes: 33 additions & 42 deletions .github/workflows/unit-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,56 +60,47 @@ jobs:
contentctl test --post-test-behavior never_pause mode:changes --mode.target-branch develop
mkdir artifacts
cp test_results/summary.yml artifacts/
cat test_results/summary.yml
- name: store_artifacts
uses: actions/upload-artifact@v3
with:
name: content-latest
path: |
artifacts/summary.yml
- name: Install dependencies
run: sudo apt-get install -y jq

summarize-test-results:
needs: contentctl-unit-testing-setup
runs-on: ubuntu-latest
if: "!contains(github.ref, 'refs/tags/')" #don't run on tags - future steps won't run either since they depend on this job
# needs: [validate-tag-if-present, quit-for-dependabot]
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install dependencies
run: sudo apt-get install -y jq

- name: Extract total_fail value
run: |
total_fail=$(yq e '.summary.total_fail' summary.yml)
- name: Extract total_fail value
run: |
total_fail=$(yq e '.summary.total_fail' summary.yml)
- name: Check if total_fail is greater than one
run: |
# Debug: Print the content of summary.yml
cat test_results/summary.yml
- name: Print the failures
run: |
# Debug: Print the content of summary.yml
cat test_results/summary.yml
# Extract total_fail value and debug print it
total_fail=$(yq e '.summary.total_fail' test_results/summary.yml)
echo "Extracted total_fail: [$total_fail]"
# Extract total_fail value and debug print it
total_fail=$(yq e '.summary.total_fail' test_results/summary.yml)
echo "Extracted total_fail: [$total_fail]"
# Check if total_fail is a valid integer and greater than one
if [[ "$total_fail" =~ ^[0-9]+$ ]] && [ "$total_fail" -gt 1 ]; then
echo "CI Failure: There are failed tests."
echo -e "Name | Status | Test Type"
echo -e "---- | ------ | ---------"
# Loop through each item in tested_detections and print required fields with color
yq e '.tested_detections[] | .name as $name | .tests[].status as $status | .tests[].test_type as $test_type | "\($name) | \($status) | \($test_type)"' test_results/summary.yml | while read line; do
name=$(echo $line | cut -d '|' -f 1)
status=$(echo $line | cut -d '|' -f 2 | xargs)
test_type=$(echo $line | cut -d '|' -f 3)
if [ "$status" == "pass" ]; then
echo -e "${name} | \033[32m${status}\033[0m | ${test_type}"
else
echo -e "${name} | \033[31m${status}\033[0m | ${test_type}"
fi
done
exit 1 # Fail the CI job
else
echo "CI Success: No failed tests."
fi
# Check if total_fail is a valid integer and greater than one
if [[ "$total_fail" =~ ^[0-9]+$ ]] && [ "$total_fail" -gt 1 ]; then
echo "CI Failure: There are failed tests."
echo -e "Name | Status | Test Type"
echo -e "---- | ------ | ---------"
# Loop through each item in tested_detections and print required fields with color
yq e '.tested_detections[] | .name as $name | .tests[].status as $status | .tests[].test_type as $test_type | "\($name) | \($status) | \($test_type)"' test_results/summary.yml | while read line; do
name=$(echo $line | cut -d '|' -f 1)
status=$(echo $line | cut -d '|' -f 2 | xargs)
test_type=$(echo $line | cut -d '|' -f 3)
if [ "$status" == "pass" ]; then
echo -e "${name} | \033[32m${status}\033[0m | ${test_type}"
else
echo -e "${name} | \033[31m${status}\033[0m | ${test_type}"
fi
done
exit 1 # Fail the CI job
else
echo "CI Success: No failed tests."
fi

0 comments on commit 25921b3

Please sign in to comment.