@@ -3,328 +3,129 @@ layout: default
33title : CI Integration
44---
55
6- # Continuous Integration with Rails Accessibility Testing
6+ # CI/CD Integration
77
8- This guide shows you how to integrate Rails Accessibility Testing into your CI/CD pipeline to catch accessibility issues before they reach production .
8+ Automating accessibility tests in your Continuous Integration (CI) pipeline ensures no new violations are merged .
99
10- ## Why CI Integration?
11-
12- - ** Catch issues early** - Before code is merged
13- - ** Prevent regressions** - Ensure fixes stay fixed
14- - ** Team accountability** - Everyone sees accessibility status
15- - ** Compliance tracking** - Document WCAG compliance
16-
17- ## GitHub Actions
10+ ---
1811
19- ### Basic Setup
12+ ## GitHub Actions (Recommended)
2013
21- Create ` .github/workflows/accessibility.yml ` :
14+ Add this workflow file to your project at ` .github/workflows/accessibility.yml ` :
2215
2316``` yaml
24- name : Accessibility Tests
17+ name : Accessibility
2518
26- on :
27- pull_request :
28- push :
29- branches : [main]
19+ on : [push, pull_request]
3020
3121jobs :
32- accessibility :
22+ scan :
3323 runs-on : ubuntu-latest
34-
3524 services :
3625 postgres :
3726 image : postgres:14
3827 env :
39- POSTGRES_PASSWORD : postgres
28+ POSTGRES_PASSWORD : password
29+ ports : ['5432:5432']
4030 options : >-
4131 --health-cmd pg_isready
4232 --health-interval 10s
4333 --health-timeout 5s
4434 --health-retries 5
45-
35+
4636 steps :
4737 - uses : actions/checkout@v3
4838
4939 - name : Set up Ruby
5040 uses : ruby/setup-ruby@v1
5141 with :
52- ruby-version : 3.1
42+ ruby-version : 3.2
5343 bundler-cache : true
54-
44+
5545 - name : Install Chrome
5646 run : |
5747 sudo apt-get update
5848 sudo apt-get install -y google-chrome-stable
59-
60- - name : Setup test database
49+
50+ - name : Setup Database
6151 env :
6252 RAILS_ENV : test
63- DATABASE_URL : postgres://postgres:postgres @localhost/test
53+ DATABASE_URL : postgres://postgres:password @localhost:5432/test_db
6454 run : |
65- bundle exec rails db:create db:schema:load
66-
67- - name : Run accessibility tests
55+ bin/ rails db:create db:schema:load
56+
57+ - name : Run Accessibility Tests
6858 env :
6959 RAILS_ENV : test
70- DATABASE_URL : postgres://postgres:postgres@localhost/test
60+ RAILS_A11Y_PROFILE : ci
7161 run : |
72- bundle exec rspec spec/system/ --format documentation
73-
74- - name : Upload accessibility report
75- if : failure()
76- uses : actions/upload-artifact@v3
77- with :
78- name : accessibility-report
79- path : accessibility-report.json
62+ bundle exec rspec spec/system/
8063` ` `
8164
82- ### Advanced: JSON Report
83-
84- Generate a JSON report for programmatic access:
85-
86- ` ` ` yaml
87- - name : Run accessibility tests with JSON report
88- run : |
89- bundle exec rails_a11y check --format json --output accessibility-report.json
90- ` ` `
91-
92- ### Comment on PR
93-
94- Add a comment to PRs with accessibility status:
95-
96- ` ` ` yaml
97- - name : Comment on PR
98- if : github.event_name == 'pull_request'
99- uses : actions/github-script@v6
100- with :
101- script : |
102- const fs = require('fs');
103- const report = JSON.parse(fs.readFileSync('accessibility-report.json', 'utf8'));
104-
105- const comment = `## Accessibility Report
106-
107- **Status:** ${report.summary.total_violations === 0 ? '✅ Pass' : '❌ Fail'}
108- **Violations:** ${report.summary.total_violations}
109- **URLs Checked:** ${report.summary.urls_checked}
110-
111- ${report.summary.total_violations > 0 ? 'Please fix accessibility issues before merging.' : 'All accessibility checks passed!'}
112- `;
113-
114- github.rest.issues.createComment({
115- issue_number: context.issue.number,
116- owner: context.repo.owner,
117- repo: context.repo.repo,
118- body: comment
119- });
120- ` ` `
65+ ---
12166
12267## CircleCI
12368
124- ### Basic Configuration
125-
126- Add to ` .circleci/config.yml`:
69+ Add this job to your ` .circleci/config.yml`:
12770
12871` ` ` yaml
129- version: 2.1
130-
13172jobs:
132- accessibility :
73+ accessibility_check :
13374 docker:
134- - image: cimg/ruby:3.1
135- environment:
136- RAILS_ENV: test
75+ - image: cimg/ruby:3.2-browsers
76+ - image: cimg/postgres:14.0
77+ environment:
78+ RAILS_ENV: test
79+ RAILS_A11Y_PROFILE: ci
13780 steps:
13881 - checkout
139- - restore_cache:
140- keys:
141- - v1-dependencies-{{ checksum "Gemfile.lock" }}
82+ - ruby/install-deps
14283 - run:
143- name: Install dependencies
144- command: bundle install
84+ name: Wait for DB
85+ command: dockerize -wait tcp://localhost:5432 -timeout 1m
14586 - run:
146- name: Setup database
147- command: bundle exec rails db:create db:schema:load
87+ name: Database Setup
88+ command: bin/ rails db:schema:load
14889 - run:
149- name: Run accessibility tests
90+ name: Run Accessibility Scans
15091 command: bundle exec rspec spec/system/
15192` ` `
15293
153- # # GitLab CI
94+ ---
15495
155- # ## Basic Configuration
96+ # # GitLab CI
15697
157- Add to `.gitlab-ci.yml` :
98+ Add this to your `.gitlab-ci.yml` :
15899
159100` ` ` yaml
160- accessibility :
161- image: ruby:3.1
101+ accessibility_test :
102+ image: ruby:3.2
162103 services:
163104 - postgres:14
164105 variables:
165106 RAILS_ENV: test
166- POSTGRES_DB: test
167- POSTGRES_USER: postgres
168- POSTGRES_PASSWORD: postgres
107+ RAILS_A11Y_PROFILE: ci
169108 before_script:
170- - apt-get update -qq && apt-get install -y -qq postgresql-client
109+ - apt-get update -q && apt-get install -y google-chrome-stable
171110 - bundle install
172- - bundle exec rails db:create db:schema:load
111+ - bin/ rails db:create db:schema:load
173112 script:
174113 - bundle exec rspec spec/system/
175- artifacts:
176- when: on_failure
177- paths:
178- - accessibility-report.json
179- reports:
180- junit: accessibility-report.xml
181- ` ` `
182-
183- # # Jenkins
184-
185- # ## Pipeline Script
186-
187- ` ` ` groovy
188- pipeline {
189- agent any
190-
191- stages {
192- stage('Accessibility Tests') {
193- steps {
194- sh 'bundle install'
195- sh 'bundle exec rails db:create db:schema:load RAILS_ENV=test'
196- sh 'bundle exec rspec spec/system/'
197- }
198- }
199- }
200-
201- post {
202- always {
203- archiveArtifacts artifacts: 'accessibility-report.json', allowEmptyArchive: true
204- }
205- }
206- }
207- ` ` `
208-
209- # # CI Configuration Tips
210-
211- # ## Use CI Profile
212-
213- Configure stricter checks in CI :
214-
215- ` ` ` yaml
216- # config/accessibility.yml
217- ci:
218- checks:
219- color_contrast: true # Enable expensive checks in CI
220- skip_links: true # Require skip links in production
221- ` ` `
222-
223- Then set the profile in CI :
224-
225- ` ` ` bash
226- RAILS_A11Y_PROFILE=ci bundle exec rspec spec/system/
227- ` ` `
228-
229- # ## Fail Fast
230-
231- Make accessibility failures block merges :
232-
233- ` ` ` yaml
234- # GitHub Actions
235- - name: Run accessibility tests
236- run: bundle exec rspec spec/system/
237- continue-on-error: false # Fail the build on errors
238- ` ` `
239-
240- # ## Parallel Execution
241-
242- Run accessibility tests in parallel with other tests :
243-
244- ` ` ` yaml
245- strategy:
246- matrix:
247- test_type: [unit, integration, accessibility]
248114` ` `
249115
250- # ## Cache Dependencies
251-
252- Speed up CI runs by caching :
253-
254- ` ` ` yaml
255- - name: Cache gems
256- uses: actions/cache@v3
257- with:
258- path: vendor/bundle
259- key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
260- ` ` `
261-
262- # # Reporting
263-
264- # ## Generate Reports
265-
266- ` ` ` bash
267- # Human-readable report
268- bundle exec rails_a11y check --format human --output report.txt
269-
270- # JSON report for programmatic access
271- bundle exec rails_a11y check --format json --output report.json
272- ` ` `
273-
274- # ## Share Reports
275-
276- Upload reports to :
277- - **GitHub Actions Artifacts** - Automatic artifact upload
278- - **S3/Cloud Storage** - For long-term storage
279- - **Slack/Email** - Notify team of failures
280-
281- # # Best Practices
282-
283- 1. **Run on every PR** - Catch issues before merge
284- 2. **Use CI profile** - Stricter checks in CI than dev
285- 3. **Fail on violations** - Don't allow merging with issues
286- 4. **Report results** - Make status visible to team
287- 5. **Track trends** - Monitor violation counts over time
288-
289- # # Troubleshooting
290-
291- # ## Tests Time Out
292-
293- If tests are slow, disable expensive checks :
294-
295- ` ` ` yaml
296- ci:
297- checks:
298- color_contrast: false # Disable if too slow
299- ` ` `
116+ ---
300117
301- # ## Chrome Not Found
118+ # # Best Practices for CI
302119
303- Install Chrome in CI :
120+ 1. **Use the CI Profile:** Set `RAILS_A11Y_PROFILE=ci` to enable strict checks (like color contrast) that you might skip in development.
121+ 2. **Fail the Build:** Ensure your tests return a non-zero exit code if accessibility violations are found (this is the default behavior).
122+ 3. **Artifacts:** If using the static scanner's report output, save the generated HTML/JSON report as a build artifact.
304123
305124` ` ` yaml
306- - name: Install Chrome
307- run: |
308- wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
309- sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
310- sudo apt-get update
311- sudo apt-get install -y google-chrome-stable
312- ` ` `
313-
314- # ## Database Issues
315-
316- Ensure database is set up :
317-
318- ` ` ` bash
319- bundle exec rails db:create db:schema:load RAILS_ENV=test
125+ - name: Upload Report
126+ if: failure()
127+ uses: actions/upload-artifact@v3
128+ with:
129+ name: accessibility-report
130+ path: coverage/accessibility/
320131` ` `
321-
322- # # Next Steps
323-
324- - **Set up notifications** - Get alerts when checks fail
325- - **Track metrics** - Monitor accessibility over time
326- - **Automate fixes** - Use reports to prioritize work
327-
328- ---
329-
330- **Questions?** See the main [README](https://github.com/rayraycodes/rails-accessibility-testing/blob/main/README.md) or open an issue.
0 commit comments