Repository navigation
Expand file tree
/
Copy pathTaskfile.yml
More file actions
189 lines (161 loc) · 6.93 KB
/
Copy pathTaskfile.yml
File metadata and controls
189 lines (161 loc) · 6.93 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
version: '3'
silent: true
vars:
# Prefer the explicit `toolchain goX.Y.Z` line; fall back to the `go X.Y` line.
# Required for coverage tasks — the bare language version is not a valid toolchain name.
GO_TOOLCHAIN:
sh: |
tc=$(awk '/^toolchain / { print $2; exit }' go.mod)
if [ -z "$tc" ]; then
tc=$(awk '/^go / { print "go" $2; exit }' go.mod)
fi
echo "$tc"
GOTOOLCHAIN_COVERAGE: '{{.GO_TOOLCHAIN}}+auto'
tasks:
# ── Default ──────────────────────────────────────────────────────────────
default:
desc: Show available tasks
cmds:
- task --list
# ── Build ─────────────────────────────────────────────────────────────────
build:
desc: Compile all packages (library + examples) and durable-inspect
cmds:
- echo "==> Building durable-go..."
- go build ./...
- go build -C examples ./...
- go build -C benchmarks -o /dev/null .
- mkdir -p bin
- go build -o bin/durable-inspect ./cmd/durable-inspect
- echo "==> Build complete (bin/durable-inspect)"
bench:
desc: Measure durability overhead (journal persist vs replay vs no engine)
cmds:
- go run ./benchmarks/ -- {{.CLI_ARGS}}
bench-test:
desc: Run testing.B microbenchmarks (journal append/load, RunTask)
cmds:
- go test -run=^$ -bench=. -benchmem -count=1 ./...
# ── Test ──────────────────────────────────────────────────────────────────
test:
desc: Run all tests
cmds:
- echo "==> Running tests..."
- go test ./... -count=1 -race
- go test -C examples ./... -count=1
- go test -C benchmarks ./... -count=1
- echo "==> Tests complete"
test-coverage:
desc: Run tests with coverage; writes coverage.out and coverage.html
env:
GOTOOLCHAIN: '{{.GOTOOLCHAIN_COVERAGE}}'
cmds:
- echo "==> Running tests with coverage..."
- go test ./... -count=1 -coverprofile=coverage.out
- echo "==> Total coverage:"
- go tool cover -func=coverage.out | grep '^total:'
- go tool cover -html=coverage.out -o coverage.html
- 'echo "==> Coverage report: coverage.html"'
proto:
desc: Regenerate pb/journal.pb.go from journal.proto
cmds:
- echo "==> go generate ./pb/"
- go generate ./pb/
- echo "==> Proto generate complete"
# ── Format ────────────────────────────────────────────────────────────────
fmt:
desc: Format all Go files (gofmt -s -w)
cmds:
- echo "==> gofmt -s -w"
- gofmt -s -w .
- echo "==> Format complete"
fmt-check:
desc: Fail if any Go file needs gofmt -s (run `task fmt` to fix)
cmds:
- |
echo "==> Checking gofmt -s..."
files=$(gofmt -s -l .)
if [ -n "$files" ]; then
echo "These files are not gofmt -s formatted. Run: task fmt"
echo "$files"
exit 1
fi
echo "==> gofmt -s OK"
# ── Spell-check ───────────────────────────────────────────────────────────
spell:
desc: Spell-check tracked source files (skips gitignored paths)
cmds:
- |
echo "==> misspell"
files=$(git ls-files -z -- '*.go' '*.md' '*.yaml' '*.yml')
if [ -z "$files" ]; then
echo "No files to spell-check"
else
printf '%s' "$files" | xargs -0 go run github.com/client9/misspell/cmd/misspell@latest -error
fi
# ── Lint ──────────────────────────────────────────────────────────────────
lint:
desc: Run all linters (fmt-check, spell, go vet, golangci-lint)
cmds:
- task: fmt-check
- task: spell
- echo "==> go vet..."
- go vet ./...
- echo "==> golangci-lint..."
- golangci-lint run ./...
- echo "==> Lint complete"
# ── Module maintenance ────────────────────────────────────────────────────
tidy:
desc: Tidy module dependencies (go mod tidy)
cmds:
- echo "==> Tidying module dependencies..."
- go mod tidy
- go mod tidy -C examples
- go mod tidy -C benchmarks
- echo "==> Tidy complete"
# ── Clean ─────────────────────────────────────────────────────────────────
clean:
desc: Remove coverage artifacts
cmds:
- echo "==> Cleaning..."
- rm -f coverage.out coverage.html
- echo "==> Clean complete"
# ── Security ──────────────────────────────────────────────────────────────
secrets-scan:
desc: Scan tracked files for leaked secrets (gitleaks)
cmds:
- |
echo "==> gitleaks detect"
if command -v gitleaks >/dev/null 2>&1; then
gitleaks detect --source . --verbose --redact
elif command -v docker >/dev/null 2>&1; then
docker run --rm -v "$(pwd):/repo" -w /repo zricethezav/gitleaks:latest detect --source=/repo --verbose --redact
else
echo "Install gitleaks or Docker to run secrets-scan."
exit 1
fi
govuln:
desc: Run govulncheck against all packages
cmds:
- |
echo "==> govulncheck"
if ! command -v govulncheck >/dev/null 2>&1; then
go install golang.org/x/vuln/cmd/govulncheck@latest
fi
echo "==> GOTOOLCHAIN={{.GOTOOLCHAIN_COVERAGE}}"
GOTOOLCHAIN="{{.GOTOOLCHAIN_COVERAGE}}" govulncheck ./...
echo "==> govulncheck complete"
# ── All-in-one gate (run before push) ────────────────────────────────────
#
# Mirrors CI: lint → test → build → secrets-scan → govuln
# test-coverage is omitted (run it separately when you need the HTML report).
# If fmt-check fails, run `task fmt` first.
check:
desc: All CI/security gates locally (lint, test, build, secrets-scan, govuln)
cmds:
- task: lint
- task: test
- task: build
- task: secrets-scan
- task: govuln
- echo "==> All checks passed (ready to push)"