|
1 |
| - |
2 |
| -name: Accessibility check (Pa11y) |
| 1 | +name: pa11y-accessibility-check |
3 | 2 |
|
4 | 3 | on:
|
5 |
| - pull_request: |
6 |
| - branches: [ "main" ] |
7 |
| - workflow_dispatch: |
| 4 | + pull_request_target: |
| 5 | + types: [opened, synchronize, reopened] |
8 | 6 |
|
9 | 7 | jobs:
|
10 |
| - pa11y: |
| 8 | + accessibility_assessment_comment: |
11 | 9 | runs-on: ubuntu-latest
|
| 10 | + container: |
| 11 | + image: mcr.microsoft.com/playwright:v1.42.1-jammy # includes Chromium, Node, and tools |
12 | 12 | steps:
|
13 |
| - - uses: actions/checkout@v4 |
| 13 | + - uses: actions/checkout@v3 |
| 14 | + with: |
| 15 | + ref: ${{ github.event.pull_request.head.sha }} |
| 16 | + fetch-depth: 0 |
| 17 | + |
| 18 | + - name: Set up Python 3.11 |
| 19 | + uses: actions/setup-python@v4 |
| 20 | + with: |
| 21 | + python-version: '3.11.6' |
| 22 | + |
| 23 | + - name: Install Poetry |
| 24 | + run: | |
| 25 | + curl -sSL https://install.python-poetry.org | python3 - |
| 26 | + echo "$HOME/.local/bin" >> $GITHUB_PATH |
| 27 | +
|
| 28 | + - name: Install dependencies |
| 29 | + run: | |
| 30 | + export PATH="$HOME/.local/bin:$PATH" |
| 31 | + poetry install |
14 | 32 |
|
15 |
| - - uses: actions/setup-node@v4 |
| 33 | + - name: Cache executed notebooks |
| 34 | + uses: actions/cache@v4 |
16 | 35 | with:
|
17 |
| - node-version: '20' |
| 36 | + path: _build/.jupyter_cache |
| 37 | + key: jupyter-book-cache-${{ hashFiles('pyproject.toml') }} |
18 | 38 |
|
19 |
| - - name: Install pa11y |
20 |
| - run: npm install -g pa11y pa11y-ci |
| 39 | + - name: Build the book |
| 40 | + run: poetry run jupyter-book build . |
21 | 41 |
|
22 |
| - - name: Build site |
23 |
| - uses: actions/setup-python@v5 |
| 42 | + - name: Upload error logs |
| 43 | + uses: actions/upload-artifact@v4 |
24 | 44 | with:
|
25 |
| - python-version: '3.11' |
26 |
| - - run: | |
27 |
| - python -m pip install --upgrade pip |
28 |
| - pip install -r requirements.in |
29 |
| - jupyter-book build . |
| 45 | + name: error-logs |
| 46 | + path: _build/html/reports/pathways/related_courses.err.log |
| 47 | + continue-on-error: true |
30 | 48 |
|
31 |
| - - name: Run pa11y-ci on homepage |
| 49 | + - name: Install Node.js and dependencies |
32 | 50 | run: |
|
33 |
| - # Check the built homepage for common accessibility issues |
34 |
| - pa11y-ci --sitemap false "_build/html/index.html" || true |
| 51 | + apt-get update |
| 52 | + apt-get install -y curl gnupg jq findutils |
| 53 | + curl -fsSL https://deb.nodesource.com/setup_20.x | bash - |
| 54 | + apt-get install -y nodejs |
| 55 | + npm install --save-dev pa11y-ci |
| 56 | + npx puppeteer browsers install chrome |
| 57 | +
|
| 58 | + - name: Identify changed files and map to HTML |
| 59 | + id: map_html_targets |
| 60 | + shell: bash |
| 61 | + run: | |
| 62 | + git config --global --add safe.directory "$GITHUB_WORKSPACE" |
| 63 | +
|
| 64 | + declare -A seen |
| 65 | + echo "[" > pa11y_targets.json |
| 66 | + first=true |
| 67 | +
|
| 68 | + git fetch --no-tags --prune --progress --depth=100 origin ${{ github.base_ref }} |
| 69 | + git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -E "\.md$|\.ipynb$" > changed_files.txt || true |
| 70 | + echo "Changed source files:" |
| 71 | + cat changed_files.txt || echo "None" |
| 72 | +
|
| 73 | + while IFS= read -r file; do |
| 74 | + [ -z "$file" ] && continue |
| 75 | + basefile=$(basename "$file") |
| 76 | + name="${basefile%.*}" |
| 77 | + matches=$(find _build/html -type f -name "${name}.html") |
| 78 | + for match in $matches; do |
| 79 | + if [[ -z "${seen[$match]}" ]]; then |
| 80 | + seen[$match]=1 |
| 81 | + if [ "$first" = true ]; then |
| 82 | + first=false |
| 83 | + else |
| 84 | + echo "," >> pa11y_targets.json |
| 85 | + fi |
| 86 | + echo "\"$match\"" >> pa11y_targets.json |
| 87 | + fi |
| 88 | + done |
| 89 | + done < changed_files.txt |
| 90 | +
|
| 91 | + echo "]" >> pa11y_targets.json |
| 92 | + echo "Generated pa11y_targets.json:" |
| 93 | + cat pa11y_targets.json |
| 94 | +
|
| 95 | +
|
| 96 | + - name: Run Pa11y CI once on identified pages and save output |
| 97 | + id: run_pa11y |
| 98 | + shell: bash |
| 99 | + run: | |
| 100 | + touch pa11y_output.md |
| 101 | +
|
| 102 | + num_files=$(jq length pa11y_targets.json) |
| 103 | + if [ "$num_files" -eq 0 ]; then |
| 104 | + echo "No relevant HTML files to check. Skipping Pa11y." | tee pa11y_output.md |
| 105 | + else |
| 106 | + echo "### 🚦 Pa11y Accessibility Report" > pa11y_output.md |
| 107 | + echo "" >> pa11y_output.md |
| 108 | +
|
| 109 | + # Run pa11y-ci once on all files listed in the config |
| 110 | + result=$(npx pa11y-ci --reporter cli --config pa11yci.js 2>&1 || true) |
| 111 | + echo "$result" >> pa11y_output.md |
| 112 | +
|
| 113 | + echo "" >> pa11y_output.md |
| 114 | + echo "_⚠️ Any errors likely originate from the source file (e.g., \`filename.md\`, \`filename.ipynb\`)._" >> pa11y_output.md |
| 115 | + fi |
| 116 | +
|
| 117 | + - name: 🔍 Debug comment body |
| 118 | + run: | |
| 119 | + echo "------- BEGIN COMMENT BODY -------" |
| 120 | + cat pa11y_output.md |
| 121 | + echo "-------- END COMMENT BODY --------" |
| 122 | +
|
| 123 | + - name: Debug GitHub context |
| 124 | + run: | |
| 125 | + echo "Event name: ${{ github.event_name }}" |
| 126 | + echo "PR number: ${{ github.event.pull_request.number || 'None' }}" |
| 127 | +
|
| 128 | + - name: Find previous PR comment (if exists) |
| 129 | + id: find_comment |
| 130 | + uses: peter-evans/find-comment@v3 |
| 131 | + with: |
| 132 | + issue-number: ${{ github.event.pull_request.number }} |
| 133 | + comment-author: 'github-actions[bot]' |
| 134 | + body-includes: '### 🚦 Pa11y Accessibility Report' |
| 135 | + |
| 136 | + - name: Create or update PR comment with Pa11y results |
| 137 | + uses: peter-evans/create-or-update-comment@v4 |
| 138 | + with: |
| 139 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 140 | + issue-number: ${{ github.event.pull_request.number }} |
| 141 | + body-path: pa11y_output.md |
| 142 | + comment-id: ${{ steps.find_comment.outputs.comment-id }} |
| 143 | + edit-mode: replace |
| 144 | + |
| 145 | + |
| 146 | + |
0 commit comments