-
Notifications
You must be signed in to change notification settings - Fork 198
Expand file tree
/
Copy pathtest-results.sh
More file actions
executable file
·54 lines (52 loc) · 2.57 KB
/
Copy pathtest-results.sh
File metadata and controls
executable file
·54 lines (52 loc) · 2.57 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
#!/bin/bash
set -eo pipefail # For jq to propagate yq failures.
# This script processes the XML tests results and outputs a NDJSON stream with one document per test execution.
# Hence, each document corresponds to a testcase entry in the XML. It contains the following fields:
#
# - 'timestamp': As the testsuite (parent of the entry) timestamp field.
# - 'suite_name': As the entry class name.
# - 'test': As the entry name.
# - 'result': success/failure/skipped from the optional child node of the entry. No child node means success.
# - 'reason': As the entry child (skipped or failure) contents. For example, in the source, <failure>SOURCE FOR REASON</failure>.
# - 'duration_seconds': As the time field of the entry.
# - 'workflow_run_id': As the content of the environment variable 'WORKFLOW_RUN_ID'
# - 'workflow_run_link': As the content of the environment variable 'WORKFLOW_RUN_LINK'
# - 'workflow_head_branch': As the content of the environment variable 'WORKFLOW_HEAD_BRANCH'
# - 'workflow_retry_number': As the content of the environment variable 'WORKFLOW_RUN_NUMBER'
# - 'commit_sha': As the content of the environment variable 'COMMIT_SHA'
#
# INPUT:
# - The XML file(s) to process. For example, the test results generated by JUnit in the 'target/surefire-reports' directory.
# - The following environment variables to enrich with the workflow information:
# - WORKFLOW_RUN_ID
# - WORKFLOW_RUN_LINK
# - WORKFLOW_HEAD_BRANCH
# - WORKFLOW_RUN_NUMBER
# - COMMIT_SHA
#
# OUTPUT: NDJSON stream through stdout.
#
yq -p=xml -o=json \
'
((.testsuites.testsuite | select(kind == "seq") | .[]), (.testsuites.testsuite | select(kind == "map"))) |
."+@timestamp" as $ts |
select(has("testcase")) |
((.testcase | select(kind == "seq") | .[]), (.testcase | select(kind == "map"))) |
{
"timestamp": $ts,
"suite_name": ."+@classname",
"test": ."+@name",
"result": ((keys | map(select(. == "failure" or . == "skipped")) | .[0]) // "success"),
"reason": ((.failure."+content" // .skipped."+@message") // null),
"duration_seconds": (."+@time" | select(. != "") | tonumber // null),
"workflow_run_id": (strenv(WORKFLOW_RUN_ID) | tonumber),
"workflow_run_link": strenv(WORKFLOW_RUN_LINK),
"workflow_head_branch": strenv(WORKFLOW_HEAD_BRANCH),
"workflow_retry_number": (strenv(WORKFLOW_RUN_NUMBER) | tonumber),
"commit_sha": strenv(COMMIT_SHA),
"compatibility_matrix_id": (strenv(COMBINATION_ID) | select(. != "") // null)
} |
select(.suite_name != null)
' \
"$@" \
| jq -c . # jq for compacting the output to NDJSON.