This repository was archived by the owner on Jun 21, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
314 lines (277 loc) · 9.08 KB
/
Copy pathTaskfile.yml
File metadata and controls
314 lines (277 loc) · 9.08 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
version: "3"
tasks:
default:
desc: List available tasks
cmds:
- task --list
build:
desc: Build detected projects and run lightweight compile checks
cmds:
- task: _go_smoke
vars:
GO_ARGS: test -run '^$' ./tests
- task: _rust
vars:
KIND: build
ARGS: check --workspace
- task: _js
vars:
KIND: build
SCRIPTS: build
- task: _python_syntax
test:
desc: Run detected project tests
cmds:
- task: _go_smoke
vars:
GO_ARGS: test ./tests
- task: _rust
vars:
KIND: test
ARGS: test --workspace
- task: _js
vars:
KIND: test
SCRIPTS: test:ci test
- task: _python
vars:
KIND: test
CMD: run pytest
lint:
desc: Run detected project linters
cmds:
- task: _go_lint
- task: _rust
vars:
KIND: lint
ARGS: fmt --all -- --check
- task: _rust
vars:
KIND: lint
ARGS: clippy --workspace --all-targets -- -D warnings
- task: _js
vars:
KIND: lint
SCRIPTS: check:lint lint check
- task: _python
vars:
KIND: lint
CMD: run ruff check .
clean:
desc: Remove common build and test artifacts
cmds:
- task: _js
vars:
KIND: clean
SCRIPTS: clean
- task: _python
vars:
KIND: clean
CMD: cache clean
- |
find . \
\( -path '*/.git' -o -path '*/node_modules' -o -path '*/.venv' \) -prune \
-o \( -name dist -o -name build -o -name coverage -o -name .turbo \
-o -name .next -o -name .react-router -o -name .vite \
-o -name .vitest -o -name .pytest_cache -o -name .ruff_cache \
-o -name .cache -o -name __pycache__ -o -name target \) -type d -print \
| while IFS= read -r path; do
rm -rf "$path"
done
_go_smoke:
internal: true
silent: true
cmds:
- |
set -eu
if find tests -name '*_test.go' -type f | grep -q .; then
cache_dir="${TMPDIR:-/tmp}/phenoproject-go-build-cache"
mkdir -p "$cache_dir"
echo "go: GO111MODULE=off GOCACHE=$cache_dir go {{.GO_ARGS}}"
GO111MODULE=off GOCACHE="$cache_dir" go {{.GO_ARGS}}
fi
_go_lint:
internal: true
silent: true
cmds:
- |
set -eu
go_files=$(find . \
\( -path '*/.git' -o -path '*/node_modules' -o -path '*/vendor' \) -prune \
-o -name '*.go' -type f -print)
if [ -z "$go_files" ]; then
exit 0
fi
unformatted=$(gofmt -l $go_files)
if [ -n "$unformatted" ]; then
echo "go: gofmt required for:"
echo "$unformatted"
exit 1
fi
echo "go: gofmt check passed"
_rust:
internal: true
silent: true
cmds:
- |
set -eu
if ! command -v cargo >/dev/null 2>&1; then
echo "{{.KIND}}: skipping Rust projects (cargo not installed)"
exit 0
fi
has_parent_cargo() {
dir=$(dirname "$(dirname "$1")")
while [ "$dir" != "." ] && [ "$dir" != "/" ]; do
if [ -f "$dir/Cargo.toml" ]; then
return 0
fi
dir=$(dirname "$dir")
done
return 1
}
find . \
-maxdepth 4 \
\( -path '*/.git' -o -path '*/node_modules' -o -path '*/target' \) -prune \
-o -name Cargo.toml -type f -print \
| sort \
| while IFS= read -r manifest; do
if has_parent_cargo "$manifest"; then
continue
fi
dir=$(dirname "$manifest")
echo "{{.KIND}}: $dir (cargo {{.ARGS}})"
(cd "$dir" && cargo {{.ARGS}})
done
_js:
internal: true
silent: true
cmds:
- |
set -eu
has_script() {
node -e 'const fs = require("fs"); const pkg = JSON.parse(fs.readFileSync(process.argv[1], "utf8")); const script = process.argv[2]; process.exit(pkg.scripts && Object.hasOwn(pkg.scripts, script) ? 0 : 1)' "$1" "$2"
}
package_manager() {
dir=$1
declared_pm=$(node -e 'const fs = require("fs"); const pkg = JSON.parse(fs.readFileSync(process.argv[1], "utf8")); const value = String(pkg.packageManager || "").split("@")[0]; if (value) console.log(value)' "$dir/package.json")
if [ -n "$declared_pm" ]; then
echo "$declared_pm"
elif [ -f "$dir/pnpm-workspace.yaml" ] || [ -f "$dir/pnpm-lock.yaml" ]; then
echo pnpm
elif [ -f "$dir/bun.lock" ] || [ -f "$dir/bun.lockb" ]; then
echo bun
elif [ -f "$dir/yarn.lock" ]; then
echo yarn
else
echo npm
fi
}
has_lockfile() {
dir=$1
[ -f "$dir/package-lock.json" ] \
|| [ -f "$dir/npm-shrinkwrap.json" ] \
|| [ -f "$dir/pnpm-lock.yaml" ] \
|| [ -f "$dir/bun.lock" ] \
|| [ -f "$dir/bun.lockb" ] \
|| [ -f "$dir/yarn.lock" ]
}
has_installed_dependencies() {
dir=$1
[ -d "$dir/node_modules" ]
}
has_parent_package() {
dir=$(dirname "$(dirname "$1")")
while [ "$dir" != "." ] && [ "$dir" != "/" ]; do
if [ -f "$dir/package.json" ]; then
return 0
fi
dir=$(dirname "$dir")
done
return 1
}
find . \
\( -path '*/.git' -o -path '*/node_modules' -o -path '*/dist' \
-o -path '*/build' -o -path '*/.turbo' -o -path '*/.next' \) -prune \
-o -name package.json -type f -print \
| sort \
| while IFS= read -r manifest; do
if has_parent_package "$manifest"; then
continue
fi
dir=$(dirname "$manifest")
pm=$(package_manager "$dir")
if ! has_lockfile "$dir" && ! has_installed_dependencies "$dir"; then
echo "{{.KIND}}: skipping $dir (no JavaScript lockfile or installed dependencies)"
continue
fi
if ! has_installed_dependencies "$dir"; then
echo "{{.KIND}}: skipping $dir (dependencies not installed)"
continue
fi
for script in {{.SCRIPTS}}; do
if has_script "$manifest" "$script"; then
echo "{{.KIND}}: $dir ($pm run $script)"
(cd "$dir" && "$pm" run "$script")
continue 2
fi
done
echo "{{.KIND}}: skipping $dir (no matching package script)"
done
_python:
internal: true
silent: true
cmds:
- |
set -eu
if ! command -v uv >/dev/null 2>&1; then
echo "{{.KIND}}: skipping Python projects (uv not installed)"
exit 0
fi
find . \
-maxdepth 3 \
\( -path '*/.git' -o -path '*/node_modules' -o -path '*/.venv' \
-o -path '*/__pycache__' -o -path '*/.pytest_cache' \) -prune \
-o -name pyproject.toml -type f -print \
| sort \
| while IFS= read -r manifest; do
dir=$(dirname "$manifest")
echo "{{.KIND}}: $dir (uv {{.CMD}})"
(cd "$dir" && uv {{.CMD}})
done
_python_syntax:
internal: true
silent: true
cmds:
- |
set -eu
if ! command -v uv >/dev/null 2>&1; then
echo "build: skipping Python projects (uv not installed)"
exit 0
fi
find . \
-maxdepth 6 \
\( -path '*/.git' -o -path '*/node_modules' -o -path '*/.venv' \
-o -path '*/__pycache__' -o -path '*/.pytest_cache' \) -prune \
-o -name pyproject.toml -type f -print \
| sort \
| while IFS= read -r manifest; do
dir=$(dirname "$manifest")
echo "build: $dir (python syntax check)"
(cd "$dir" && uv run --no-project python - <<'PY'
import ast
import pathlib
import sys
ignored = {".git", ".venv", "__pycache__", "node_modules"}
failed = False
for path in sorted(pathlib.Path(".").rglob("*.py")):
if any(part in ignored for part in path.parts):
continue
try:
ast.parse(path.read_text(encoding="utf-8"), filename=str(path))
except SyntaxError as exc:
failed = True
print(f"{path}:{exc.lineno}:{exc.offset}: {exc.msg}", file=sys.stderr)
raise SystemExit(1 if failed else 0)
PY
)
done