-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev-test-build.sh
166 lines (144 loc) · 3.92 KB
/
dev-test-build.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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env bash
## Purpose: This script is used to run all the necessary checks and
## tests for the project.
## Fail on any error:
set -e
## Declare default styles:
_sty_bold=""
_sty_underline=""
_sty_standout=""
_sty_normal=""
_sty_black=""
_sty_red=""
_sty_green=""
_sty_yellow=""
_sty_blue=""
_sty_magenta=""
_sty_cyan=""
_sty_white=""
## Set styles if we are on terminal:
if test -t 1; then
## Check if the terminal supports colors:
ncolors=$(tput colors)
## Defines styles:
if test -n "$ncolors" && test "${ncolors}" -ge 8; then
_sty_bold="$(tput bold)"
_sty_underline="$(tput smul)"
_sty_standout="$(tput smso)"
_sty_normal="$(tput sgr0)"
_sty_black="$(tput setaf 0)"
_sty_red="$(tput setaf 1)"
_sty_green="$(tput setaf 2)"
_sty_yellow="$(tput setaf 3)"
_sty_blue="$(tput setaf 4)"
_sty_magenta="$(tput setaf 5)"
_sty_cyan="$(tput setaf 6)"
_sty_white="$(tput setaf 7)"
fi
fi
_clean=""
while getopts ":c" opt; do
case ${opt} in
c)
_clean="true"
;;
?)
echo "Invalid option: -${OPTARG}."
exit 1
;;
esac
done
_get_now() {
t=${EPOCHREALTIME} # remove the decimal separator (s → µs)
t=${t%???} # remove the last three digits (µs → ms)
echo "${t}"
}
_get_diff() {
printf "scale=3; %s - %s\n" "${2}" "${1}" | bc
}
_print_header() {
printf "${_sty_bold}${_sty_blue}🔵 Running %s${_sty_normal}" "${1}"
}
_print_success() {
_start="${1}"
_until="${2}"
_elapsed=$(_get_diff "${_start}" "${_until}")
printf "${_sty_bold}${_sty_green} ✅ %ss${_sty_normal}\n" "${_elapsed}"
}
_clean() {
_print_header "clean"
_start=$(_get_now)
chronic -- cabal clean && chronic -- cabal v1-clean
_print_success "${_start}" "$(_get_now)"
}
_hpack() {
_print_header "hpack (v$(hpack --numeric-version))"
_start=$(_get_now)
chronic -- hpack
_print_success "${_start}" "$(_get_now)"
}
_fourmolu() {
_print_header "fourmolu (v$(fourmolu --version | head -n1 | cut -d' ' -f2))"
_start=$(_get_now)
chronic -- fourmolu --quiet --mode check src/ test/
_print_success "${_start}" "$(_get_now)"
}
_prettier() {
_print_header "prettier (v$(prettier --version))"
_start=$(_get_now)
chronic -- prettier --check .
_print_success "${_start}" "$(_get_now)"
}
_nixpkgs_fmt() {
_print_header "nixpkgs-fmt (v$(nixpkgs-fmt --version 2>&1 | cut -d' ' -f2))"
_start=$(_get_now)
chronic -- find . -iname "*.nix" -not -path "*/nix/sources.nix" -exec nixpkgs-fmt --check {} \;
_print_success "${_start}" "$(_get_now)"
}
_hlint() {
_print_header "hlint (v$(hlint --numeric-version))"
_start=$(_get_now)
chronic -- hlint src/ test/
_print_success "${_start}" "$(_get_now)"
}
_cabal_build() {
_print_header "cabal build (v$(cabal --numeric-version))"
_start=$(_get_now)
chronic -- cabal build -O0
_print_success "${_start}" "$(_get_now)"
}
_cabal_test() {
_print_header "cabal test (v$(cabal --numeric-version))"
_start=$(_get_now)
chronic -- cabal v1-test
_print_success "${_start}" "$(_get_now)"
}
_weeder() {
_print_header "weeder (v$(weeder --version | head -n1 | cut -d' ' -f3))"
_start=$(_get_now)
chronic -- weeder
_print_success "${_start}" "$(_get_now)"
}
_cabal_haddock() {
_print_header "cabal haddock (v$(cabal --numeric-version))"
_start=$(_get_now)
chronic -- cabal haddock -O0 \
--haddock-quickjump \
--haddock-hyperlink-source \
--haddock-html-location="https://hackage.haskell.org/package/\$pkg-\$version/docs"
_print_success "${_start}" "$(_get_now)"
}
_scr_start=$(_get_now)
if [ -n "${_clean}" ]; then
_clean
fi
_hpack
_fourmolu
_prettier
_nixpkgs_fmt
_hlint
_cabal_build
_cabal_test
_weeder
_cabal_haddock
printf "Finished all in %ss\n" "$(_get_diff "${_scr_start}" "$(_get_now)")"