-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathjustfile
More file actions
333 lines (296 loc) · 9.64 KB
/
justfile
File metadata and controls
333 lines (296 loc) · 9.64 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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# this setting will allow passing arguments through to tasks, see the docs here
# https://just.systems/man/en/settings.html#positional-arguments
set positional-arguments
# Disable echoing recipe lines before executing
set quiet
# Enable unstable features
set unstable
# Ignore recipe lines beginning with "#"
set ignore-comments
# causes the evaluator to skip evaluating unused variables
set lazy
# import the user's justfile if it exists
import? '~/.justfile'
import? '~/justfile'
# set some just variables
j_dir := justfile_directory()
tool_bin := clean(j_dir / "tools/tool")
build_dir := clean(j_dir / "build")
cache_dir := clean(j_dir / ".cache")
tarout_dir := clean(build_dir / "tar")
gotestsum_bin := which("gotestsum") || tool_bin + " gotestsum"
# build specific vars
APP_NAME := env("APP_NAME", "go-camo")
APP_VER := env("APP_VER", "")
GITHASH := env("GITHASH", "")
BUILD_OPTIONS := env("BUILD_OPTIONS", "-trimpath")
BUILD_DEPFLAGS := env("BUILD_DEPFLAGS", '-tags netgo,production')
BUILD_LDFLAGS := env("BUILD_LDFLAGS", '-s -w')
SIGN_KEY := env("SIGN_KEY", home_dir() / ".minisign/go-camo.key")
CC_BUILD_TARGETS := env("CC_BUILD_TARGETS", "go-camo url-tool")
CC_BUILD_ARCHES := env("CC_BUILD_ARCHES", "darwin-arm64 freebsd-amd64 linux-amd64 linux-arm64 windows-amd64")
GOVER :=`go version | awk '{print $3}' | tr -d '.'`
OS :=`go env GOHOSTOS`
ARCH :=`go env GOHOSTARCH`
# test specific vars
GOTEST_FLAGS := env("GOTEST_FLAGS", "-cpu=1,2 -count=1 -vet=off")
GOTESTSUM_FLAGS := env("GOTESTSUM_FLAGS", "")
# export some env vars
export VERSION_VAR := "main.ServerVersion"
export GOPRIVATE := "github.com/dropwhile/go-camo"
# some exported vars (pre-configure go build behavior)
export CGO_ENABLED := "0"
# unsure toolchains are not automatically downloaded/upgraded
export GOTOOLCHAIN := "local"
_banner *ARGS:
printf '{{ YELLOW }}[%s] %-72s{{ NORMAL }}\n' "$(date +%H:%M:%S)" "{{ ARGS }}"
# show the list of available commands
[default]
help:
just --list --justfile {{ justfile() }}
# run go vet
[group('~checks:default')]
vet:
just _banner ">> running go vet"
go vet $(go list ./... | grep -v "github.com/dropwhile/icanbringthat/rpc")
# run staticcheck
[group('~checks:default')]
staticcheck:
just _banner ">> running staticcheck"
{{ tool_bin }} staticcheck ./...
# run errcheck
[group('~checks:default')]
errcheck:
just _banner ">> running errcheck"
{{ tool_bin }} errcheck \
-ignoretests \
-exclude .errcheck-excludes.txt \
./...
# run errortype
[group('~checks:default')]
errortype:
just _banner ">> running errortype"
{{ tool_bin }} errortype ./...
# run nilness
[group('~checks:default')]
nilness:
just _banner ">> running nilness"
{{ tool_bin }} nilness ./...
# run ineffassign
[group('~checks:default')]
ineffassign:
just _banner ">> running ineffassign"
{{ tool_bin }} ineffassign ./...
# run govulncheck
[group('~checks:default')]
govulncheck:
just _banner ">> running govulncheck"
{{ tool_bin }} govulncheck ./...
# run betteralign
[group('~checks:default')]
betteralign:
just _banner ">> running betteralign"
{{ tool_bin }} betteralign ./...
# run gosec
[group('~checks:default')]
gosec:
just _banner ">> running gosec"
{{ tool_bin }} gosec \
-quiet \
-exclude-generated \
-exclude-dir=cmd/refidgen \
-exclude-dir=tools ./...
# run nilaway (will have false positives)
[group('~checks:optional')]
nilaway:
just _banner ">> running nilaway"
-{{ tool_bin }} nilaway -test=false \
-include-pkgs "github.com/dropwhile/icanbringthat" \
-exclude-file-docstrings "@generated,Code generated by,Autogenerated by" \
./...
# run deadcode (will have false positives)
[group('~checks:optional')]
deadcode:
just _banner ">> running deadcode"
-{{ tool_bin }} deadcode -test ./...
# run errorlint (will have false positives)
[group('~checks:optional')]
errorlint:
just _banner ">> running errorlint"
-{{ tool_bin }} go-errorlint ./...
# run all ~checks:default checkers
[group('checks')]
check: vet staticcheck errcheck errortype nilness ineffassign govulncheck betteralign gosec
# run all ~checks:optional checkers
[group('checks')]
check-optional: nilaway deadcode errorlint
# run modernize
[group('hygiene')]
modernize:
just _banner ">> running modernize"
{{ tool_bin }} modernize -rangeint=false -test ./...
# run 'go fix'
[group('hygiene')]
fix:
just _banner ">> running go fix"
go fix -rangeint=false ./...
# update go.mod dependencies
[group('hygiene')]
update-go-deps:
just _banner ">> updating go.mod dependencies"
go get -u all
go mod tidy
# update dependencies
[group('hygiene')]
update-deps: update-go-deps
# run coverage analysis
[group('tests')]
cover:
just _banner ">> running coverage analysis"
go test -cover {{GOTEST_FLAGS}} ./...
# run benchmarks
[group('tests')]
bench +FLAGS='-vet=off':
just _banner ">> running benchtests"
go test -bench="." -run="^$" -test.benchmem=true {{FLAGS}} ./...
# run tests
[group('tests')]
test:
just _banner ">> running tests"
{{gotestsum_bin}} {{GOTESTSUM_FLAGS}} -- {{GOTEST_FLAGS}} ./...
# clean
[group('build')]
clean: (_banner ">> cleaning build dir")
rm -rf "{{build_dir}}"
# build man pages
[group('build')]
manpages: (_banner ">> building manual pages")
[ -d "{{build_dir}}/man" ] || mkdir -p "{{build_dir}}/man"
for file in man/*.scd; do \
bname="${file##*/}"; \
fname="${bname%.scd}"; \
scdoc < $file > "{{build_dir}}/man/${fname}"; \
done
# build binaries
[group('build')]
build: (_banner ">> building binaries")
#!/bin/sh
set -eu
APP_VER="{{ APP_VER }}"
if [ "$APP_VER" = "" ]; then
APP_VER="$(git describe --always --tags|sed 's/^v//')"
fi
[ -d "{{ build_dir }}/bin" ] || mkdir -p "{{ build_dir }}/bin"
echo "> Building as APP_VER=${APP_VER}"
for x in {{CC_BUILD_TARGETS}}; do
echo " * ${x} ...";
go build {{ BUILD_DEPFLAGS }} {{ BUILD_OPTIONS }} \
-ldflags="{{ BUILD_LDFLAGS }} -X {{ VERSION_VAR }}=${APP_VER}" \
-o "{{ build_dir }}/bin/${x}" ./cmd/${x};
done
# build binaries tarball
[group('release')]
tar: manpages build (_banner ">> assembling tarball")
#!/bin/sh
set -eu
APP_VER="{{ APP_VER }}"
if [ "$APP_VER" = "" ]; then
APP_VER="$(git describe --always --tags|sed 's/^v//')"
fi
OUTDIR="{{tarout_dir}}/{{APP_NAME}}-${APP_VER}"
mkdir -p "${OUTDIR}"
cp -R {{build_dir}}/bin ${OUTDIR}/
cp -R {{build_dir}}/man ${OUTDIR}/
tar -C {{tarout_dir}} \
-czf {{tarout_dir}}/{{APP_NAME}}-${APP_VER}.{{GOVER}}.{{OS}}-{{ARCH}}.tar.gz \
{{APP_NAME}}-${APP_VER}/
rm -rf "${OUTDIR}"
# build cross compiled binaries
[group('build')]
cross-build: (_banner ">> building cc targets")
#!/bin/sh
set -eu
APP_VER="{{ APP_VER }}"
if [ "$APP_VER" = "" ]; then
APP_VER="$(git describe --always --tags|sed 's/^v//')"
fi
for x in {{CC_BUILD_TARGETS}}; do
for y in {{CC_BUILD_ARCHES}}; do
printf -- "--> %15s: %s\n" "${y}" "${x}"
GOOS="${y%%-*}"
GOARCH="${y##*-}"
EXT=""
if echo "${y}" | grep -q 'windows-'; then EXT=".exe"; fi;
env GOOS=${GOOS} GOARCH=${GOARCH} \
go build {{BUILD_DEPFLAGS}} {{BUILD_OPTIONS}} \
-ldflags "{{BUILD_LDFLAGS}} -X {{VERSION_VAR}}=${APP_VER}" \
-o "{{build_dir}}/bin/${x}.${GOOS}-${GOARCH}${EXT}" \
./cmd/${x}
done
done
# build cross compiled tarballs
[group('release')]
cross-tar: manpages cross-build (_banner ">> building cc tarballs")
#!/bin/sh
set -eu
APP_VER="{{ APP_VER }}"
if [ "$APP_VER" = "" ]; then
APP_VER="$(git describe --always --tags|sed 's/^v//')"
fi
mkdir -p "{{tarout_dir}}"
for x in {{CC_BUILD_ARCHES}}; do
printf -- "--> %15s\n" "${x}"
EXT=""
if echo "${x}" | grep -q 'windows-'; then EXT=".exe"; fi;
XDIR="{{GOVER}}.${x}"
ODIR="{{tarout_dir}}/${XDIR}/{{APP_NAME}}-${APP_VER}"
mkdir -p "${ODIR}/bin"; \
mkdir -p "${ODIR}/man"; \
for t in {{CC_BUILD_TARGETS}}; do
cp {{build_dir}}/bin/${t}.${x}${EXT} ${ODIR}/bin/${t}${EXT}
done
cp -R {{build_dir}}/man ${ODIR}/
tar -C {{tarout_dir}}/${XDIR} \
-czf {{tarout_dir}}/{{APP_NAME}}-${APP_VER}.${XDIR}.tar.gz \
{{APP_NAME}}-${APP_VER}
rm -rf "{{tarout_dir}}/${XDIR}/"
done
# build container images
[group('build')]
build-oci-image *FLAGS: (_banner ">> building container images")
#!/bin/sh
set -eu
GITHASH="{{ GITHASH }}"
if [ "$GITHASH" = "" ]; then
GITHASH="$(git rev-parse --short HEAD)"
fi
APP_VER="{{ APP_VER }}"
if [ "$APP_VER" = "" ]; then
APP_VER="$(git describe --always --tags|sed 's/^v//')"
fi
docker build {{FLAGS}} \
--build-arg GITHASH=${GITHASH} \
--build-arg APP_VER=${APP_VER} \
--build-arg BUILDKIT_INLINE_CACHE=1 \
-t go-camo:latest \
-f docker/Dockerfile \
.
# build binaries tarball
[group('release')]
release-sign: (_banner ">> signing release")
#!/bin/sh
set -eu
APP_VER="{{ APP_VER }}"
if [ "$APP_VER" = "" ]; then
APP_VER="$(git describe --always --tags|sed 's/^v//')"
fi
(
cd build/tar; shasum -a 256 go-camo-*.tar.gz > SHA256; \
minisign -S -s {{SIGN_KEY}} \
-c "go-camo-${APP_VER} SHA256" \
-t "go-camo-${APP_VER} SHA256" \
-x SHA256.sig -m SHA256; \
)
# build binaries tarball
[group('release')]
release: cross-tar release-sign