-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.sh
executable file
·128 lines (107 loc) · 1.88 KB
/
make.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
#!/bin/sh
set -e
for bin in $(grep -vE "^#" make.dep | awk '{ print $1 }'); do
if ! hash "$bin" 2> /dev/null; then
url=$(grep "^$bin" make.dep | awk '{ print $2 }')
>&2 printf "missing binary %s\n" "$bin"
>&2 printf "install binary via: %s\n" "$url"
exit 1
fi
done
_err() {
>&2 echo $@
exit 1
}
_version() {
tag=$(
git log --decorate=full --format=format:%d |
head -1 |
tr ',' '\n' |
grep tag: |
cut -d / -f 3 |
tr -d ',)'
)
if [ -z "$tag" ]; then
echo "devel $(git log -n 1 --format='format:%h %cd' HEAD)"
else
echo "$tag"
fi
}
lessc_bin="node_modules/.bin/lessc"
LDFLAGS="$LDFLAGS $(printf -- "-X 'djinn-ci.com/version.Build=%s'" "$(_version)")"
TAGS="$TAGS netgo osusergo"
_exec() {
set -x
"$@"
set +x
}
_css() {
_exec "$lessc_bin" --clean-css template/static/less/"$1".less template/static/"$1".css
}
_ui() {
[ ! -f "$lessc_bin" ] && _exec yarn install
_css main
_css auth
_css error
_exec qtc
}
_build() {
[ ! -d bin ] && mkdir bin
targets="$1"
if [ -z "$targets" ]; then
targets="$(ls cmd)"
fi
_exec go generate ./...
for target in $targets; do
GOOS="$GOOS" GOARCH="$GOARCH" _exec go build \
-trimpath \
-ldflags "$LDFLAGS" \
-tags "$TAGS" \
-o bin/"$target" \
./cmd/"$target"
done
}
_manif() {
cd bin && {
_exec sha256sum djinn* | awk '{ print "SHA256 ("$2") = " $1 }' > sum.manif
cd - > /dev/null
}
}
_test() {
_exec go generate ./...
_exec go test ./...
}
_clean() {
_exec rm -f bin/*
_exec find . -name "*.log" -exec rm -f {} \;
_exec go clean -cache -testcache
}
case "$1" in
build)
_build
;;
clean)
_clean
;;
css)
_css main
_css auth
_css error
;;
ui)
_ui
;;
*)
if [ "$1" = "" ]; then
_ui
_test
_build
_manif
elif [ -d "cmd/djinn-$1" ]; then
_build "djinn-$1"
elif [ "$1" = "runner" ]; then
_build djinn-runner
else
_err "unknown target: $1"
fi
esac