Skip to content

Commit 55425a2

Browse files
authored
Merge branch 'main' into add-machine-learning-quiz
2 parents 7f1a0a4 + d4af10e commit 55425a2

File tree

118 files changed

+24791
-10624
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+24791
-10624
lines changed

.github/workflows/accessibility.yml

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

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
.ipynb_checkpoints/
33
individual_modules/introduction_to_machine_learning/datasets
44
_build/
5+
6+
# Files when running R locally
7+
renv/
8+
renv.lock
9+
.Rprofile

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ Then navigate to the course content of interest (e.g. open the notebooks in `ind
7474
(Optional) Build the Jupyter Book site locally:
7575

7676
To build the complete website from this repository, run:
77+
7778
```bash
78-
jupyter-book build
79+
jupyter-book build .
7980
```
8081

8182
This will generate the static site under the `_build/html/` directory, which you can open in a browser to view the book offline. (This step requires the `jupyter-book` package, which is included in the requirements.)

0 commit comments

Comments
 (0)