-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
233 lines (205 loc) · 6.39 KB
/
Copy pathTaskfile.yml
File metadata and controls
233 lines (205 loc) · 6.39 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
# https://taskfile.dev
version: "3"
vars:
PROJECT_NAME: policy-zig
BUILD_DIR: zig-out
tasks:
default:
desc: "Build the project in debug mode"
aliases: [b]
cmds:
- zig build
build:
desc: "Build the project with specified optimization"
aliases: [build-opt]
cmds:
- zig build -Doptimize={{.OPTIMIZE | default "Debug"}}
build:protos:
desc: "Build the project with protos"
cmds:
- zig build -Dgen-proto=true gen-proto
build:release:
desc: "Build the project in release mode (ReleaseFast)"
aliases: [br, release]
cmds:
- zig build -Doptimize=ReleaseFast
build:safe:
desc: "Build the project in ReleaseSafe mode"
aliases: [bs]
cmds:
- zig build -Doptimize=ReleaseSafe
build:small:
desc: "Build the project in ReleaseSmall mode"
aliases: [bsm]
cmds:
- zig build -Doptimize=ReleaseSmall
bench:
desc: "Run benchmarks (log/metric/trace × policy counts)"
cmds:
- zig build bench
test:
desc: "Run all tests"
aliases: [t]
cmds:
- zig build test -Doptimize=ReleaseSafe
test:file:
desc: "Run tests for a specific file"
aliases: [tf]
cmds:
- |
if [ -z "{{.FILE}}" ]; then
echo "Usage: task test:file FILE=<path>"
echo "Example: task test:file FILE=src/parser.zig"
exit 1
fi
zig test {{.FILE}}
test:summary:
desc: "Run tests with summary output"
aliases: [ts]
cmds:
- zig build test --summary all
format:
desc: "Format all Zig source files"
aliases: [fmt, f]
dir: "{{.TASKFILE_DIR}}"
cmds:
- zig fmt src/
- zig fmt build.zig
format:check:
desc: "Check if code is formatted correctly"
aliases: [fmt-check, fc]
dir: "{{.TASKFILE_DIR}}"
cmds:
- zig fmt --check src/
- zig fmt --check build.zig
lint:
desc: "Run linting checks"
aliases: [l]
cmds:
- task: format:check
- task: lint:zig
lint:zig:
desc: "Run ziglint on handwritten Zig files before merge"
aliases: [zl]
dir: "{{.TASKFILE_DIR}}"
cmds:
- |
if ! command -v ziglint >/dev/null 2>&1; then
echo "ziglint is required before merge. Install it or add it to PATH."
exit 1
fi
ziglint
clean:
desc: "Clean build artifacts"
aliases: [c]
cmds:
- rm -rf zig-out/
- rm -rf zig-cache/
- rm -rf .zig-cache/
check:
desc: "Check the project (build without running)"
cmds:
- zig build --summary failures
deps:
desc: "Check dependencies and Zig installation"
cmds:
- zig version
- zig env
do:
desc: "Run all pre-commit checks"
cmds:
- task: format
- task: lint
- task: test
signoff:
desc: "Sign off the codebase"
aliases: ["sign", "s"]
cmds:
- task: do
- task: build:safe
- gh signoff
info:
desc: "Show project information"
cmds:
- echo "Project {{.PROJECT_NAME}}"
- echo "Build directory {{.BUILD_DIR}}"
- zig version
- echo ""
- echo "Available build modes:"
- echo " - Debug (default)"
- echo " - ReleaseFast (task build:release)"
- echo " - ReleaseSafe (task build:safe)"
- echo " - ReleaseSmall (task build:small)"
update:protos:
desc: "Update proto files"
cmds:
- buf export buf.build/tero/policy -o proto
- buf export buf.build/opentelemetry/opentelemetry -o proto
- task: build:protos
# =============================================================================
# CI Setup
# =============================================================================
ci:setup:
desc: "Install CI/development dependencies (idempotent, safe to run locally)"
dir: "{{.TASKFILE_DIR}}"
cmds:
- |
echo "Checking for required dependencies..."
# Check for hyperscan/vectorscan
if ! pkg-config --exists libhs 2>/dev/null; then
echo "Installing hyperscan..."
if [ "$(uname)" = "Darwin" ]; then
if command -v brew >/dev/null 2>&1; then
brew install vectorscan pkg-config
else
echo "Homebrew not found. Install vectorscan manually or use Hermit."
fi
elif [ "$(uname)" = "Linux" ]; then
if command -v apt-get >/dev/null 2>&1; then
sudo apt-get update && sudo apt-get install -y libhyperscan-dev pkg-config
elif command -v yum >/dev/null 2>&1; then
sudo yum install -y hyperscan-devel pkg-config
else
echo "Unknown package manager. Install hyperscan manually."
fi
else
echo "Unknown platform: $(uname)"
fi
else
echo "Hyperscan already installed"
fi
# Check for ziglint (required by `task lint:zig`, which `signoff` runs).
# Installed from prebuilt release binaries; pinned for reproducibility.
if ! command -v ziglint >/dev/null 2>&1; then
ZIGLINT_VERSION="v0.5.2"
case "$(uname -s)" in
Darwin) zl_os="macos" ;;
Linux) zl_os="linux" ;;
*) zl_os="" ;;
esac
case "$(uname -m)" in
arm64|aarch64) zl_arch="aarch64" ;;
x86_64|amd64) zl_arch="x86_64" ;;
*) zl_arch="" ;;
esac
if [ -z "$zl_os" ] || [ -z "$zl_arch" ]; then
echo "Unknown platform $(uname -s)/$(uname -m). Install ziglint manually from https://github.com/rockorager/ziglint"
else
echo "Installing ziglint ${ZIGLINT_VERSION} (${zl_arch}-${zl_os})..."
zl_asset="ziglint-${zl_arch}-${zl_os}.tar.gz"
zl_url="https://github.com/rockorager/ziglint/releases/download/${ZIGLINT_VERSION}/${zl_asset}"
zl_tmp="$(mktemp -d)"
if curl -fsSL "$zl_url" -o "$zl_tmp/ziglint.tar.gz"; then
tar -xzf "$zl_tmp/ziglint.tar.gz" -C "$zl_tmp"
if [ -w /usr/local/bin ]; then zl_sudo=""; else zl_sudo="sudo"; fi
$zl_sudo install -m 0755 "$zl_tmp/ziglint" /usr/local/bin/ziglint
echo "ziglint installed: $(ziglint --version)"
else
echo "Failed to download ziglint from $zl_url"
fi
rm -rf "$zl_tmp"
fi
else
echo "ziglint already installed"
fi
echo "CI setup complete"