Skip to content

Commit

Permalink
simplify conditional only test if diff is not empty
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrebb committed Jan 15, 2024
1 parent 1faa5e7 commit bea3364
Showing 1 changed file with 31 additions and 35 deletions.
66 changes: 31 additions & 35 deletions .github/workflows/backstop-sanity-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 "<details>" >> $GITHUB_STEP_SUMMARY
echo "<summary>Expand Diff</summary>" >> $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 "</details>" >> $GITHUB_STEP_SUMMARY
fi
echo "## Unfiltered Diff" >> $GITHUB_STEP_SUMMARY
echo "<details>" >> $GITHUB_STEP_SUMMARY
echo "<summary>Expand Diff</summary>" >> $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 "</details>" >> $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:
Expand Down Expand Up @@ -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"
Expand All @@ -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 "<details>" >> $GITHUB_STEP_SUMMARY
echo "<summary>Expand Diff</summary>" >> $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 "</details>" >> $GITHUB_STEP_SUMMARY
fi
echo "## Unfiltered Diff" >> $GITHUB_STEP_SUMMARY
echo "<details>" >> $GITHUB_STEP_SUMMARY
echo "<summary>Expand Diff</summary>" >> $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 "</details>" >> $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

0 comments on commit bea3364

Please sign in to comment.