forked from getsentry/sentry-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash_hook-release.trycmd
75 lines (62 loc) · 2.2 KB
/
bash_hook-release.trycmd
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
```
$ sentry-cli bash-hook --release "0.1.0"
? success
set -e
_SENTRY_TRACEBACK_FILE="[..].traceback"
_SENTRY_LOG_FILE="[..].out"
if [ "${SENTRY_CLI_NO_EXIT_TRAP-0}" != 1 ]; then
trap _sentry_exit_trap EXIT
fi
trap _sentry_err_trap ERR
_sentry_shown_traceback=0
_sentry_exit_trap() {
local _exit_code="$?"
local _command="${BASH_COMMAND:-unknown}"
if [[ $_exit_code != 0 && "${_sentry_shown_traceback}" != 1 ]]; then
_sentry_err_trap "$_command" "$_exit_code"
fi
rm -f "$_SENTRY_TRACEBACK_FILE" "$_SENTRY_LOG_FILE"
exit $_exit_code
}
_sentry_err_trap() {
local _exit_code="$?"
local _command="${BASH_COMMAND:-unknown}"
if [ $# -ge 1 ] && [ "x$1" != x ]; then
_command="$1"
fi
if [ $# -ge 2 ] && [ "x$2" != x ]; then
_exit_code="$2"
fi
_sentry_traceback 1
echo "@command:${_command}" >> "$_SENTRY_TRACEBACK_FILE"
echo "@exit_code:${_exit_code}" >> "$_SENTRY_TRACEBACK_FILE"
: >> "$_SENTRY_LOG_FILE"
export SENTRY_LAST_EVENT=$([CWD]/target/debug/sentry-cli[EXE] bash-hook --send-event --traceback "$_SENTRY_TRACEBACK_FILE" --release "0.1.0" --log "$_SENTRY_LOG_FILE" )
rm -f "$_SENTRY_TRACEBACK_FILE" "$_SENTRY_LOG_FILE"
}
_sentry_traceback() {
_sentry_shown_traceback=1
local -i start=$(( ${1:-0} + 1 ))
local -i end=${#BASH_SOURCE[@]}
local -i i=0
local -i j=0
: > "$_SENTRY_TRACEBACK_FILE"
for ((i=${start}; i < ${end}; i++)); do
j=$(( $i - 1 ))
local function="${FUNCNAME[$i]}"
local file="${BASH_SOURCE[$i]}"
local line="${BASH_LINENO[$j]}"
echo "${function}:${file}:${line}" >> "$_SENTRY_TRACEBACK_FILE"
done
}
: > "$_SENTRY_LOG_FILE"
if command -v perl >/dev/null; then
exec /
1> >(tee >(perl '-MPOSIX' -ne '$|++; print strftime("%Y-%m-%d %H:%M:%S %z: ", localtime()), "stdout: ", $_;' >> "$_SENTRY_LOG_FILE")) /
2> >(tee >(perl '-MPOSIX' -ne '$|++; print strftime("%Y-%m-%d %H:%M:%S %z: ", localtime()), "stderr: ", $_;' >> "$_SENTRY_LOG_FILE") >&2)
else
exec /
1> >(tee >(awk '{ system(""); print strftime("%Y-%m-%d %H:%M:%S %z:"), "stdout:", $0; system(""); }' >> "$_SENTRY_LOG_FILE")) /
2> >(tee >(awk '{ system(""); print strftime("%Y-%m-%d %H:%M:%S %z:"), "stderr:", $0; system(""); }' >> "$_SENTRY_LOG_FILE") >&2)
fi
```