@@ -36,54 +36,26 @@ Add to your test helper:
3636require ' capybara_screenshot_diff/reporters/html'
3737```
3838
39- ### 2. Upload artifacts (manual setup )
39+ ### 2. Reusable composite action (recommended )
4040
41- This is the full YAML so you understand what each step does :
41+ The simplest way — one step handles artifact upload, job summary, and PR comments :
4242
4343``` yaml
4444# .github/workflows/test.yml
4545jobs :
4646 test :
4747 runs-on : ubuntu-latest
48+ permissions :
49+ contents : read
50+ pull-requests : write # Required for PR comments
51+
4852 steps :
4953 - uses : actions/checkout@v6
5054
5155 - uses : ruby/setup-ruby@v1
5256 with :
5357 bundler-cache : true
5458
55- # Install libvips for the :vips driver (optional — skip if using :chunky_png)
56- - name : Install libvips
57- run : sudo apt-get install -y libvips-dev
58-
59- - name : Run tests
60- run : bundle exec rake test
61-
62- # Upload HTML report — renders inline in Actions UI (no download needed)
63- - name : Upload screenshot report
64- if : failure()
65- uses : actions/upload-artifact@v7
66- with :
67- name : screenshot-report
68- path : doc/screenshots/snap_diff_report.html
69- archive : false
70- retention-days : 2
71-
72- # Upload full report with images (for offline review)
73- - name : Upload full screenshot report
74- if : failure()
75- uses : actions/upload-artifact@v7
76- with :
77- name : screenshot-report-full
78- path : doc/screenshots/
79- retention-days : 2
80- ` ` `
81-
82- ### 3. Or use the reusable action (one line)
83-
84- Instead of the manual upload steps above, reference our composite action directly:
85-
86- ` ` ` yaml
8759 - name : Run tests
8860 run : bundle exec rake test
8961
@@ -92,54 +64,123 @@ Instead of the manual upload steps above, reference our composite action directl
9264 uses : snap-diff/snap_diff-capybara/.github/actions/upload-screenshots@master
9365 with :
9466 name : screenshots
67+ pr-comment : ' true'
9568` ` `
9669
97- This uploads diffs, Capybara failure screenshots, and the HTML report (inline + full) in one step.
70+ That's it. On failure, this will:
71+ - Upload diff images + HTML report as artifacts
72+ - Post a PR comment with links to the inline report and full artifact download
73+ - Add a job summary with report links (visible in the Actions UI)
9874
99- ** Inputs:**
75+ #### Inputs
10076
10177| Input | Default | Description |
10278|-------|---------|-------------|
10379| ` name` | (required) | Artifact name prefix |
10480| `report-path` | `doc/screenshots` | Path to HTML report directory |
10581| `retention-days` | `2` | Days to retain artifacts |
82+ | `pr-comment` | `false` | Post PR comment with report link (requires `pull-requests : write`) |
10683
107- # ## 4. PR comment with link to report (optional)
84+ # ### Outputs
10885
109- Automatically comment on the PR pointing to the artifact. Uses `find-comment` to update existing comments instead of creating duplicates :
86+ | Output | Description |
87+ |--------|-------------|
88+ | `report-url` | Direct URL to the inline HTML report artifact |
89+ | `report-full-url` | Direct URL to the full report artifact (with images) |
11090
111- ` ` ` yaml
112- - name: Find existing comment
113- if: failure() && github.event_name == 'pull_request'
114- uses: peter-evans/find-comment@v3
115- id: find-comment
116- with:
117- issue-number: ${{ github.event.pull_request.number }}
118- comment-author: 'github-actions[bot]'
119- body-includes: 'Screenshot diffs detected'
91+ # ## 3. Ruby + libvips setup action
92+
93+ For consistent CI environments (libvips, font antialiasing disabled), use the setup action :
12094
121- - name: Comment PR with report link
122- if: failure() && github.event_name == 'pull_request'
123- uses: peter-evans/create-or-update-comment@v5
95+ ` ` ` yaml
96+ - uses: snap-diff/snap_diff-capybara/.github/actions/setup-ruby-and-dependencies@master
12497 with:
125- comment-id: ${{ steps.find-comment.outputs.comment-id }}
126- issue-number: ${{ github.event.pull_request.number }}
127- edit-mode: replace
128- body: |
129- ### Screenshot diffs detected
130- [View report](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}#artifacts)
98+ ruby-version: '4.0'
99+ cache-apt-packages: true
131100` ` `
132101
133- **Required:** Add permissions to the job for PR commenting to work:
102+ This installs Ruby, libvips (with apt caching), and disables font antialiasing for consistent rendering across CI runs.
103+
104+ # ### Inputs
105+
106+ | Input | Default | Description |
107+ |-------|---------|-------------|
108+ | `ruby-version` | (required) | Ruby version to install |
109+ | `cache-apt-packages` | `false` | Cache libvips apt packages for faster runs |
110+ | `ruby-cache-version` | — | Bundler cache version key |
111+
112+ # ## 4. Full example with both actions
134113
135114` ` ` yaml
136115jobs:
137116 test:
117+ runs-on: ubuntu-latest
118+ timeout-minutes: 10
138119 permissions:
139120 contents: read
140121 pull-requests: write
122+
123+ steps:
124+ - uses: actions/checkout@v6
125+
126+ - uses: snap-diff/snap_diff-capybara/.github/actions/setup-ruby-and-dependencies@master
127+ with:
128+ ruby-version: '4.0'
129+ cache-apt-packages: true
130+
131+ - run: bundle exec rake test
132+
133+ - uses: snap-diff/snap_diff-capybara/.github/actions/upload-screenshots@master
134+ if: failure()
135+ with:
136+ name: screenshots
137+ pr-comment: 'true'
141138` ` `
142139
140+ # ## 5. Manual setup (without composite actions)
141+
142+ If you prefer full control, here's the expanded YAML :
143+
144+ <details>
145+ <summary>Expand manual setup</summary>
146+
147+ ` ` ` yaml
148+ jobs:
149+ test:
150+ runs-on: ubuntu-latest
151+ steps:
152+ - uses: actions/checkout@v6
153+
154+ - uses: ruby/setup-ruby@v1
155+ with:
156+ bundler-cache: true
157+
158+ - name: Install libvips
159+ run: sudo apt-get install -y libvips-dev
160+
161+ - name: Run tests
162+ run: bundle exec rake test
163+
164+ - name: Upload screenshot report
165+ if: failure()
166+ uses: actions/upload-artifact@v7
167+ with:
168+ name: screenshot-report
169+ path: doc/screenshots/snap_diff_report.html
170+ archive: false
171+ retention-days: 2
172+
173+ - name: Upload full report with images
174+ if: failure()
175+ uses: actions/upload-artifact@v7
176+ with:
177+ name: screenshot-report-full
178+ path: doc/screenshots/
179+ retention-days: 2
180+ ` ` `
181+
182+ </details>
183+
143184# # Update Baselines in CI
144185
145186When intentional UI changes are made, baselines need to be re-recorded. You can do this locally :
@@ -152,6 +193,9 @@ git commit -m "chore: update screenshot baselines"
152193
153194Or add a workflow that maintainers can trigger manually :
154195
196+ <details>
197+ <summary>Expand update-baselines workflow</summary>
198+
155199` ` ` yaml
156200# .github/workflows/update-baselines.yml
157201name: Update Screenshot Baselines
@@ -175,12 +219,10 @@ jobs:
175219 with:
176220 ref: ${{ inputs.branch }}
177221
178- - uses: ruby/ setup-ruby@v1
222+ - uses: snap-diff/snap_diff-capybara/.github/actions/ setup-ruby-and-dependencies@master
179223 with:
180- bundler-cache: true
181-
182- - name: Install libvips
183- run: sudo apt-get install -y libvips-dev
224+ ruby-version: '4.0'
225+ cache-apt-packages: true
184226
185227 - name: Record new baselines
186228 run: RECORD_SCREENSHOTS=1 bundle exec rake test
@@ -195,14 +237,11 @@ jobs:
195237 git push
196238` ` `
197239
240+ </details>
241+
198242**How it works:**
1992431. Go to Actions → "Update Screenshot Baselines" → "Run workflow"
2002442. Enter the branch name (e.g. your PR branch)
2012453. The workflow records new baselines, commits, and pushes
202246
203- **Safety:**
204- - Only maintainers with write access can trigger `workflow_dispatch`
205- - The commit uses `git diff --staged --quiet ||` to skip empty commits
206- - ` GITHUB_TOKEN` pushes don't trigger subsequent CI runs ([by design](https://docs.github.com/actions/using-workflows/events-that-trigger-workflows))
207-
208247[← Back to README](../README.md)
0 commit comments