Add cancellation guidance to roles #120
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: pa11y-accessibility-check | |
on: | |
pull_request_target: | |
types: [opened, synchronize, reopened] | |
jobs: | |
accessibility_assessment_comment: | |
runs-on: ubuntu-latest | |
container: | |
image: mcr.microsoft.com/playwright:v1.42.1-jammy # includes Chromium, Node, and tools | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
fetch-depth: 0 | |
- name: Set up Python 3.11 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.11.6' | |
- name: Install Poetry | |
run: | | |
curl -sSL https://install.python-poetry.org | python3 - | |
echo "$HOME/.local/bin" >> $GITHUB_PATH | |
- name: Install dependencies | |
run: | | |
export PATH="$HOME/.local/bin:$PATH" | |
poetry install | |
- name: Cache executed notebooks | |
uses: actions/cache@v4 | |
with: | |
path: _build/.jupyter_cache | |
key: jupyter-book-cache-${{ hashFiles('pyproject.toml') }} | |
- name: Build the book | |
run: poetry run jupyter-book build . | |
- name: Upload error logs | |
uses: actions/upload-artifact@v4 | |
with: | |
name: error-logs | |
path: _build/html/reports/pathways/related_courses.err.log | |
continue-on-error: true | |
- name: Install Node.js and dependencies | |
run: | | |
apt-get update | |
apt-get install -y curl gnupg jq findutils | |
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - | |
apt-get install -y nodejs | |
npm install --save-dev pa11y-ci | |
npx puppeteer browsers install chrome | |
- name: Identify changed files and map to HTML | |
id: map_html_targets | |
shell: bash | |
run: | | |
git config --global --add safe.directory "$GITHUB_WORKSPACE" | |
declare -A seen | |
echo "[" > pa11y_targets.json | |
first=true | |
git fetch --no-tags --prune --progress --depth=100 origin ${{ github.base_ref }} | |
git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -E "\.md$|\.ipynb$" > changed_files.txt || true | |
echo "Changed source files:" | |
cat changed_files.txt || echo "None" | |
while IFS= read -r file; do | |
[ -z "$file" ] && continue | |
basefile=$(basename "$file") | |
name="${basefile%.*}" | |
matches=$(find _build/html -type f -name "${name}.html") | |
for match in $matches; do | |
if [[ -z "${seen[$match]}" ]]; then | |
seen[$match]=1 | |
if [ "$first" = true ]; then | |
first=false | |
else | |
echo "," >> pa11y_targets.json | |
fi | |
echo "\"$match\"" >> pa11y_targets.json | |
fi | |
done | |
done < changed_files.txt | |
echo "]" >> pa11y_targets.json | |
echo "Generated pa11y_targets.json:" | |
cat pa11y_targets.json | |
- name: Run Pa11y CI once on identified pages and save output | |
id: run_pa11y | |
shell: bash | |
run: | | |
touch pa11y_output.md | |
num_files=$(jq length pa11y_targets.json) | |
if [ "$num_files" -eq 0 ]; then | |
echo "No relevant HTML files to check. Skipping Pa11y." | tee pa11y_output.md | |
else | |
echo "### 🚦 Pa11y Accessibility Report" > pa11y_output.md | |
echo "" >> pa11y_output.md | |
# Run pa11y-ci once on all files listed in the config | |
result=$(npx pa11y-ci --reporter cli --config pa11yci.js 2>&1 || true) | |
echo "$result" >> pa11y_output.md | |
echo "" >> pa11y_output.md | |
echo "_⚠️ Any errors likely originate from the source file (e.g., \`filename.md\`, \`filename.ipynb\`)._" >> pa11y_output.md | |
fi | |
- name: 🔍 Debug comment body | |
run: | | |
echo "------- BEGIN COMMENT BODY -------" | |
cat pa11y_output.md | |
echo "-------- END COMMENT BODY --------" | |
- name: Debug GitHub context | |
run: | | |
echo "Event name: ${{ github.event_name }}" | |
echo "PR number: ${{ github.event.pull_request.number || 'None' }}" | |
- name: Find previous PR comment (if exists) | |
id: find_comment | |
uses: peter-evans/find-comment@v3 | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
comment-author: 'github-actions[bot]' | |
body-includes: '### 🚦 Pa11y Accessibility Report' | |
- name: Create or update PR comment with Pa11y results | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
issue-number: ${{ github.event.pull_request.number }} | |
body-path: pa11y_output.md | |
comment-id: ${{ steps.find_comment.outputs.comment-id }} | |
edit-mode: replace | |