-
Notifications
You must be signed in to change notification settings - Fork 321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pa11y testing and reporting #294
Merged
Merged
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
b63a39c
add pa11y-ci reporting
bollwyvl 5755c49
update docs
bollwyvl ab8748e
fix warnings in new docs
bollwyvl cb3149d
linting, comment out a roadmap item so it will fail
bollwyvl 1c10ad7
add some developer docs, in-browser tools
bollwyvl 2ca1778
try to get audit to show up in annotation
bollwyvl dfabae5
yep, i sure don't know rst
bollwyvl e26b2cb
try annotations directly
bollwyvl ecf6970
clean up more docs
bollwyvl c8001f2
Merge remote-tracking branch 'upstream/master' into add-pa11y
bollwyvl 8e122bb
further streamline test workflow
bollwyvl 970ddd5
rework language about audits, links to specs
bollwyvl 8db7e24
fix reporter
bollwyvl 0997016
address more comments
bollwyvl 4bb257c
uncomment intentional fail
bollwyvl 125d5fb
restore http streaming log
bollwyvl eb84c10
more reporting
bollwyvl fac2b3d
get SEO score back up by adding metatags, normalizing URLs to 127.0.0.1
bollwyvl c846cae
fix url for accessibility page in lighthouse
bollwyvl 3376f82
tweak some language settings
bollwyvl 7c41ef5
merge upstream
bollwyvl 746c5d0
yarn config updates
bollwyvl 7149244
resolve yarn.lock
bollwyvl 88c60f3
merge upstream
bollwyvl d6c043d
resolve yarn.lock
bollwyvl 6aef1c6
merge upstream
bollwyvl c8ecd78
resolve yarn.lock
bollwyvl df90d50
revert default port to 8000
bollwyvl 1f1ba7a
install nodejs
bollwyvl 11a4650
improve artifact uploading
bollwyvl 809c5ab
Update docs/user_guide/accessibility.rst
bollwyvl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,7 @@ jobs: | |
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v1 | ||
with: | ||
|
@@ -120,14 +121,21 @@ jobs: | |
HOST: 127.0.0.1 | ||
# the base url | ||
URL: http://127.0.0.1:8000 | ||
PA11Y_BUILD: /tmp/pa11y/pa11y-${{ github.run_number }} | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Set up Node/yarn | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: '10.x' | ||
|
||
- name: Cache python wheels | ||
uses: actions/cache@v2 | ||
with: | ||
|
@@ -138,10 +146,18 @@ jobs: | |
${{ runner.os }}-pip-${{ matrix.python-version }}- | ||
${{ runner.os }}-pip- | ||
|
||
- name: Cache node_modules | ||
uses: actions/cache@v2 | ||
with: | ||
path: 'node_modules' | ||
key: | | ||
${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock') }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip wheel setuptools | ||
python -m pip install -e .[coverage] | ||
yarn --frozen-lockfile | ||
|
||
# Build the docs | ||
- name: Build docs to store | ||
|
@@ -159,6 +175,7 @@ jobs: | |
# TODO: use the hosted API with a secret? would allow for comparison over time... | ||
- name: Make folder for Lighthouse reports | ||
run: mkdir -p /tmp/lighthouse/lighthouse-${{ github.run_number }} | ||
|
||
- name: Run Lighthouse on Site | ||
id: lighthouse | ||
uses: foo-software/[email protected] | ||
|
@@ -168,16 +185,13 @@ jobs: | |
${{ env.URL }}/index.html, | ||
${{ env.URL }}/demo/api.html, | ||
${{ env.URL }}/demo/demo.html, | ||
${{ env.URL }}/demo/example_pandas.html | ||
${{ env.URL }}/demo/example_pandas.html, | ||
${{ env.URL }}/user_guide/accessibility.html | ||
outputDirectory: /tmp/lighthouse/lighthouse-${{ github.run_number }} | ||
verbose: true | ||
|
||
# Store the audit | ||
- name: Upload Lighthouse Reports | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: Lighthouse Report ${{ github.run_number }} | ||
path: /tmp/lighthouse | ||
- name: Run the accessibility audit | ||
run: python docs/a11y.py --no-serve | ||
|
||
# Check the audit for threshold values | ||
# TODO: write this someplace after a PR is merged, and load? | ||
|
@@ -189,6 +203,16 @@ jobs: | |
minBestPracticesScore: "85" | ||
minPerformanceScore: "10" | ||
minSeoScore: "80" | ||
if: always() | ||
|
||
- name: Publish Audit reports | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: Pa11y and Lighthouse ${{ github.run_number }} | ||
path: | | ||
/tmp/pa11y | ||
/tmp/lighthouse | ||
if: always() | ||
|
||
publish: | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,4 +104,5 @@ envs/ | |
|
||
node_modules/ | ||
.vscode | ||
.yarn-packages | ||
.idea |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
yarn-offline-mirror "./.yarn-packages" | ||
yarn-offline-mirror-pruning true | ||
ignore-optional true | ||
prefer-offline true |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# These are the pa11y error codes we'd like to fix. PRs welcome! | ||
|
||
WCAG2AA.Principle1.Guideline1_3.1_3_1.H39.3.LayoutTable | ||
WCAG2AA.Principle1.Guideline1_3.1_3_1.H43,H63 | ||
WCAG2AA.Principle1.Guideline1_3.1_3_1.H43.HeadersRequired | ||
WCAG2AA.Principle1.Guideline1_4.1_4_3.G18.Fail | ||
WCAG2AA.Principle3.Guideline3_2.3_2_2.H32.2 | ||
WCAG2AA.Principle4.Guideline4_1.4_1_2.H91.A.EmptyNoId | ||
WCAG2AA.Principle4.Guideline4_1.4_1_2.H91.A.NoContent |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
""" use pa11y-ci to generate an accessibility report | ||
""" | ||
import json | ||
import os | ||
import shutil | ||
import subprocess | ||
import sys | ||
import time | ||
from collections import defaultdict | ||
from pathlib import Path | ||
from urllib.error import URLError | ||
from urllib.request import urlopen | ||
from yaml import safe_dump | ||
|
||
HERE = Path(__file__).parent.resolve() | ||
ROOT = HERE.parent | ||
BUILD = HERE / "_build" | ||
PA11Y_BUILD = Path(os.environ.get("PA11Y_BUILD", BUILD / "pa11y")) | ||
PA11Y_JSON = PA11Y_BUILD / "pa11y-ci-results.json" | ||
PA11Y_ROADMAP = HERE / "a11y-roadmap.txt" | ||
YARN = [shutil.which("yarn"), "--silent"] | ||
SITEMAP = "http://127.0.0.1:8000/sitemap.xml" | ||
REPORT_INDEX_URL = (PA11Y_BUILD / "index.html").as_uri() | ||
|
||
|
||
def clean(): | ||
if PA11Y_BUILD.exists(): | ||
shutil.rmtree(PA11Y_BUILD) | ||
PA11Y_BUILD.mkdir(parents=True) | ||
|
||
|
||
def serve(): | ||
"""start the local server""" | ||
server = subprocess.Popen( | ||
[sys.executable, HERE / "serve.py"], | ||
) | ||
ready = 0 | ||
retries = 10 | ||
while retries and not ready: | ||
retries -= 1 | ||
try: | ||
time.sleep(1) | ||
ready = urlopen(SITEMAP) | ||
except URLError: | ||
pass | ||
|
||
assert ready, "server did not start in 10 seconds" | ||
|
||
return server | ||
|
||
|
||
def audit(): | ||
"""run audit, generating a raw JSON report""" | ||
audit_rc = subprocess.call( | ||
f"yarn --silent pa11y-ci --json --sitemap {SITEMAP} > {PA11Y_JSON}", | ||
shell=True, | ||
cwd=ROOT, | ||
) | ||
|
||
return audit_rc | ||
|
||
|
||
def report(): | ||
"""generate HTML report from raw JSON""" | ||
subprocess.call( | ||
[ | ||
*YARN, | ||
"pa11y-ci-reporter-html", | ||
"--source", | ||
PA11Y_JSON, | ||
"--destination", | ||
PA11Y_BUILD, | ||
], | ||
cwd=ROOT, | ||
) | ||
|
||
|
||
def summary(): | ||
"""generate a summary and return the number of errors not ignored explicitly""" | ||
report = dict( | ||
HTML=REPORT_INDEX_URL, Roadmap=str(PA11Y_ROADMAP), JSON=str(PA11Y_JSON) | ||
) | ||
|
||
pa11y_json = json.loads(PA11Y_JSON.read_text()) | ||
pa11y_roadmap = [ | ||
line.split("#")[0].strip() | ||
for line in PA11Y_ROADMAP.read_text().splitlines() | ||
if line.strip() and not line.strip().startswith("#") | ||
] | ||
|
||
error_codes = defaultdict(lambda: 0) | ||
|
||
for page, results in pa11y_json["results"].items(): | ||
for result in results: | ||
if "code" in result: | ||
error_codes[result["code"]] += 1 | ||
|
||
roadmap_counts = {} | ||
not_roadmap_counts = {} | ||
|
||
for code, count in sorted(error_codes.items()): | ||
code_on_roadmap = code in pa11y_roadmap | ||
if code_on_roadmap: | ||
roadmap_counts[code] = count | ||
else: | ||
not_roadmap_counts[code] = count | ||
|
||
report.update( | ||
{ | ||
"total errors": pa11y_json["errors"], | ||
"on roadmap": roadmap_counts, | ||
"not on roadmap": not_roadmap_counts, | ||
} | ||
) | ||
|
||
nrc = sum(not_roadmap_counts.values()) | ||
report["passed"] = nrc == 0 | ||
report_str = safe_dump(report, default_flow_style=False) | ||
|
||
if os.environ.get("CI") and nrc: | ||
print("""::error ::{}""".format(report_str.replace("\n", "%0A"))) | ||
else: | ||
print(report_str) | ||
|
||
return nrc | ||
|
||
|
||
def main(no_serve=True): | ||
"""start the server (if needed), then audit, report, and clean up""" | ||
clean() | ||
server = None | ||
try: | ||
if not no_serve: | ||
server = serve() | ||
audit() | ||
report() | ||
finally: | ||
server and server.terminate() | ||
|
||
error_count = summary() | ||
|
||
return error_count | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main(no_serve="--no-serve" in sys.argv)) |
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
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why don't we just use
sphinx_sitemap
anyway? Do they clash or something? I'd be fine just using the extension rather than special-casing RTD unless it's noticeably betterThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the RTD one is generally better. is aware of versions/languages, etc.