-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
89 lines (71 loc) · 2.35 KB
/
entrypoint.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
#!/bin/bash
set -eo pipefail
if [ "${INPUT_DEBUG}" == "true" ]; then
set -x
date
fi
if [ -z "${INPUT_SHA:-$GITHUB_SHA}" ]; then
echo "Neither INPUT_SHA or GITHUB_SHA present" 2>&1
exit 1
fi
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
BT_TEMP="${SCRIPT_DIR}/tmp"
mkdir -p ${BT_TEMP}
export BT_DIR="$(mktemp -d ${BT_TEMP}/bt-$$-XXXXXXX)"
export BT_DISABLE_CPUSAMPLE=1
export BT_SMALLSTATS=1
. ./bt.sh
. ./lib.sh
rm -f ${BT_DIR}/bt*
# Account for replication delay
sleep $INPUT_DELAY
bt_init "${INPUT_TRACE_START:-$first}"
bt_start "bt.sh"
curl -s --retry 5 --retry-all-errors --retry-max-time 30 \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H "Content-Type: application/json" \
-H "Accept: application/vnd.github.antiope-preview+json" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/commits/${INPUT_SHA:-$GITHUB_SHA}/check-runs" | \
tee ${BT_TEMP}/checkruns.json | \
jq -r '.check_runs[] | [.started_at, .id, .name, .conclusion, .completed_at] | @tsv' | \
sort -n > ${BT_TEMP}/checkruns.tsv
first=$(head -n 1 ${BT_TEMP}/checkruns.tsv | cut -f 1)
last=$(cat ${BT_TEMP}/checkruns.json | \
jq -r '.check_runs[] | [.completed_at] | @tsv' | \
grep -E '[0-9]' | \
sort -rn | \
tee ${BT_TEMP}/completed_at.tsv | \
head -n 1)
if [ "${INPUT_DEBUG}" == "true" ]; then
set +e
find ${BT_TEMP} -name '*.tsv' -o -name '*.json' | xargs -n 1 -t cat
date
set -e
fi
# Record traces for each completed check run
while IFS="" read -r checkrun || [ -n "$checkrun" ]
do
started_at=$(echo "$checkrun" | cut -f 1)
id=$(echo "$checkrun" | cut -f 2)
name=$(echo "$checkrun" | cut -f 3)
conclusion=$(echo "$checkrun" | cut -f 4)
completed_at=$(echo "$checkrun" | cut -f 5)
if [ "$conclusion" == "skipped" ]; then
continue
fi
bt_start "$(echo -e "$name\\thttps://github.com/${GITHUB_REPOSITORY}/runs/$id")" "$started_at"
if [ -n "$completed_at" ]; then
bt_end "$(echo -e "$name\\thttps://github.com/${GITHUB_REPOSITORY}/runs/$id")" "$completed_at"
fi
done < ${BT_TEMP}/checkruns.tsv
if [ "${INPUT_DEBUG}" == "true" ]; then
date
fi
bt_end "bt.sh"
# display the results
if [ -n "$INPUT_SUMMARY" ]; then
output="$(bt_cleanup "${last}")"
echo -e "\`\`\`\n${output}\n\`\`\`" >> "$GITHUB_STEP_SUMMARY"
else
bt_cleanup "${last}"
fi