Skip to content

Commit 16bac57

Browse files
Update github actions
1 parent 2f946c3 commit 16bac57

File tree

3 files changed

+223
-82
lines changed

3 files changed

+223
-82
lines changed

.github/workflows/accessibility.yml

Lines changed: 133 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,146 @@
1-
2-
name: Accessibility check (Pa11y)
1+
name: pa11y-accessibility-check
32

43
on:
5-
pull_request:
6-
branches: [ "main" ]
7-
workflow_dispatch:
4+
pull_request_target:
5+
types: [opened, synchronize, reopened]
86

97
jobs:
10-
pa11y:
8+
accessibility_assessment_comment:
119
runs-on: ubuntu-latest
10+
container:
11+
image: mcr.microsoft.com/playwright:v1.42.1-jammy # includes Chromium, Node, and tools
1212
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
1432
15-
- uses: actions/setup-node@v4
33+
- name: Cache executed notebooks
34+
uses: actions/cache@v4
1635
with:
17-
node-version: '20'
36+
path: _build/.jupyter_cache
37+
key: jupyter-book-cache-${{ hashFiles('pyproject.toml') }}
1838

19-
- name: Install pa11y
20-
run: npm install -g pa11y pa11y-ci
39+
- name: Build the book
40+
run: poetry run jupyter-book build .
2141

22-
- name: Build site
23-
uses: actions/setup-python@v5
42+
- name: Upload error logs
43+
uses: actions/upload-artifact@v4
2444
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
3048

31-
- name: Run pa11y-ci on homepage
49+
- name: Install Node.js and dependencies
3250
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+

.github/workflows/build-book.yml

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,47 @@
1+
name: Build Book
12

2-
name: Build Jupyter Book (PR check)
3-
3+
# Run this on pull requests
44
on:
55
pull_request:
6-
branches: [ "main" ]
7-
workflow_dispatch:
6+
branches:
7+
- main
88

99
jobs:
10-
build:
10+
build-book:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v4
14-
- uses: actions/setup-python@v5
15-
with:
16-
python-version: '3.11'
17-
- name: Install dependencies
18-
run: |
19-
python -m pip install --upgrade pip
20-
pip install -r requirements.in
21-
- name: Build Jupyter Book
22-
run: jupyter-book build .
13+
- uses: actions/checkout@v3
14+
15+
# Install dependencies
16+
- name: Set up Python 3.11
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: 3.11
20+
21+
- name: Install Poetry
22+
run: |
23+
curl -sSL https://install.python-poetry.org | python3 -
24+
25+
- name: Install dependencies
26+
run: |
27+
poetry install
28+
29+
# (optional) Cache your executed notebooks between runs
30+
- name: Cache executed notebooks
31+
uses: actions/cache@v4
32+
with:
33+
path: _build/.jupyter_cache
34+
key: jupyter-book-cache-${{ hashFiles('pyproject.toml') }}
35+
36+
# Build the book
37+
- name: Build the book
38+
run: |
39+
poetry run jupyter-book build .
40+
41+
# Always upload logs, even if build succeeds
42+
- name: Upload error logs
43+
uses: actions/upload-artifact@v4
44+
with:
45+
name: error-logs
46+
path: _build/html/reports/pathways/related_courses.err.log
47+
continue-on-error: true

.github/workflows/deploy-book.yml

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,57 @@
1+
name: Deploy Book
12

2-
name: Deploy Jupyter Book to GitHub Pages
3-
3+
# Run on push to main branch, on a schedule, and allow manual trigger
44
on:
55
push:
6-
branches: [ "main" ]
7-
workflow_dispatch:
8-
9-
permissions:
10-
contents: read
11-
pages: write
12-
id-token: write
13-
14-
concurrency:
15-
group: "pages"
16-
cancel-in-progress: true
6+
branches:
7+
- main
8+
schedule:
9+
# Runs at 1 AM UTC every day
10+
- cron: '0 1 * * *'
11+
workflow_dispatch: # Allows manual trigger from the GitHub Actions tab
1712

1813
jobs:
19-
build:
20-
runs-on: ubuntu-latest
21-
steps:
22-
- name: Checkout
23-
uses: actions/checkout@v4
24-
25-
- name: Set up Python
26-
uses: actions/setup-python@v5
27-
with:
28-
python-version: '3.11'
29-
30-
- name: Install dependencies
31-
run: |
32-
python -m pip install --upgrade pip
33-
pip install -r requirements.in
34-
35-
- name: Build Jupyter Book
36-
run: |
37-
jupyter-book build .
38-
39-
- name: Upload artifact
40-
uses: actions/upload-pages-artifact@v3
41-
with:
42-
path: _build/html
43-
44-
deploy:
45-
needs: build
14+
deploy-book:
4615
runs-on: ubuntu-latest
47-
environment:
48-
name: github-pages
49-
url: ${{ steps.deployment.outputs.page_url }}
16+
permissions:
17+
pages: write
18+
id-token: write
5019
steps:
51-
- name: Deploy to GitHub Pages
52-
id: deployment
53-
uses: actions/deploy-pages@v4
20+
- uses: actions/checkout@v3
21+
22+
# Install dependencies
23+
- name: Set up Python 3.11
24+
uses: actions/setup-python@v4
25+
with:
26+
python-version: 3.11
27+
28+
- name: Install Poetry
29+
run: |
30+
curl -sSL https://install.python-poetry.org | python3 -
31+
32+
- name: Install dependencies
33+
run: |
34+
poetry install
35+
36+
# (optional) Cache your executed notebooks between runs
37+
- name: Cache executed notebooks
38+
uses: actions/cache@v4
39+
with:
40+
path: _build/.jupyter_cache
41+
key: jupyter-book-cache-${{ hashFiles('pyproject.toml') }}
42+
43+
# Build the book
44+
- name: Build the book
45+
run: |
46+
poetry run jupyter-book build .
47+
48+
# Upload the book's HTML as an artifact
49+
- name: Upload artifact
50+
uses: actions/upload-pages-artifact@v3
51+
with:
52+
path: "_build/html"
53+
54+
# Deploy the book's HTML to GitHub Pages
55+
- name: Deploy to GitHub Pages
56+
id: deployment
57+
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)