-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaxe-linter-changed.sh
74 lines (61 loc) · 2.33 KB
/
axe-linter-changed.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
# StatusCode 0 - No Accessibility Defects
# StatusCode 1 - axe DevTools Linter Detected Accessibility Defects
# StatusCode 2 - Execution problem, or axe DevTools Linter unavailable.
echo "axe DevTools Linter Starting $(date)"
echo "This job runs axe Linter scan on all the files staged for the merge process. It will only run when a merge branch process is started"
StatusCode=0
VerboseOutput="false"
OutFile="axe-linter-report.json"
TempStatusCode=0
# copy scripts and linter-connector cli to the root of the project
cp github-action-linter/* .
chmod +x axe-linter-connector-linux
if [[ -z "${AXE_LINTER_API_KEY}" ]]; then
echo "AXE_LINTER_API_KEY must be set"
exit 2
fi
# Get list of changed files
ChangedFiles=($(git diff-tree --no-commit-id --name-only -r $CI_COMMIT_SHA))
# File extensions to check
FileExtensions=("html" "js" "jsx" "tsx" "vue" "htm" "md" "markdown")
for file in "${ChangedFiles[@]}"; do
# Check if the file has one of the specified extensions
for ext in "${FileExtensions[@]}"; do
if [[ "$file" == *.$ext ]]; then
echo "Scanning $file"
./axe-linter-connector-linux \
-s "$file" \
-d . \
--url="$AXE_LINTER_SERVER_URL" \
--api-key="$AXE_LINTER_API_KEY"
if [ ! -f "$OutFile" ]; then
echo "$OutFile Does Not Exist"
exit 2
else
if grep -q "BUG" "$OutFile"; then
if [ "$VerboseOutput" == "true" ]; then
cat "$OutFile"
fi
echo "----------------------------------------------------------------"
echo "axe DevTools Linter Accessibility Defect Detected: $file"
echo "----------------------------------------------------------------"
grep $OutFile
TempStatusCode=1
else
echo "No axe DevTools Linter Bugs Detected"
fi
fi
if [ "$TempStatusCode" != 0 ]; then
StatusCode=1
fi
# Remove previous results
rm -f "$OutFile"
break
fi
done
done
if [ "$StatusCode" != "0" ]; then
echo "Merge Request Failed due to Accessibility Issues"
fi
exit "$StatusCode"