Skip to content

Merge pull request #4097 from OpenLiberty/staging #7

Merge pull request #4097 from OpenLiberty/staging

Merge pull request #4097 from OpenLiberty/staging #7

name: Accessibility tests for main pages
on:
push:
branches:
- prod
workflow_dispatch:
jobs:
run-accessibility-tests:
runs-on: ubuntu-latest
container: cypress/included:13.9.0
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: |
cd /__w/openliberty.io/openliberty.io/src/test/cypressjs
npm install
- name: Cleanup previous results
run: rm -rf /__w/openliberty.io/openliberty.io/src/test/cypressjs/results/*
- name: Cleanup Cypress Cache
run: rm -rf ~/.cache/Cypress
- name: Run first test file
run: |
cypress run --browser chrome --headed \
--env JDK_VERSION="1.8.0_311" \
--config-file /__w/openliberty.io/openliberty.io/src/test/cypressjs/cypress.config.js \
--spec "/__w/openliberty.io/openliberty.io/src/test/cypressjs/cypress/e2e/generalAllyTest.cy.js"
- name: Debug - List files
run: ls -R /__w/openliberty.io/openliberty.io/src/test/cypressjs/results
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install zip utility
run: apt-get update && apt-get install -y zip
- name: Analyze Accessibility Results
id: analyze_results
run: |
node <<'EOF'
import fs from 'fs';
import path from 'path';
import { execSync } from 'child_process';
const resultsDir = '/__w/openliberty.io/openliberty.io/src/test/cypressjs/results/OL.io';
if (!fs.existsSync(resultsDir)) {
console.log('No results directory found.');
process.exit(0);
}
const files = fs.readdirSync(resultsDir).filter(f => f.endsWith('.json'));
const violatingFiles = [];
for (const file of files) {
const filePath = path.join(resultsDir, file);
try {
const data = JSON.parse(fs.readFileSync(filePath, 'utf8'));
const violations = data?.summary?.counts?.violation ?? 0;
if (violations > 0) violatingFiles.push(file);
} catch (err) {
console.error(`Error parsing ${file}:`, err);
}
}
if (violatingFiles.length > 0) {
// Create ZIP of violating files for download
const zipName = 'violations_only.zip';
const fileList = violatingFiles.map(f => path.join(resultsDir, f)).join(' ');
execSync(`zip -j ${zipName} ${fileList}`);
// Store output for next steps
const fileNamesWithoutExt = violatingFiles.map(f => path.basename(f, '.json')).join(', ');
fs.appendFileSync(process.env.GITHUB_OUTPUT, `violations=${fileNamesWithoutExt}\n`);
fs.appendFileSync(process.env.GITHUB_OUTPUT, `zip_file=${zipName}\n`);
console.log('Violations found in:', fileNamesWithoutExt);
} else {
console.log('No accessibility violations found.');
}
EOF
- name: Upload Violations ZIP
if: steps.analyze_results.outputs.zip_file != ''
uses: actions/upload-artifact@v4
with:
name: accessibility-violations
path: ${{ steps.analyze_results.outputs.zip_file }}
retention-days: 7
- name: Generate Issue Content
if: steps.analyze_results.outputs.violations != ''
run: |
echo "### Accessibility Violations Detected" > issue.md
echo "" >> issue.md
echo "Cypress has reported accessibility violations on the following pages:" >> issue.md
echo "${{ steps.analyze_results.outputs.violations }}" >> issue.md
echo "" >> issue.md
echo "[Download violating result files (ZIP)](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> issue.md
echo "" >> issue.md
echo "_This issue was automatically generated by the accessibility testing workflow._" >> issue.md
- name: Create GitHub Issue
if: steps.analyze_results.outputs.violations != ''
uses: peter-evans/create-issue-from-file@v5
with:
title: "Accessibility violations detected in main pages"
content-filepath: issue.md
labels: a11y