♿️ access: add pa11y automated accessibility testing workflow #1
This file contains 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: Accessibility Tests | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
jobs: | |
pa11y: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Install pnpm | |
uses: pnpm/action-setup@v2 | |
with: | |
version: 8 | |
run_install: false | |
- name: Get pnpm store directory | |
shell: bash | |
run: | | |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV | |
- name: Setup pnpm cache | |
uses: actions/cache@v3 | |
with: | |
path: ${{ env.STORE_PATH }} | |
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | |
restore-keys: | | |
${{ runner.os }}-pnpm-store- | |
- name: Install dependencies | |
run: pnpm install | |
- name: Install pa11y | |
run: pnpm add -D pa11y | |
- name: Build Next.js app | |
run: pnpm build | |
- name: Start Next.js app | |
run: | | |
pnpm start & | |
sleep 10 # Wait for the app to be ready | |
- name: Run pa11y | |
run: | | |
# Create a directory for the reports | |
mkdir -p pa11y-reports | |
# Run pa11y on main pages and save reports | |
pnpm exec pa11y http://localhost:3000 > pa11y-reports/home.txt | |
pnpm exec pa11y http://localhost:3000/cv > pa11y-reports/cv.txt | |
pnpm exec pa11y http://localhost:3000/prosjekter > pa11y-reports/prosjekter.txt | |
pnpm exec pa11y http://localhost:3000/kontakt > pa11y-reports/kontakt.txt | |
- name: Upload pa11y results | |
if: always() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: pa11y-reports | |
path: pa11y-reports/ | |
- name: Check for accessibility issues | |
run: | | |
if grep -q "Error:" pa11y-reports/*.txt; then | |
echo "Accessibility issues found. Check the uploaded artifacts for details." | |
exit 1 | |
fi |