Merge pull request #384 from trails-cool/stigi/visual-diff-pr-comment

Post visual diff comment and job summary on visual test failure
This commit is contained in:
Ullrich Schäfer 2026-05-10 21:56:43 +02:00 committed by GitHub
commit 264276d1de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -113,6 +113,9 @@ jobs:
visual-tests:
name: Visual Tests
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v6
- uses: pnpm/action-setup@v6
@ -149,28 +152,18 @@ jobs:
diffs=$(find apps/planner/.vitest-attachments -name "*-diff-*.png" 2>/dev/null | sort)
if [ -z "$diffs" ]; then exit 0; fi
artifact_url="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
body="## Visual regression failures"$'\n\n'
body+="| Test | Diff (reference → actual) |"$'\n'
body+="|------|--------------------------|"$'\n'
body+="The following tests produced screenshot diffs:"$'\n\n'
for diff in $diffs; do
# Upload image to GitHub's CDN via the issue assets endpoint
response=$(curl -sf -X POST \
-H "Authorization: Bearer $GH_TOKEN" \
-H "Content-Type: image/png" \
-H "Accept: application/json" \
--data-binary @"$diff" \
"https://uploads.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/assets?name=$(basename $diff)")
url=$(echo "$response" | jq -r '.url // empty')
name=$(basename "$diff" | sed 's/-diff-chromium-linux\.png//' | sed 's/-/ /g')
if [ -n "$url" ]; then
body+="| \`$name\` | ![$name]($url) |"$'\n'
else
body+="| \`$name\` | *(upload failed)* |"$'\n'
fi
name=$(basename "$diff" | sed 's/-diff-chromium-[a-z]*\.png//' | sed 's/-/ /g')
body+="- \`$name\`"$'\n'
done
body+=$'\n'"Run \`pnpm --filter @trails-cool/planner test:visual:update\` to regenerate snapshots if the change is intentional."
body+=$'\n'"**[Download the \`visual-snapshots-diff\` artifact]($artifact_url)** to inspect the diffs locally."$'\n\n'
body+="To update snapshots if the change is intentional:"$'\n'
body+="\`\`\`"$'\n'
body+="pnpm --filter @trails-cool/planner test:visual:update"$'\n'
body+="\`\`\`"
gh pr comment ${{ github.event.pull_request.number }} --body "$body"
@ -180,6 +173,7 @@ jobs:
with:
name: visual-snapshots-diff
path: apps/planner/.vitest-attachments/
include-hidden-files: true
retention-days: 7
e2e: