-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-tests.sh
More file actions
executable file
·157 lines (127 loc) · 5.94 KB
/
Copy pathrun-tests.sh
File metadata and controls
executable file
·157 lines (127 loc) · 5.94 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/env bash
set -euo pipefail
# ---------------------------------------------------------------------------
# run-tests.sh – Call the SmoothQA Pipeline API and surface results.
#
# Expected env vars (set by action.yml):
# SMOOTHQA_API_KEY Pipeline API key
# SMOOTHQA_BASE_URL Instance base URL
# SMOOTHQA_SUITE_IDS Comma-separated suite IDs
# SMOOTHQA_TIMEOUT_MS Timeout in ms
# SMOOTHQA_INCLUDE_DETAILS "true" | "false"
# SMOOTHQA_FAIL_ON_FAILURE "true" | "false"
# GITHUB_OUTPUT Path to GitHub Actions output file
# ---------------------------------------------------------------------------
# --- Validate required inputs ------------------------------------------------
if [[ -z "${SMOOTHQA_API_KEY:-}" ]]; then
echo "::error::api_key is required"
exit 1
fi
if [[ -z "${SMOOTHQA_BASE_URL:-}" ]]; then
echo "::error::base_url is required"
exit 1
fi
if [[ -z "${SMOOTHQA_SUITE_IDS:-}" ]]; then
echo "::error::suite_ids is required"
exit 1
fi
# --- Build request body ------------------------------------------------------
BASE_URL="${SMOOTHQA_BASE_URL%/}"
TIMEOUT_MS="${SMOOTHQA_TIMEOUT_MS:-600000}"
INCLUDE_DETAILS="${SMOOTHQA_INCLUDE_DETAILS:-false}"
# Convert comma-separated IDs to a JSON array
SUITE_IDS_JSON=$(echo "$SMOOTHQA_SUITE_IDS" | tr ',' '\n' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | jq -R . | jq -s .)
BODY=$(jq -n \
--argjson suiteIds "$SUITE_IDS_JSON" \
--argjson timeoutMs "$TIMEOUT_MS" \
--argjson includeDetails "$INCLUDE_DETAILS" \
'{suiteIds: $suiteIds, timeoutMs: $timeoutMs, includeDetails: $includeDetails}')
echo "::group::Request"
echo "URL: ${BASE_URL}/testservice/pipeline/runs"
echo "Suites: ${SMOOTHQA_SUITE_IDS}"
echo "Timeout: ${TIMEOUT_MS}ms"
echo "Include details: ${INCLUDE_DETAILS}"
echo "::endgroup::"
# --- Call the API ------------------------------------------------------------
HTTP_RESPONSE=$(mktemp)
HTTP_CODE=$(curl -s -w "%{http_code}" -o "$HTTP_RESPONSE" \
-X POST "${BASE_URL}/testservice/pipeline/runs" \
-H "Content-Type: application/json" \
-H "X-API-Key: ${SMOOTHQA_API_KEY}" \
--max-time $(( (TIMEOUT_MS / 1000) + 30 )) \
-d "$BODY") || {
echo "::error::Failed to connect to SmoothQA at ${BASE_URL}"
rm -f "$HTTP_RESPONSE"
exit 1
}
RESULT=$(cat "$HTTP_RESPONSE")
rm -f "$HTTP_RESPONSE"
# --- Handle HTTP errors ------------------------------------------------------
if [[ "$HTTP_CODE" -lt 200 || "$HTTP_CODE" -ge 300 ]]; then
echo "::error::SmoothQA API returned HTTP ${HTTP_CODE}"
echo "$RESULT" | jq . 2>/dev/null || echo "$RESULT"
exit 1
fi
# --- Parse response ----------------------------------------------------------
OVERALL_STATUS=$(echo "$RESULT" | jq -r '.summary.overallStatus // "UNKNOWN"')
TOTAL_SUITES=$(echo "$RESULT" | jq -r '.summary.totalSuites // 0')
PASSED_SUITES=$(echo "$RESULT" | jq -r '.summary.passedSuites // 0')
FAILED_SUITES=$(echo "$RESULT" | jq -r '.summary.failedSuites // 0')
ERROR_SUITES=$(echo "$RESULT" | jq -r '.summary.errorSuites // 0')
TOTAL_DURATION=$(echo "$RESULT" | jq -r '.summary.totalDurationMs // 0')
# --- Print summary -----------------------------------------------------------
echo ""
echo "╔══════════════════════════════════════════════════╗"
echo "║ SmoothQA Test Results ║"
echo "╠══════════════════════════════════════════════════╣"
if [[ "$OVERALL_STATUS" == "PASSED" ]]; then
echo "║ ✅ Overall: PASSED ║"
else
echo "║ ❌ Overall: FAILED ║"
fi
echo "╠══════════════════════════════════════════════════╣"
printf "║ Total: %-39s ║\n" "$TOTAL_SUITES suites"
printf "║ Passed: %-39s ║\n" "$PASSED_SUITES"
printf "║ Failed: %-39s ║\n" "$FAILED_SUITES"
printf "║ Errors: %-39s ║\n" "$ERROR_SUITES"
printf "║ Duration: %-37s ║\n" "${TOTAL_DURATION}ms"
echo "╚══════════════════════════════════════════════════╝"
echo ""
# Print per-suite breakdown
echo "::group::Suite Results"
echo "$RESULT" | jq -r '.outcomes[] | "[\(.status)] \(.suiteName) (\(.suiteId)) - \(.durationMs // "?")ms"'
echo "::endgroup::"
# Print failures with details
FAILURE_COUNT=$(echo "$RESULT" | jq '[.outcomes[] | select(.status != "PASSED")] | length')
if [[ "$FAILURE_COUNT" -gt 0 ]]; then
echo ""
echo "::group::Failed Suites"
echo "$RESULT" | jq -r '.outcomes[] | select(.status != "PASSED") | "Suite: \(.suiteName)\n Status: \(.status)\n Error: \(.error // "N/A")\n"'
if [[ "$INCLUDE_DETAILS" == "true" ]]; then
echo "$RESULT" | jq -r '
.outcomes[]
| select(.status != "PASSED")
| select(.testCaseResults != null)
| "Suite: \(.suiteName)",
(.testCaseResults[] | " [\(.status)] \(.testCaseName)\(.if .error then " — " + .error else "" end)")
' 2>/dev/null || true
fi
echo "::endgroup::"
fi
# --- Set outputs -------------------------------------------------------------
# Escape the JSON for the multiline output format
{
echo "overall_status=${OVERALL_STATUS}"
echo "total_suites=${TOTAL_SUITES}"
echo "passed_suites=${PASSED_SUITES}"
echo "failed_suites=${FAILED_SUITES}"
echo "total_duration_ms=${TOTAL_DURATION}"
RESULT_ESCAPED=$(echo "$RESULT" | jq -c .)
echo "result_json=${RESULT_ESCAPED}"
} >> "$GITHUB_OUTPUT"
# --- Exit code ---------------------------------------------------------------
if [[ "$OVERALL_STATUS" != "PASSED" && "${SMOOTHQA_FAIL_ON_FAILURE:-true}" == "true" ]]; then
echo "::error::SmoothQA tests failed (${FAILED_SUITES} of ${TOTAL_SUITES} suites failed)"
exit 1
fi
echo "All SmoothQA tests passed."