-
Notifications
You must be signed in to change notification settings - Fork 0
116 lines (102 loc) · 3.47 KB
/
Copy pathci.yml
File metadata and controls
116 lines (102 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
name: CI
on:
pull_request:
push:
branches: [ main, master ]
permissions:
contents: read
pull-requests: write
jobs:
build-and-a11y:
name: Build & A11y checks
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '18'
cache: npm
- name: Install dependencies
run: npm ci
- name: Run npm audit
run: npm audit --audit-level=low || true
- name: Serve site
run: |
npx http-server -p 8000 -c-1 &
echo $! > server.pid
for i in $(seq 1 30); do
if curl -sf http://127.0.0.1:8000/ > /dev/null; then exit 0; fi
sleep 1
done
echo "Server did not become ready" >&2
exit 1
shell: bash
- name: Run pa11y
run: |
if npx pa11y http://127.0.0.1:8000 --reporter json > pa11y.json; then
:
else
echo '[]' > pa11y.json
fi
shell: bash
- name: Upload pa11y report
if: always()
uses: actions/upload-artifact@v4
with:
name: pa11y-report
path: pa11y.json
- name: Install Playwright browsers
run: npx playwright install --with-deps chromium
- name: Run axe audit (Playwright)
run: npm run axe-audit
- name: Upload axe results (if any)
if: always()
uses: actions/upload-artifact@v4
with:
name: axe-results
path: axe-results.json
- name: Stop server
if: always()
run: kill "$(cat server.pid)" 2>/dev/null || true
shell: bash
- name: Comment accessibility summary on PR
if: github.event_name == 'pull_request' && !cancelled()
continue-on-error: true
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const paExists = fs.existsSync('pa11y.json');
const axeExists = fs.existsSync('axe-results.json');
let paCount = 'n/a';
let axeCount = 'n/a';
if (paExists) {
try {
const pa = JSON.parse(fs.readFileSync('pa11y.json', 'utf8'));
paCount = Array.isArray(pa) ? pa.length : (pa.issues ? pa.issues.length : Object.keys(pa).length);
} catch (e) {
paCount = 'parse error';
}
}
if (axeExists) {
try {
const axe = JSON.parse(fs.readFileSync('axe-results.json', 'utf8'));
if (axe.error) {
axeCount = 'audit error';
} else {
axeCount = (axe.violations && axe.violations.length) ? axe.violations.length : 0;
}
} catch (e) {
axeCount = 'parse error';
}
}
const artifactsUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/artifacts`;
const body = `Accessibility report summary:\n- Pa11y issues: ${paCount}\n- Axe violations: ${axeCount}\n\nDownload artifacts (pa11y.json, axe-results.json) from the workflow run: ${artifactsUrl}`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});