Skip to content

[Documentation] Accessibility Check #334

[Documentation] Accessibility Check

[Documentation] Accessibility Check #334

name: '[Documentation] Accessibility Check'
on:
workflow_dispatch:
# Run on Weekdays at 9:00 AM UTC, 4AM ET, 1:00 AM PT
schedule:
- cron: '0 9 * * 1,2,3,4,5'
jobs:
axe-scan:
name: Accessibility Check
runs-on: ubuntu-latest
outputs:
pages_with_errors: ${{ steps.accessibility_check.outputs.pages_with_errors }}
total_errors: ${{ steps.accessibility_check.outputs.total_errors }}
steps:
- uses: actions/checkout@v4
- name: Install Axe CLI globally
run: |
npm install @axe-core/cli -g
- uses: actions/setup-node@v4
with:
node-version-file: 'VAMobile/.nvmrc'
cache: yarn
cache-dependency-path: VAMobile/documentation/yarn.lock
- name: Install ChromeDriver
run: npm install -g chromedriver
- name: Install mobile app modules
working-directory: VAMobile
run: |
yarn install --frozen-lockfile
- name: Start web server
working-directory: VAMobile/documentation
run: |
yarn install --frozen-lockfile
yarn build
yarn start &
npx wait-on http://localhost:3000 &
sleep 10
- name: Check accessibility issues
id: accessibility_check
run: |
# Path to the downloaded sitemap file
sitemap_path="VAMobile/documentation/build/sitemap.xml"
# Counter for urls with errors
pages_with_errors=0
# Counter for total errors
total_errors=0
for url in $(grep -o '<loc>[^<]*' "$sitemap_path" | sed 's/<loc>//');
do
# save output so that we can send it to std out AND do an operation on it
output=$(axe "$url")
# send output to stdout
echo "${output}"
# regex number of issues NOTE: grep exits 1 if it finds no match. GH Actions exits the runner if anything exits 1 so we add the || true to overcome that
issues=$(echo "${output}" | grep -oP '\d+(?= Accessibility issues detected)' || true)
# If issues is not an empty string, there were issues
if [[ ! -z "$issues" ]]
then
pages_with_errors=$((pages_with_errors + 1))
total_errors=$((total_errors + issues))
fi
done
# Output to runner
echo "pages_with_errors=$pages_with_errors" >> $GITHUB_OUTPUT
echo "total_errors=$total_errors" >> $GITHUB_OUTPUT
start_slack_thread:
name: Start Slack thread
needs: axe-scan
uses: ./.github/workflows/start_slack_thread.yml
secrets: inherit
with:
channel_name: va-mobile-build-alerts
message: 'Accessibility issues detected in the documentation site. Please review and fix. See :thread: or <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|workflow run> for results. Number of pages with errors: ${{ needs.axe-scan.outputs.pages_with_errors }}. Total number of accessibility issues detected: ${{ needs.axe-scan.outputs.total_errors }}'