-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.sh
executable file
·92 lines (76 loc) · 3.21 KB
/
main.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env bash
set -e
throw() {
echo "Error: $*"
exit 1
}
[ -z "$API_KEY" ] && throw "API_KEY required"
[ -z "$SERVER_URL" ] && throw "SERVER_URL required"
[ -z "$COMMIT_SHA" ] && throw "COMMIT_SHA required"
[ -z "$ENABLE_A11Y_THRESHOLD" ] && throw "ENABLE_A11Y_THRESHOLD required"
RETRY_COUNT=${RETRY_COUNT:-10}
echo "Attempting to get status for commit $COMMIT_SHA from $SERVER_URL with $RETRY_COUNT retries"
Response=$(
curl \
--fail-with-body \
--silent \
--show-error \
--retry "$RETRY_COUNT" \
--retry-all-errors \
--header "X-API-Key: $API_KEY" \
--header "Accept: application/json" \
--url "$SERVER_URL/api-pub/v1/axe-watcher/gh/$COMMIT_SHA"
)
LastRunCreatedAt=$(echo "$Response" | jq -r .last_run_created_at)
LastRunViolationCount=$(echo "$Response" | jq -r .last_run_violation_count)
LastRunPageStateCount=$(echo "$Response" | jq -r .last_run_page_state_count)
LastRunNewViolationCount=$(echo "$Response" | jq -r .last_run_new_violation_count)
LastRunResolvedViolationCount=$(echo "$Response" | jq -r .last_run_resolved_violation_count)
IssuesOverA11yThreshold=$(echo "$Response" | jq .issues_over_a11y_threshold)
AxeURL=$(echo "$Response" | jq -r .axe_url)
ProjectName=$(echo "$Response" | jq -r .project_name)
DifferenceInPageStateCount=$(echo "$Response" | jq -r .difference_in_page_states)
# Only set outs when running in GitHub Actions.
if [ -n "${GITHUB_OUTPUT+x}" ]; then
echo "project=$ProjectName" >>"$GITHUB_OUTPUT"
echo "axe_url=$SERVER_URL$AxeURL" >>"$GITHUB_OUTPUT"
echo "created_at=$LastRunCreatedAt" >>"$GITHUB_OUTPUT"
echo "issue_count=$LastRunViolationCount" >>"$GITHUB_OUTPUT"
echo "new_issues=$LastRunNewViolationCount" >> "$GITHUB_OUTPUT"
echo "resolved_issues=$LastRunResolvedViolationCount" >> "$GITHUB_OUTPUT"
echo "issues_over_a11y_threshold=$IssuesOverA11yThreshold" >>"$GITHUB_OUTPUT"
echo "difference_in_page_states=$DifferenceInPageStateCount" >> "$GITHUB_OUTPUT"
echo "page_states=$LastRunPageStateCount" >> "$GITHUB_OUTPUT"
fi
echo "Project: $ProjectName"
echo "axe Developer Hub accessibility results:"
echo "$LastRunViolationCount violations found"
echo "$LastRunPageStateCount page states found"
echo "$LastRunNewViolationCount new issues found"
echo "$LastRunResolvedViolationCount issues resolved"
existing_issues_count=$(( $LastRunViolationCount - $LastRunNewViolationCount ))
existing_issues_count=$(( existing_issues_count < 0 ? 0 : existing_issues_count ))
echo "$existing_issues_count previous issues remain"
if [ "$DifferenceInPageStateCount" -gt 0 ]; then
echo "$DifferenceInPageStateCount more page states"
elif [ "$DifferenceInPageStateCount" -lt 0 ]; then
AbsoluteDifference=$(( -DifferenceInPageStateCount ))
echo "$AbsoluteDifference fewer page states"
else
echo "No change in page state count"
fi
if [ "$ENABLE_A11Y_THRESHOLD" = "true" ]; then
echo "$IssuesOverA11yThreshold accessibility violations over your a11y threshold."
fi
echo "See full report at $SERVER_URL$AxeURL"
if [ "$ENABLE_A11Y_THRESHOLD" = "true" ]; then
if [ "$IssuesOverA11yThreshold" -gt 0 ]; then
exit 1
else
# If there are no issues over the threshold, we can exit successfully.
exit 0
fi
fi
if [ "$LastRunViolationCount" -gt 0 ]; then
exit 1
fi