Repository navigation
Expand file tree
/
Copy pathTaskfile.yml
More file actions
165 lines (147 loc) · 5.87 KB
/
Copy pathTaskfile.yml
File metadata and controls
165 lines (147 loc) · 5.87 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
# https://taskfile.dev
#
# One Taskfile for every module in the workspace. Modules are read from
# go.work, so a new module is covered the moment it is added there.
#
# Two tiers: `task test` is the quick loop (cached, no race); `task check` is
# the full gate run once before a commit (gofmt, vet, race tests, short fuzz of
# every fuzz target). Nothing here runs automatically: there is no CI on push.
version: "3"
vars:
# Module directories from go.work, relative to the repo root.
MODULES:
sh: go list -m -f '{{"{{"}}.Dir{{"}}"}}' | sed "s#^$(pwd)#.#" | tr '\n' ' '
FUZZTIME: '{{.FUZZTIME | default "10s"}}'
tasks:
default:
desc: List available tasks
cmds:
- task --list
silent: true
modules:
desc: List the workspace modules
cmds:
- for: { var: MODULES }
cmd: echo "{{.ITEM}}"
silent: true
test:
desc: 'Quick tests for every module, or one: task test -- ./dotenv'
cmds:
- |
set -e
for m in {{if .CLI_ARGS}}{{.CLI_ARGS}}{{else}}{{.MODULES}}{{end}}; do
echo "── $m"; (cd "$m" && go test ./...)
done
test:race:
desc: Race-detector tests for every module
cmds:
- |
set -e
for m in {{.MODULES}}; do echo "── $m"; (cd "$m" && go test -race ./...); done
vet:
desc: go vet every module
cmds:
- |
set -e
for m in {{.MODULES}}; do echo "── $m"; (cd "$m" && go vet ./...); done
windows:check:
desc: 'go vet and compile every test binary of every module for GOOS=windows (there is no Windows CI: this proves the Windows code paths build; it runs nothing)'
cmds:
- |
set -e
out=$(mktemp -d); trap 'rm -rf "$out"' EXIT
for m in {{.MODULES}}; do
# plugins/file: file_test.go calls syscall.Mkfifo, which Windows
# lacks, so its tests do not build there (known, not yet fixed).
# Its non-test code is still built.
if [ "$m" = "./plugins/file" ]; then
echo "── $m (build only)"; (cd "$m" && GOOS=windows go build ./...); continue
fi
echo "── $m"
(cd "$m" && GOOS=windows go vet ./... && GOOS=windows go test -c -o "$out/" ./...)
done
fmt:
desc: gofmt the tree
cmds:
- gofmt -w .
fmt:check:
desc: Fail when any Go file is unformatted
cmds:
- |
out=$(gofmt -l .)
if [ -n "$out" ]; then echo "gofmt needed on:"; echo "$out"; exit 1; fi
fuzz:list:
desc: List every fuzz target as <package dir> <Fuzz name>
cmds:
- |
grep -rH --include=*_test.go -o "^func Fuzz[A-Za-z0-9_]*" . | sed -e "s#/[^/]*_test.go:func # #" | sort -u
silent: true
fuzz:
desc: 'Fuzz one target: task fuzz -- ./jsonc FuzzParseRender [30s]'
cmds:
- |
set -- {{.CLI_ARGS}}
dir=$1; name=$2; t=${3:-30s}
cd "$dir" && go test -run '^$' -fuzz "^$name\$" -fuzztime "$t" .
fuzz:all:
desc: 'Fuzz every target for FUZZTIME each (default 10s): task fuzz:all FUZZTIME=30s'
cmds:
- |
set -e
task fuzz:list | while read -r dir name; do
echo "── $dir $name"
(cd "$dir" && go test -run '^$' -fuzz "^$name\$" -fuzztime {{.FUZZTIME}} .)
done
tidy:
desc: go mod tidy every module (needs the workspace for unreleased siblings)
cmds:
- |
for m in {{.MODULES}}; do echo "── $m"; (cd "$m" && go mod tidy) || true; done
cfgkit:check:
desc: 'Prove cfgkit contrib/format-jsonc (local branch format-jsonc in the cfgkit clone) against this tree, in a temp go.work outside both repos'
vars:
CFGKIT_REPO: '{{.CFGKIT_REPO | default "../cfgkit"}}'
cmds:
- |
set -e
here=$(pwd); ck=$(cd {{.CFGKIT_REPO}} && pwd)
ws=$(mktemp -d); trap 'rm -rf "$ws"' EXIT
git -C "$ck" worktree add -q --detach "$ws/cfgkit" format-jsonc
trap 'git -C "$ck" worktree remove --force "$ws/cfgkit"; rm -rf "$ws"' EXIT
cd "$ws"; z=v0.0.0-00010101000000-000000000000
go work init ./cfgkit ./cfgkit/contrib/format-jsonc "$here" "$here/jsonc" "$here/dotenv"
go work edit -replace=github.com/ubgo/textdata@$z="$here" -replace=github.com/ubgo/textdata/jsonc@$z="$here/jsonc" -replace=github.com/ubgo/textdata/dotenv@$z="$here/dotenv"
export GOWORK="$ws/go.work"
for m in cfgkit/contrib/format-jsonc cfgkit; do echo "── $m"; (cd "$m" && go vet ./... && go test -race -count=1 ./...); done
deps:check:
desc: Fail when a module directly requires something its non-test code does not import (test-only or unused); the integration module is exempt
cmds:
- |
bad=0
for m in {{.MODULES}}; do
[ "$m" = "./integration" ] && continue
used=$(cd "$m" && go list -deps -f '{{"{{"}}with .Module{{"}}"}}{{"{{"}}.Path{{"}}"}}{{"{{"}}end{{"}}"}}' ./... | sort -u)
for r in $(cd "$m" && go mod edit -json | python3 -c 'import json,sys;[print(r["Path"]) for r in json.load(sys.stdin).get("Require") or [] if not r.get("Indirect")]'); do
echo "$used" | grep -qx "$r" || { echo "$m requires $r but its non-test code does not import it"; bad=1; }
done
done
exit $bad
tidy:check:
desc: Fail when any module's go.mod or go.sum is not what a standalone `go mod tidy` writes
cmds:
- |
bad=0
for m in {{.MODULES}}; do
out=$(cd "$m" && GOWORK=off go mod tidy -diff 2>&1) || { echo "── $m is not tidy (run: cd $m && GOWORK=off go mod tidy)"; echo "$out"; bad=1; }
done
exit $bad
check:
desc: The full gate, once before a commit — gofmt, go mod tidy, dependency rules, vet, Windows vet and test build, race tests, short fuzz of every target
cmds:
- task: fmt:check
- task: tidy:check
- task: deps:check
- task: vet
- task: windows:check
- task: test:race
- task: fuzz:all