Skip to content

Commit 853f982

Browse files
Create a11y-main.yml
1 parent 938cde8 commit 853f982

1 file changed

Lines changed: 98 additions & 0 deletions

File tree

.github/workflows/a11y-main.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Accessibility Checks (main)
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- gh-pages
7+
workflow_dispatch:
8+
9+
env:
10+
# SITE_SUBDIR is where your site is deployed.
11+
# If deployed at example.com/notes, SITE_SUBDIR should be
12+
# "notes" if deployed at the root, leave empty
13+
SITE_SUBDIR: ${{ github.event.repository.name }}
14+
15+
permissions:
16+
contents: read
17+
pages: read
18+
19+
jobs:
20+
axe-audit-render-from-main:
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
# 1. Checkout Code
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
28+
# 2. Setup Quarto
29+
- name: Set up Quarto
30+
uses: quarto-dev/quarto-actions/setup@v2
31+
32+
# 3. Setup Node.js (for Axe and http-server)
33+
- name: Set up Node.js
34+
uses: actions/setup-node@v4
35+
with:
36+
node-version: '20'
37+
38+
# 5. Render the Site
39+
- name: Render Quarto Site
40+
run: quarto render
41+
42+
# 6. Install Tools
43+
- name: Install Axe and Server
44+
run: npm install -g @axe-core/cli http-server wait-on
45+
46+
# 7. Determine the Production URL via GitHub Pages metadata
47+
- name: Set Production URL
48+
env:
49+
GH_TOKEN: ${{ github.token }}
50+
run: |
51+
# Fetch the URL configured in Settings > Pages
52+
# This returns the custom domain or the username.github.io/repo URL
53+
PAGES_URL=$(gh api repos/${{ github.repository }}/pages --template '{{.html_url}}')
54+
55+
echo "PRODUCTION_URL=$PAGES_URL" >> $GITHUB_ENV
56+
echo "Detected Production URL: $PAGES_URL"
57+
58+
# 8. Start Local Server (Background Process)
59+
- name: Start Local Server
60+
run: |
61+
# We create a 'public/SITE_SUBDIR' folder so the local server
62+
# mimics the production path structure exactly.
63+
mkdir -p public/${{ env.SITE_SUBDIR }}
64+
cp -r _site/* public/${{ env.SITE_SUBDIR }}/
65+
66+
# Serve the 'public' folder on port 3000
67+
npx http-server ./public -p 3000 > /dev/null 2>&1 &
68+
npx wait-on http://localhost:3000/
69+
70+
# 9. Run Axe Scan
71+
- name: Run Accessibility Scan
72+
id: axe-scan
73+
run: |
74+
# Swap the Production URL for Localhost + Subdirectory
75+
CLEAN_PROD_URL=$(echo "$PRODUCTION_URL" | sed 's|/$||')
76+
LOCAL_URL="http://localhost:3000/${{ env.SITE_SUBDIR }}/"
77+
78+
URLS=$(cat _site/sitemap.xml | \
79+
sed -n 's/.*<loc>\(.*\)<\/loc>.*/\1/p' | \
80+
sed "s|$CLEAN_PROD_URL|$LOCAL_URL|" | \
81+
tr '\n' ' ')
82+
83+
echo "Scanning the following pages:"
84+
echo "$URLS"
85+
86+
# Run Axe
87+
axe $URLS \
88+
--tags wcag2a,wcag2aa,wcag21a,wcag21aa \
89+
--save axe-report.json \
90+
--exit
91+
92+
# 10. Upload Report (Runs even if Step 8 fails)
93+
- name: Upload Accessibility Report
94+
if: always()
95+
uses: actions/upload-artifact@v4
96+
with:
97+
name: axe-report
98+
path: axe-report.json

0 commit comments

Comments
 (0)