From 94893b3e58193f8d41269e19f414974ebe3f70a7 Mon Sep 17 00:00:00 2001 From: dulude Date: Wed, 4 Dec 2024 13:31:15 -0500 Subject: [PATCH 01/10] refactored html_accessibility_check.yml to use a11ywatch API instead of GH action --- .github/workflows/html_accessibility_check.yml | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/.github/workflows/html_accessibility_check.yml b/.github/workflows/html_accessibility_check.yml index 5459479..75ce639 100644 --- a/.github/workflows/html_accessibility_check.yml +++ b/.github/workflows/html_accessibility_check.yml @@ -25,17 +25,7 @@ jobs: a11yWatchRun: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Web Accessibility Evaluation of ${{ inputs.target_url }} - uses: a11ywatch/github-actions@v2.1.10 - with: - WEBSITE_URL: ${{ inputs.target_url }} - SITE_WIDE: true - SUBDOMAINS: true - SITEMAP: true - UPGRADE: true - LIST: true - EXTERNAL: true - UPLOAD: true - FAIL_ERRORS_COUNT: 1 - A11YWATCH_TOKEN: ${{ secrets.A11YWATCH_TOKEN }} + - name: Run PEP8 style check + run: | + curl --location --request POST 'https://api.a11ywatch.com/api/crawl' --header 'Authorization: ${{ secrets.A11YWATCH_TOKEN }}' --header 'Content-Type: application/json' -d '{ "url": "${{ inputs.target_url }}" }' + From a56146474d91c47bfa9cbbfce1415eab7bd578ce Mon Sep 17 00:00:00 2001 From: dulude Date: Wed, 4 Dec 2024 15:18:36 -0500 Subject: [PATCH 02/10] initial commit of parse_json.py --- .github/helpers/parse_json.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/helpers/parse_json.py diff --git a/.github/helpers/parse_json.py b/.github/helpers/parse_json.py new file mode 100644 index 0000000..329ff62 --- /dev/null +++ b/.github/helpers/parse_json.py @@ -0,0 +1,13 @@ +import json +import json_repair #will have to pip install +import pdb + +json_filename = 'barf1.json' + +# Fix any json formatting errors +json_object = json_repair.from_file(json_filename) + +# pretty print json filecld +json_formatted_str = json.dumps(json_object, indent=2) +print(json_formatted_str) +pdb.set_trace() \ No newline at end of file From 7aa2880cb4bd9d3b8b548a1da5605c684007e10f Mon Sep 17 00:00:00 2001 From: dulude Date: Wed, 4 Dec 2024 15:54:37 -0500 Subject: [PATCH 03/10] fleshed out parse_json.py --- .github/helpers/parse_json.py | 41 ++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/.github/helpers/parse_json.py b/.github/helpers/parse_json.py index 329ff62..922bdcb 100644 --- a/.github/helpers/parse_json.py +++ b/.github/helpers/parse_json.py @@ -1,13 +1,38 @@ +import argparse import json -import json_repair #will have to pip install import pdb +import sys + +import json_repair #will have to pip install + +def parse_json_file(json_filename): + """reads through json file produced by a11ywatch API and displays the results. + + Parameters + ---------- + json_filename : str + name of the json file to process + + Returns + ------- + rv : int + if a11ywatch didn't find any issues, rv will be integer value '0'. However, if a11ywatch did find + issues, rv will be integer value '99'. + """ + # Fix any json formatting errors + json_object = json_repair.from_file(json_filename) + + # pretty print json file contents + json_formatted_str = json.dumps(json_object, indent=2) + print(json_formatted_str) + rv = 0 + return rv -json_filename = 'barf1.json' -# Fix any json formatting errors -json_object = json_repair.from_file(json_filename) +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument( 'json_filename', type=str, help='Name of the json file to be processed') + args = parser.parse_args() -# pretty print json filecld -json_formatted_str = json.dumps(json_object, indent=2) -print(json_formatted_str) -pdb.set_trace() \ No newline at end of file + rv = parse_json_file(args.json_filename) + sys.exit(rv) \ No newline at end of file From c97f65fee954d8144cb2d451328d2e2729e0368f Mon Sep 17 00:00:00 2001 From: dulude Date: Thu, 5 Dec 2024 11:43:49 -0500 Subject: [PATCH 04/10] Finished development of parse_json.py --- .github/helpers/parse_json.py | 75 ++++++++++++++++++- .../workflows/html_accessibility_check.yml | 2 +- 2 files changed, 72 insertions(+), 5 deletions(-) diff --git a/.github/helpers/parse_json.py b/.github/helpers/parse_json.py index 922bdcb..a57d634 100644 --- a/.github/helpers/parse_json.py +++ b/.github/helpers/parse_json.py @@ -5,13 +5,22 @@ import json_repair #will have to pip install -def parse_json_file(json_filename): +def parse_json_file(json_filename, total_combined_limit=0, total_error_limit=0, total_warning_limit=0): """reads through json file produced by a11ywatch API and displays the results. Parameters ---------- json_filename : str name of the json file to process + total_combined_limit : int + The maximum total allowed number of HTML accessibility errors and warnings. To skip this testing + requirement, enter the value "-1". If not explicitly specified, the default value is "0". + total_error_limit : int + The maximum total allowed number of HTML accessibility errors. To skip this testing requirement, + enter the value "-1". If not explicitly specified, the default value is "0". + total_error_limit : int + The maximum total allowed number of HTML accessibility warnings. To skip this testing requirement, + enter the value "-1". If not explicitly specified, the default value is "0". Returns ------- @@ -25,14 +34,72 @@ def parse_json_file(json_filename): # pretty print json file contents json_formatted_str = json.dumps(json_object, indent=2) print(json_formatted_str) - rv = 0 - return rv + # parse out the scan results to determine success for failure + if json_object[0]['success'] == True: + scan_results_dict = {} + totals_dict = {} + for total_item in ['totalIssues', 'errorCount', 'warningCount', 'noticeCount']: + totals_dict[total_item] = 0 + for item in json_object: + item_dict = {} + + for issuesInfoItem in ['totalIssues', 'errorCount', 'warningCount', 'noticeCount']: + item_dict[issuesInfoItem] = item['data']['issuesInfo'][issuesInfoItem] + totals_dict[issuesInfoItem] += item['data']['issuesInfo'][issuesInfoItem] + scan_results_dict[item['data']['url']] = item_dict + # for item in scan_results_dict.keys(): + # print(scan_results_dict[item]) + # print(totals_dict) + + # Determine test status + print() + print("****************") + print("* SCAN RESULTS *") + print("****************") + + print(f"Total number of HTML accessibility errors: {totals_dict['errorCount']}") + print(f"Total number of HTML accessibility warnings: {totals_dict['warningCount']}") + print(f"Total number of warnings and errors: {totals_dict['totalIssues']}\n") + rv = 0 + if total_combined_limit != -1 and totals_dict['totalIssues'] > total_combined_limit: + print(f"The total number of HTML accessibility errors and warnings ({totals_dict['totalIssues']}) exceeded the maximum allowed threshold ({total_combined_limit}).") + rv = 99 + elif total_error_limit != -1 and totals_dict['errorCount'] > total_error_limit: + print(f"The total number of HTML accessibility errors ({totals_dict['errorCount']}) exceeded the maximum allowed threshold ({total_error_limit}).") + rv = 99 + elif total_warning_limit != -1 and totals_dict['warningCount'] > total_warning_limit: + print(f"The total number of HTML accessibility warnings ({totals_dict['errorCount']}) exceeded the maximum allowed threshold ({total_warning_limit}).") + rv = 99 + else: + print("SUCCESS! No HTML accessibility errors and warnings were found.") + else: + print("ERROR: A11ywatch scan failure.") + rv = 98 + return rv if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument( 'json_filename', type=str, help='Name of the json file to be processed') + parser.add_argument('-c', '--total_combined_limit', required=False, + default=0, type=int, + help='The maximum total allowed number of HTML accessibility errors and errors. To skip this ' + 'testing requirement, enter the value "-1". If not explicitly specified, the ' + 'default value is "0".') + parser.add_argument('-e', '--total_error_limit', required=False, + default=0, type=int, + help='The maximum total allowed number of HTML accessibility errors. To skip this ' + 'testing requirement, enter the value "-1". If not explicitly specified, the ' + 'default value is "0".') + parser.add_argument('-w', '--total_warning_limit', required=False, + default=0, type=int, + help='The maximum total allowed number of HTML accessibility warnings. To skip this ' + 'testing requirement, enter the value "-1". If not explicitly specified, the ' + 'default value is "0".') args = parser.parse_args() - rv = parse_json_file(args.json_filename) + rv = parse_json_file(args.json_filename, + total_combined_limit = args.total_combined_limit, + total_error_limit=args.total_error_limit, + total_warning_limit=args.total_warning_limit) sys.exit(rv) \ No newline at end of file diff --git a/.github/workflows/html_accessibility_check.yml b/.github/workflows/html_accessibility_check.yml index 75ce639..83da6be 100644 --- a/.github/workflows/html_accessibility_check.yml +++ b/.github/workflows/html_accessibility_check.yml @@ -27,5 +27,5 @@ jobs: steps: - name: Run PEP8 style check run: | - curl --location --request POST 'https://api.a11ywatch.com/api/crawl' --header 'Authorization: ${{ secrets.A11YWATCH_TOKEN }}' --header 'Content-Type: application/json' -d '{ "url": "${{ inputs.target_url }}" }' + curl --location --request POST 'https://api.a11ywatch.com/api/crawl' --header 'Authorization: ${{ secrets.A11YWATCH_TOKEN }}' --header 'Content-Type: application/json' -d '{ "url": "${{ inputs.target_url }}" }' > blarg.json From 2d7379f746f3401c01e0ca916dcc3cb030a592bc Mon Sep 17 00:00:00 2001 From: dulude Date: Thu, 5 Dec 2024 11:45:57 -0500 Subject: [PATCH 05/10] Finished development of parse_json.py --- .github/workflows/html_accessibility_check.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/html_accessibility_check.yml b/.github/workflows/html_accessibility_check.yml index 83da6be..9a51f68 100644 --- a/.github/workflows/html_accessibility_check.yml +++ b/.github/workflows/html_accessibility_check.yml @@ -28,4 +28,5 @@ jobs: - name: Run PEP8 style check run: | curl --location --request POST 'https://api.a11ywatch.com/api/crawl' --header 'Authorization: ${{ secrets.A11YWATCH_TOKEN }}' --header 'Content-Type: application/json' -d '{ "url": "${{ inputs.target_url }}" }' > blarg.json + cat blarg.json From 6a0dd8dade0973abc0c9ad476a2ee6da67563515 Mon Sep 17 00:00:00 2001 From: dulude Date: Thu, 5 Dec 2024 12:00:15 -0500 Subject: [PATCH 06/10] Renamed parse_json.py -> parse_a11ywatch_json_file.py --- .github/helpers/{parse_json.py => parse_a11ywatch_json_file.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/helpers/{parse_json.py => parse_a11ywatch_json_file.py} (100%) diff --git a/.github/helpers/parse_json.py b/.github/helpers/parse_a11ywatch_json_file.py similarity index 100% rename from .github/helpers/parse_json.py rename to .github/helpers/parse_a11ywatch_json_file.py From 2eebd8bfc575143526a81b99ce48ef3a1c44346a Mon Sep 17 00:00:00 2001 From: dulude Date: Thu, 5 Dec 2024 12:09:08 -0500 Subject: [PATCH 07/10] Updated html_accessibility_check.yml to work with parse_a11ywatch_results.py --- .../workflows/html_accessibility_check.yml | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/.github/workflows/html_accessibility_check.yml b/.github/workflows/html_accessibility_check.yml index 9a51f68..102d2fd 100644 --- a/.github/workflows/html_accessibility_check.yml +++ b/.github/workflows/html_accessibility_check.yml @@ -25,8 +25,26 @@ jobs: a11yWatchRun: runs-on: ubuntu-latest steps: - - name: Run PEP8 style check + - uses: actions/checkout@v4 + - name: Set up Python 3.8.12 + uses: actions/setup-python@v5 ## needed for caching + with: + python-version: 3.8.12 + cache: 'pip' + - name: Add conda to system path run: | - curl --location --request POST 'https://api.a11ywatch.com/api/crawl' --header 'Authorization: ${{ secrets.A11YWATCH_TOKEN }}' --header 'Content-Type: application/json' -d '{ "url": "${{ inputs.target_url }}" }' > blarg.json - cat blarg.json + # $CONDA is an environment variable pointing to the root of the miniconda directory + echo $CONDA/bin >> $GITHUB_PATH + - name: Install dependencies + run: | + pip install json_repair + - name: Check-out notebook-ci-actions repository + uses: actions/checkout@v4 + with: + repository: spacetelescope/notebook-ci-actions + path: temp_jsonparser + - name: Web Accessibility Evaluation of ${{ inputs.target_url }} + run: | + curl --location --request POST 'https://api.a11ywatch.com/api/crawl' --header 'Authorization: ${{ secrets.A11YWATCH_TOKEN }}' --header 'Content-Type: application/json' -d '{ "url": "${{ inputs.target_url }}" }' > scan_results.json + python temp_jsonparser/.github/helpers/parse_a11ywatch_results.py scan_results.json From bcec545f6d712c3f43f564437bf003eadf561426 Mon Sep 17 00:00:00 2001 From: dulude Date: Thu, 5 Dec 2024 12:14:12 -0500 Subject: [PATCH 08/10] Updated html_accessibility_check.yml to work with parse_a11ywatch_results.py --- .github/workflows/html_accessibility_check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/html_accessibility_check.yml b/.github/workflows/html_accessibility_check.yml index 102d2fd..e02c7d9 100644 --- a/.github/workflows/html_accessibility_check.yml +++ b/.github/workflows/html_accessibility_check.yml @@ -46,5 +46,5 @@ jobs: - name: Web Accessibility Evaluation of ${{ inputs.target_url }} run: | curl --location --request POST 'https://api.a11ywatch.com/api/crawl' --header 'Authorization: ${{ secrets.A11YWATCH_TOKEN }}' --header 'Content-Type: application/json' -d '{ "url": "${{ inputs.target_url }}" }' > scan_results.json - python temp_jsonparser/.github/helpers/parse_a11ywatch_results.py scan_results.json + python .github/helpers/parse_a11ywatch_results.py scan_results.json From 3ee716dbb781f740dbb7d4f7f52ae502938a2e7b Mon Sep 17 00:00:00 2001 From: dulude Date: Thu, 5 Dec 2024 12:20:53 -0500 Subject: [PATCH 09/10] Updated html_accessibility_check.yml to work with parse_a11ywatch_results.py --- .github/workflows/html_accessibility_check.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/html_accessibility_check.yml b/.github/workflows/html_accessibility_check.yml index e02c7d9..9c02017 100644 --- a/.github/workflows/html_accessibility_check.yml +++ b/.github/workflows/html_accessibility_check.yml @@ -42,9 +42,10 @@ jobs: uses: actions/checkout@v4 with: repository: spacetelescope/notebook-ci-actions + ref: refactor_html_accessibility_check path: temp_jsonparser - name: Web Accessibility Evaluation of ${{ inputs.target_url }} run: | curl --location --request POST 'https://api.a11ywatch.com/api/crawl' --header 'Authorization: ${{ secrets.A11YWATCH_TOKEN }}' --header 'Content-Type: application/json' -d '{ "url": "${{ inputs.target_url }}" }' > scan_results.json - python .github/helpers/parse_a11ywatch_results.py scan_results.json + python temp_jsonparser/.github/helpers/parse_a11ywatch_results.py scan_results.json From f3c304ff4171acbffdd0c5aaac60908a911e66cb Mon Sep 17 00:00:00 2001 From: dulude Date: Thu, 5 Dec 2024 12:24:23 -0500 Subject: [PATCH 10/10] Updated html_accessibility_check.yml to work with parse_a11ywatch_results.py --- .github/helpers/parse_a11ywatch_json_file.py | 1 - .github/workflows/html_accessibility_check.yml | 2 -- 2 files changed, 3 deletions(-) diff --git a/.github/helpers/parse_a11ywatch_json_file.py b/.github/helpers/parse_a11ywatch_json_file.py index a57d634..1cd8bf7 100644 --- a/.github/helpers/parse_a11ywatch_json_file.py +++ b/.github/helpers/parse_a11ywatch_json_file.py @@ -1,6 +1,5 @@ import argparse import json -import pdb import sys import json_repair #will have to pip install diff --git a/.github/workflows/html_accessibility_check.yml b/.github/workflows/html_accessibility_check.yml index 9c02017..43d42ab 100644 --- a/.github/workflows/html_accessibility_check.yml +++ b/.github/workflows/html_accessibility_check.yml @@ -19,7 +19,6 @@ on: description: "URL to scan" required: false type: 'string' - jobs: a11yWatchRun: @@ -42,7 +41,6 @@ jobs: uses: actions/checkout@v4 with: repository: spacetelescope/notebook-ci-actions - ref: refactor_html_accessibility_check path: temp_jsonparser - name: Web Accessibility Evaluation of ${{ inputs.target_url }} run: |