-
Notifications
You must be signed in to change notification settings - Fork 595
Expand file tree
/
Copy pathdenoise
More file actions
executable file
·97 lines (81 loc) · 2.19 KB
/
denoise
File metadata and controls
executable file
·97 lines (81 loc) · 2.19 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
#!/usr/bin/env bash
NO_CD=1 source ${root:-$(git rev-parse --show-toplevel)}/ci3/source
source $ci3/source_redis
# Ensure a command is passed
if [ "$#" != 1 ]; then
echo "Usage: $0 <command>"
exit 1
fi
cmd=$1
if [[ "${DENOISE:-0}" -eq 0 ]] || [[ "${BUILD_SYSTEM_DEBUG:-0}" -eq 1 ]]; then
set -e
bash -c "$cmd"
exit 0
fi
dots_per_line=${LINE_WIDTH:-64}
dot_count=0
status="in-progress"
time="in-progress"
# We don't want to lose color just because we're wrapping.
export FORCE_COLOR=${FORCE_COLOR:-1}
# If stdout is connected to a terminal, print singular dots for each line.
[ -t 1 ] && realtime=1 || realtime=0
key=$(uuid)
url=http://ci.aztec-labs.com/$key
outfile=/tmp/$key
trap 'rm -f $outfile' EXIT
touch $outfile
function publish_log {
if [ "$CI_REDIS_AVAILABLE" -eq 0 ]; then
return
fi
{
echo "Parent Log: ${PARENT_LOG_URL:-none}"
echo "Command: $cmd"
echo "Date: $(date)"
echo "Status: $status"
echo "Took: ${time}"
echo
cat $outfile
} | redis_setexz $key $CI_REDIS_EXPIRE
}
function live_publish_log {
while [ -f $outfile ]; do
if [ $(( $(date +%s) - $(stat -c %Y "$outfile") )) -le 5 ]; then
publish_log
fi
sleep 5
done
}
if [ "$CI_REDIS_AVAILABLE" -eq 1 ]; then
live_publish_log &
publish_pid=$!
log_info="(${yellow}${url}${reset})"
fi
# Execute the command and process the output, allow for errors.
set +e
echo -e "Executing: $cmd ${log_info:-}"
echo -n " 0 "
PARENT_LOG_URL=$url bash -c "$cmd" 2>&1 | redact | while IFS= read -r line; do
((dot_count++))
[ $realtime -eq 1 ] && printf "."
if [[ "$dots_per_line" -gt 0 && $((dot_count % dots_per_line)) -eq 0 ]]; then
[ $realtime -eq 0 ] && printf '%.s.' $(seq 1 "$dots_per_line")
printf "\n%4s " "$dot_count"
fi
printf "%s\n" "$line" >> $outfile
done;
# Get the exit status of the command
status=${PIPESTATUS[0]}
time="${SECONDS}s"
[ -n "$publish_pid" ] && kill $publish_pid &>/dev/null || true
publish_log
# Handle non-zero exit status
if [ "$status" -ne 0 ]; then
echo -e "\nCommand exited with status $status. Dumping output:"
cat $outfile
echo -e ". ${red}failed${reset} ($time) ${log_info:-}"
else
echo -e ". ${green}done${reset} ($time)"
fi
exit $status