-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjustfile
147 lines (124 loc) · 4.58 KB
/
justfile
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
test test_name="":
#!/usr/bin/env bash
title="test"
proj_dir="$PWD"
echo -ne "\e[22;0t"; printf "\e]0;%s %s\007" "$title" "init"; trap 'echo -ne "\e[23;0t"' EXIT
red="$(tput setaf 1)"
green="$(tput setaf 2)"
yellow="$(tput setaf 3)"
magenta="$(tput setaf 5)"
cyan="$(tput setaf 6)"
reset="$(printf "%b" "\033[0m")"
log () { echo -e "[$(date '+%T.%3N')] $*" >> ~/bashscript.log; }
inotify_action () {
path_rel="$(realpath --relative-to="$proj_dir" "$1")"
[[ "${path_rel: -1}" == "~" ]] && return
[[ "$path_rel" =~ ^(.git/|.idea/|build/|scratch/|archive/|compile/) ]] && return
[[ "$path_rel" =~ (.lock|.log)$ ]] && return
test_call=(go test ./...)
if [[ -n "{{test_name}}" ]]; then
test_call+=(-run {{test_name}})
fi
echo "${test_call[*]}"
clean_stack_cmd="cat"
if command -v perl &> /dev/null; then
clean_stack_cmd="./scripts/clean_stack.pl"
fi
profile_start_tests="$EPOCHREALTIME"
"${test_call[@]}" 2>&1 \
| "$clean_stack_cmd" \
| tee /tmp/bashcompletils-test-results \
| sed s/"FAIL"/"$red&$reset"/i \
| sed s/"PASS\|ok"/"$green&$reset"/i \
| sed s/"WARNING"/"$yellow&$reset"/i \
;
status_test="${PIPESTATUS[0]}"
status_build="${PIPESTATUS[1]}"
profile_end_tests="$EPOCHREALTIME"
profile_tests="$(bc <<< "(($profile_end_tests-$profile_start_tests)*10000)/10")"
if [[ "$status_build" == 2 ]]; then
log "[tests] compile error"
printf "\e]0;%s %s %3dms\007" "$title" "cerr" "$profile_tests"
elif [[ "$status_test" != 0 ]]; then
log "[tests] fail tests ${profile_tests}ms\n$(cat "/tmp/bashcompletils-test-results" | grep '\--- FAIL:')"
printf "\e]0;%s %s %3dms\007" "$title" "fail" "$profile_tests"
else
log "[tests] pass ${profile_tests}ms"
printf "\e]0;%s %s %3dms\007" "$title" "pass" "$profile_tests"
fi
echo -e "${magenta}DONE${reset}: $(date '+%T.%3N')"
}
inotify_action "dummy.go"
inotifywait -q -m -r -e close_write,create,delete "$proj_dir" | \
while read -r dir events filename; do
inotify_action "$dir$filename"
done
logs:
#!/usr/bin/env bash
title="logs"
log_file="$HOME/bashscript.log"
echo -ne "\e[22;0t"; echo -ne "\e]0;$title\007"; trap 'echo -ne "\e[23;0t"' EXIT
echo "tailing: $log_file"
red="$(tput setaf 1)"
green="$(tput setaf 2)"
yellow="$(tput setaf 3)"
blue="$(tput setaf 4)"
magenta="$(tput setaf 5)"
cyan="$(tput setaf 6)"
reset="$(printf "%b" "\033[0m")"
tail -f "$log_file" \
| sed -u \
-e 's/\[\x00-\x09\x0B-\x1F\x7F]//' \
-e s/"go compilation error"/"$red&$reset"/i \
-e s/"RUNNING TESTS"/"$magenta&$reset"/i \
-e s/"RESULTS FAIL"/"$red&$reset"/i \
-e s/"\(FAIL\)\(.*\)\(test.*\)"/"$red\1$reset\2$cyan\3$reset"/i \
-e s/"FAIL"/"$red&$reset"/i \
-e s/"TEST:.*"/"$cyan&$reset"/i \
-e s/PASS/"$green&$reset"/i \
-e s/WARNING/"$yellow&$reset"/i \
;
build:
#!/usr/bin/env bash
title="build"
proj_dir="$PWD"
echo -ne "\e[22;0t"; echo -ne "\e]0;$title\007"; trap 'echo -ne "\e[23;0t"' EXIT
red="$(tput setaf 1)"
green="$(tput setaf 2)"
yellow="$(tput setaf 3)"
magenta="$(tput setaf 5)"
cyan="$(tput setaf 6)"
reset="$(printf "%b" "\033[0m")"
exec 3>&1
log () { echo -e "[$(date '+%T.%3N')] $*" >> ~/bashscript.log; }
inotify_action () {
path_rel="$(realpath --relative-to="$proj_dir" "$1")"
[[ "${path_rel: -1}" == "~" ]] && return
[[ "$path_rel" =~ ^(.git/|.idea/|build/|scratch/|archive/|compile/) ]] && return
[[ "$path_rel" =~ (.lock|.log)$ ]] && return
if [[ ( "$1" =~ ".go"$ || $1 =~ \.go\.sh$ ) && ! "$1" =~ "_test.go"$ && ! "$1" =~ "testutil.go"$ ]]; then
profile_start="$EPOCHREALTIME"
if ! build_out="$(go build -o "build/shcomp2" 2>&1 1>&3)"; then
log "[build] compile error:\n$build_out"
else
log "[build] compile success"
fi
profile_end="$EPOCHREALTIME"
compile_ms="$(bc <<< "scale=2;(($profile_end-$profile_start)*10000)/10")"
printf "\e]0;%s %3dms\007" "$title" "${compile_ms%%.*}"
echo "compiled: ${compile_ms}ms - $1"
fi
}
inotify_action "dummy.go"
inotifywait -q -m -r -e close_write,create,delete "$proj_dir" | \
while read -r dir events filename; do
inotify_action "$dir$filename"
done
ci: ci-build ci-test ci-format
ci-build:
mkdir -p "build"
go build -o "build/shcomp2"
ci-test:
go test ./...
ci-format:
gofmt_out="$(gofmt -l .)" && test -z "$gofmt_out" || { printf "error: go files incorrectly formatted\n%s\n" "$gofmt_out"; exit 1; }