Skip to content

Commit 4070438

Browse files
pftgclaude
andauthored
refactor: ADR-006 T3+T4 — hoist setup, consolidate assertion helpers (#186)
* refactor: ADR-006 T3+T4 — hoist setup, consolidate assertion helpers T3: Hoist duplicated setup (base_path, new_path, driver, comparison) from 3 nested classes to parent DifferenceFinderTest. Nested classes inherit setup and only add their own (@finder). T4: Extract assert_driver_check_called(driver, check_type, times) parameterized helper. Old methods kept as one-line aliases. T6: Skipped — param order already matches Minitest convention. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: remove extra empty line in InitializationTest (standardrb) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * refactor: move PR comment + job summary into upload-screenshots action Add pr-comment input to upload-screenshots composite action. When enabled, it finds/creates a PR comment with report links automatically. Also adds job summary with artifact links. Removes ~40 lines of duplicated YAML from test.yml. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * docs: update CI integration for new composite action API - Document pr-comment input for upload-screenshots action - Document setup-ruby-and-dependencies action with inputs table - Add full example combining both actions - Move manual setup and update-baselines to collapsible sections - Update README CI snippet to show pr-comment: 'true' Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4e7be3b commit 4070438

6 files changed

Lines changed: 169 additions & 166 deletions

File tree

.github/actions/upload-screenshots/action.yml

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: 'Upload SnapDiff screenshots'
3-
description: 'Upload screenshot diffs and HTML report as CI artifacts'
3+
description: 'Upload screenshot diffs, HTML report, and optionally comment on PR'
44
inputs:
55
name:
66
description: 'Artifact name prefix'
@@ -11,6 +11,9 @@ inputs:
1111
retention-days:
1212
description: 'Number of days to retain artifacts'
1313
default: '2'
14+
pr-comment:
15+
description: 'Post PR comment with report link (requires pull-requests: write)'
16+
default: 'false'
1417
outputs:
1518
report-url:
1619
description: 'Direct URL to the inline HTML report artifact'
@@ -70,3 +73,41 @@ runs:
7073
name: ${{ inputs.name }}-report-full
7174
retention-days: ${{ inputs.retention-days }}
7275
path: ${{ inputs.report-path }}/
76+
77+
- name: Job summary
78+
if: steps.check-report.outputs.exists == 'true'
79+
shell: bash
80+
run: |
81+
cat >> "$GITHUB_STEP_SUMMARY" <<EOF
82+
### SnapDiff Report
83+
84+
| Artifact | Link |
85+
|----------|------|
86+
| HTML report (inline) | ${{ steps.upload-report.outputs.artifact-url || 'N/A' }} |
87+
| Full report with images | ${{ steps.upload-report-full.outputs.artifact-url || 'N/A' }} |
88+
EOF
89+
90+
- name: Find existing PR comment
91+
if: inputs.pr-comment == 'true' && github.event_name == 'pull_request'
92+
uses: peter-evans/find-comment@v3
93+
id: find-comment
94+
with:
95+
issue-number: ${{ github.event.pull_request.number }}
96+
comment-author: 'github-actions[bot]'
97+
body-includes: 'Screenshot diffs'
98+
99+
- name: Comment PR with report link
100+
if: inputs.pr-comment == 'true' && github.event_name == 'pull_request'
101+
uses: peter-evans/create-or-update-comment@v5
102+
with:
103+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
104+
issue-number: ${{ github.event.pull_request.number }}
105+
edit-mode: replace
106+
body: |
107+
### Screenshot diffs detected
108+
109+
| Artifact | Link |
110+
|----------|------|
111+
| HTML report (inline) | ${{ steps.upload-report.outputs.artifact-url || 'N/A' }} |
112+
| Full report with images | ${{ steps.upload-report-full.outputs.artifact-url || 'N/A' }} |
113+
| [All artifacts](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}#artifacts) | Browse all |

.github/workflows/test.yml

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -82,58 +82,9 @@ jobs:
8282

8383
- uses: ./.github/actions/upload-screenshots
8484
if: failure()
85-
id: upload-screenshots
8685
with:
8786
name: base-screenshots
88-
89-
- name: Find existing report comment
90-
if: always() && github.event_name == 'pull_request'
91-
uses: peter-evans/find-comment@v3
92-
id: find-comment
93-
with:
94-
issue-number: ${{ github.event.pull_request.number }}
95-
comment-author: 'github-actions[bot]'
96-
body-includes: 'Screenshot diffs'
97-
98-
- name: Comment PR with report link
99-
if: failure() && github.event_name == 'pull_request'
100-
uses: peter-evans/create-or-update-comment@v5
101-
with:
102-
comment-id: ${{ steps.find-comment.outputs.comment-id }}
103-
issue-number: ${{ github.event.pull_request.number }}
104-
edit-mode: replace
105-
body: |
106-
### Screenshot diffs detected
107-
108-
| Artifact | Link |
109-
|----------|------|
110-
| HTML report (inline preview) | ${{ steps.upload-screenshots.outputs.report-url || 'N/A' }} |
111-
| Full report with images | ${{ steps.upload-screenshots.outputs.report-full-url || 'N/A' }} |
112-
| [All artifacts](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}#artifacts) | Browse all |
113-
114-
- name: Job summary with report links
115-
if: failure()
116-
run: |
117-
cat >> "$GITHUB_STEP_SUMMARY" <<EOF
118-
### Screenshot diffs detected
119-
120-
| Artifact | Link |
121-
|----------|------|
122-
| HTML report (inline) | ${{ steps.upload-screenshots.outputs.report-url || 'N/A' }} |
123-
| Full report with images | ${{ steps.upload-screenshots.outputs.report-full-url || 'N/A' }} |
124-
| [All artifacts](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}#artifacts) | Browse all |
125-
EOF
126-
127-
- name: Update comment on success
128-
if: success() && github.event_name == 'pull_request' && steps.find-comment.outputs.comment-id != ''
129-
uses: peter-evans/create-or-update-comment@v5
130-
with:
131-
comment-id: ${{ steps.find-comment.outputs.comment-id }}
132-
edit-mode: replace
133-
body: |
134-
### Screenshot diffs resolved
135-
136-
All screenshots match their baselines. Previous diffs have been fixed.
87+
pr-comment: 'true'
13788

13889
- name: Uploading Coverage Report
13990
uses: actions/upload-artifact@v7
@@ -253,17 +204,5 @@ jobs:
253204
run: bin/rake 'report:sample[embed]'
254205

255206
- uses: ./.github/actions/upload-screenshots
256-
id: upload-screenshots
257207
with:
258208
name: test-report
259-
260-
- name: Job summary with report links
261-
run: |
262-
cat >> "$GITHUB_STEP_SUMMARY" <<'EOF'
263-
### SnapDiff Report
264-
265-
| Artifact | Link |
266-
|----------|------|
267-
| HTML report (inline) | ${{ steps.upload-screenshots.outputs.report-url || 'N/A' }} |
268-
| Full report with images | ${{ steps.upload-screenshots.outputs.report-full-url || 'N/A' }} |
269-
EOF

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,18 @@ After tests run, open `doc/screenshots/snap_diff_report.html`:
118118

119119
Review all visual changes in one place — no need to hunt through `.diff.png` files. 4 view modes (both/base/new/heatmap), per-image zoom, annotation toggle, keyboard navigation, and search.
120120

121-
**In GitHub Actions**, the report renders inline as a CI artifact — no download needed. Add a PR comment with a link to the report automatically:
121+
**In GitHub Actions**, one step uploads the report, posts a PR comment with the link, and adds a job summary:
122122

123123
```yaml
124124
- name: Upload screenshot report
125125
if: failure()
126126
uses: snap-diff/snap_diff-capybara/.github/actions/upload-screenshots@master
127127
with:
128128
name: screenshots
129+
pr-comment: 'true'
129130
```
130131
131-
See [CI Integration](docs/ci-integration.md) for the full GitHub Actions setup with PR commenting.
132+
See [CI Integration](docs/ci-integration.md) for full setup including Ruby + libvips action and baseline update workflow.
132133
133134
## Compare Any Two Images
134135

0 commit comments

Comments
 (0)