From bea336472ee6f55ac9dd5ac4161ca6e9a77d2fc1 Mon Sep 17 00:00:00 2001 From: Dan Grebb Date: Sun, 14 Jan 2024 23:48:01 -0500 Subject: [PATCH] simplify conditional only test if diff is not empty --- .github/workflows/backstop-sanity-test.yml | 66 ++++++++++------------ 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/.github/workflows/backstop-sanity-test.yml b/.github/workflows/backstop-sanity-test.yml index d212027cf..0fcedf62d 100644 --- a/.github/workflows/backstop-sanity-test.yml +++ b/.github/workflows/backstop-sanity-test.yml @@ -45,15 +45,15 @@ jobs: PUPPETEER_TEST_RESULT=$(diff -c <(jq 'walk(if type == "object" then with_entries(.value |= if type == "object" or type == "array" then . else "" end) else . end)' test/__fixtures__/sanity-test.json) \ <(jq 'walk(if type == "object" then with_entries(.value |= if type == "object" or type == "array" then . else "" end) else . end)' test/configs/backstop_data/bitmaps_test/**/report.json)) echo "PUPPETEER_TEST_RESULT=$PUPPETEER_TEST_RESULT" >> $GITHUB_ENV - if [[ $PUPPETEER_TEST_RESULT == "0" ]]; then - echo "# ✅ Puppeteer Sanity Report Valid" >> $GITHUB_STEP_SUMMARY - else + if [[ $PUPPETEER_TEST_RESULT != "" ]]; then echo "# ❎ Puppeteer Sanity Different" >> $GITHUB_STEP_SUMMARY echo '```diff' >> $GITHUB_STEP_SUMMARY echo "${PUPPETEER_TEST_RESULT}" >> $GITHUB_STEP_SUMMARY echo '```' >> $GITHUB_STEP_SUMMARY echo "# More" >> $GITHUB_STEP_SUMMARY echo "$PUPPETEER_TEST_RESULT" >> $GITHUB_STEP_SUMMARY + else + echo "# ✅ Puppeteer Sanity Report Valid" >> $GITHUB_STEP_SUMMARY fi - name: "Full Sanity Report Diff" @@ -62,24 +62,22 @@ jobs: run: | set +e FULL_TEST_DIFF=$(diff <(jq -S '.tests[]' test/__fixtures__/sanity-test.json) <(jq -S '.tests[]' test/configs/backstop_data/bitmaps_test/**/report.json)) - if [[ $FULL_TEST_DIFF != "0" ]]; then - echo "## Unfiltered Diff" >> $GITHUB_STEP_SUMMARY - echo "
" >> $GITHUB_STEP_SUMMARY - echo "Expand Diff" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo '```diff' >> $GITHUB_STEP_SUMMARY - echo "${FULL_TEST_DIFF}" >> $GITHUB_STEP_SUMMARY - echo '```' >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "
" >> $GITHUB_STEP_SUMMARY - fi + echo "## Unfiltered Diff" >> $GITHUB_STEP_SUMMARY + echo "
" >> $GITHUB_STEP_SUMMARY + echo "Expand Diff" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo '```diff' >> $GITHUB_STEP_SUMMARY + echo "${FULL_TEST_DIFF}" >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "
" >> $GITHUB_STEP_SUMMARY - name: "Report Validation Outcome" run: | - if [[ $PUPPETEER_TEST_RESULT == "0" ]]; then - exit 0 - else + if [[ $PUPPETEER_TEST_RESULT != "" ]]; then exit 1 + else + exit 0 fi sanity-playwright: @@ -115,15 +113,15 @@ jobs: PLAYWRIGHT_TEST_RESULT=$(diff -c <(jq 'walk(if type == "object" then with_entries(.value |= if type == "object" or type == "array" then . else "" end) else . end)' test/__fixtures__/sanity-test-playwright.json) \ <(jq 'walk(if type == "object" then with_entries(.value |= if type == "object" or type == "array" then . else "" end) else . end)' test/configs/backstop_data/bitmaps_test/**/report.json)) echo "PLAYWRIGHT_TEST_RESULT=$PLAYWRIGHT_TEST_RESULT" >> $GITHUB_ENV - if [[ $PLAYWRIGHT_TEST_RESULT == "0" ]]; then - echo "# ✅ Playwright Sanity Report Valid" >> $GITHUB_STEP_SUMMARY - else - echo "# ❎ Playwright Sanity Report Different" >> $GITHUB_STEP_SUMMARY + if [[ $PLAYWRIGHT_TEST_RESULT != "" ]]; then echo '```diff' >> $GITHUB_STEP_SUMMARY echo "${PLAYWRIGHT_TEST_RESULT}" >> $GITHUB_STEP_SUMMARY echo '```' >> $GITHUB_STEP_SUMMARY echo "# More" >> $GITHUB_STEP_SUMMARY echo "$PLAYWRIGHT_TEST_RESULT" >> $GITHUB_STEP_SUMMARY + else + echo "# ✅ Playwright Sanity Report Valid" >> $GITHUB_STEP_SUMMARY + echo "# ❎ Playwright Sanity Report Different" >> $GITHUB_STEP_SUMMARY fi - name: "Full Sanity Report Diff" @@ -132,22 +130,20 @@ jobs: run: | set +e FULL_TEST_DIFF=$(diff <(jq -S '.tests[]' test/__fixtures__/sanity-test-playwright.json) <(jq -S '.tests[]' test/configs/backstop_data/bitmaps_test/**/report.json)) - if [[ $FULL_TEST_DIFF != "0" ]]; then - echo "## Unfiltered Diff" >> $GITHUB_STEP_SUMMARY - echo "
" >> $GITHUB_STEP_SUMMARY - echo "Expand Diff" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo '```diff' >> $GITHUB_STEP_SUMMARY - echo "${FULL_TEST_DIFF}" >> $GITHUB_STEP_SUMMARY - echo '```' >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "
" >> $GITHUB_STEP_SUMMARY - fi + echo "## Unfiltered Diff" >> $GITHUB_STEP_SUMMARY + echo "
" >> $GITHUB_STEP_SUMMARY + echo "Expand Diff" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo '```diff' >> $GITHUB_STEP_SUMMARY + echo "${FULL_TEST_DIFF}" >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "
" >> $GITHUB_STEP_SUMMARY - name: "Report Validation Outcome" run: | - if [[ $PLAYWRIGHT_TEST_RESULT == "0" ]]; then - exit 0 - else + if [[ $PLAYWRIGHT_TEST_RESULT != "" ]]; then exit 1 + else + exit 0 fi