Repository navigation
Expand file tree
/
Copy pathTaskfile.yaml
More file actions
394 lines (365 loc) · 15.2 KB
/
Copy pathTaskfile.yaml
File metadata and controls
394 lines (365 loc) · 15.2 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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
version: "3"
set: [errexit, nounset, pipefail]
silent: true
vars:
TYPOS_VERSION: '{{.TYPOS_VERSION | default "1.45.1"}}'
# Scanner images: docker resolves the digest and ignores the tag, which is kept for readers.
GITLEAKS_IMAGE: ghcr.io/gitleaks/gitleaks:v8.30.1@sha256:c00b6bd0aeb3071cbcb79009cb16a60dd9e0a7c60e2be9ab65d25e6bc8abbb7f
OSV_SCANNER_IMAGE: ghcr.io/google/osv-scanner:v2.7.0@sha256:4f3b7e2c64b9d38a5febc5a7e4a3dfef1d1362f726dea7a2ef4762b46469fcd0
tasks:
default:
cmd: task --list --sort alphanumeric
stats:
desc: Show lines added and removed by all authors' commits on the current branch today, over the last 7, 28, and 365 calendar days (each window includes today), and over the whole history, with the average per calendar day
cmds:
- |
TODAY_START="$(git rev-parse --since='0 days ago 00:00' | sed 's/^--max-age=//')"
FIRST_DAY="$(git log --format='%ct %cd' --date=format-local:%Y-%m-%d | sort -n | awk 'NR == 1 { print $2 }')"
FIRST_DAY_START="$(git rev-parse --since="$FIRST_DAY 00:00" | sed 's/^--max-age=//')"
# Rounding absorbs the hour a daylight-saving switch adds to or removes from a day.
ALL_DAYS=$(( (TODAY_START - FIRST_DAY_START + 43200) / 86400 + 1 ))
echo "Lines added and removed by the commits on $(git rev-parse --abbrev-ref HEAD) since $FIRST_DAY, all authors (merge commits and binary files not counted)"
printf '%-7s %5s %9s %9s %9s %10s %12s\n' window days added removed net added/day removed/day
for WINDOW in 1 7 28 365 all; do
case "$WINDOW" in
1) LABEL=today DAYS=1 ;;
all) LABEL=all DAYS="$ALL_DAYS" ;;
*) LABEL="${WINDOW}d" DAYS="$WINDOW" ;;
esac
git log --since="$((DAYS - 1)) days ago 00:00" --numstat --pretty=tformat: \
| awk -v label="$LABEL" -v days="$DAYS" '$1 != "-" { added += $1; removed += $2 }
END { printf "%-7s %5d %9d %9d %9d %10.1f %12.1f\n", label, days, added, removed, added - removed, added / days, removed / days }'
done
echo "OK: stats complete"
run:
desc: "Run a command inside the project environment (usage: task run -- python ...)"
cmd: uv run {{.CLI_ARGS}}
setup:
desc: Create or reuse the local Python environment and install repo tooling
cmds:
- uv venv --allow-existing --python 3.13.3
- uv sync --all-groups --extra notebooks
- uv run python -m ipykernel install --user --name joint-client-python --display-name "Python (joint-client-python)"
- uv run pre-commit install --hook-type pre-commit --hook-type commit-msg
- task: install:ripgrep
- task: install:typos
- cmd: |
if [ -f .env ]; then
echo ".env already exists; leaving it untouched"
else
cp .env.sample .env
echo "Created .env from .env.sample"
fi
- cmd: 'echo "Activate virtual environment with: . .venv/bin/activate"'
lint:
desc: Run Ruff lint checks
cmd: uv run ruff check .
license-check:
desc: Verify every Python source file has the required copyright/SPDX header
cmd: docker run --rm -v "$PWD:/src" --workdir /src apache/skywalking-eyes:0.8.0 -c .licenserc.yaml header check
format:
desc: Run Ruff formatter (rewrites files in place)
cmd: uv run ruff format .
typecheck:
desc: Run ty static type checks
cmd: uv run ty check --output-format concise --error-on-warning
leak-guard:
desc: Fail when a tracked or untracked, non-ignored file carries private material in its path or content
cmd: |
if uv run python scripts/leak_guard.py tree; then
echo "OK: leak guard found no private material in the working tree"
else
echo "FAIL: leak guard found private material in the working tree"
exit 1
fi
leak-guard:history:
desc: "Fail when a commit carries private material in its message, paths, or file contents; scans every ref unless given revisions (task leak-guard:history -- origin/main..HEAD)"
cmd: |
if uv run python scripts/leak_guard.py history {{.CLI_ARGS}}; then
echo "OK: leak guard found no private material in the scanned history"
else
echo "FAIL: leak guard found private material in the scanned history"
exit 1
fi
secret-scan:
desc: Fail when gitleaks finds a credential in any commit of the git history (needs docker)
cmd: |
if docker run --rm -v "$PWD:/repo" {{.GITLEAKS_IMAGE}} git /repo --redact --no-banner; then
echo "OK: gitleaks found no credentials in the git history"
else
echo "FAIL: gitleaks found credentials in the git history"
exit 1
fi
secret-scan:staged:
desc: Fail when gitleaks finds a credential in the staged changes (needs docker)
cmd: |
if docker run --rm -v "$PWD:/repo" {{.GITLEAKS_IMAGE}} git /repo --pre-commit --staged --redact --no-banner; then
echo "OK: gitleaks found no credentials in the staged changes"
else
echo "FAIL: gitleaks found credentials in the staged changes"
exit 1
fi
vuln-scan:
desc: Fail when a package pinned in uv.lock has a known vulnerability (needs docker)
cmd: |
if docker run --rm -v "$PWD:/src" {{.OSV_SCANNER_IMAGE}} scan source --config /src/osv-scanner.toml --lockfile /src/uv.lock; then
echo "OK: osv-scanner found no known vulnerabilities in uv.lock"
else
echo "FAIL: osv-scanner found known vulnerabilities in uv.lock"
exit 1
fi
test:
desc: Run the unit test suite
cmd: uv run pytest -n auto
max-utilization:
desc: Send the largest advertised forecast to the configured deployment and print a PASS/FAIL verdict
cmd: uv run jointfm-client max-utilization {{.CLI_ARGS}}
coverage:
desc: Run tests with coverage enforcement
cmd: uv run pytest -n auto --cov=jointfm_client --cov-report=term-missing --cov-fail-under=90
build:
desc: Build and validate the source distribution and wheel
cmds:
- uv build
- uv run python scripts/validate_distribution.py
check:
desc: Run static code quality checks (read-only; no file modifications)
cmds:
- task: typos
- task: lint
- uv run ruff format --check .
- task: typecheck
release:require-tag:
desc: Fail fast if Commitizen has no base tag to bump from
cmd: |
EXPECTED="v$(uv run cz version --project)"
if git rev-parse -q --verify "refs/tags/$EXPECTED" >/dev/null; then
echo "OK: base tag $EXPECTED found"
exit 0
fi
echo "FAIL: base tag $EXPECTED does not exist."
echo "Commitizen needs an annotated tag matching the current pyproject version"
echo "to compute the next bump. Seed it once with:"
echo
echo " git tag -a $EXPECTED -m 'Seed initial release tag for Commitizen'"
echo " git push --tags"
echo
echo "Then rerun this task."
exit 1
release:dry:
desc: Preview the next SemVer bump (no commit, no tag, no file changes)
cmds:
- task: release:require-tag
- |
uv run cz bump --dry-run --yes --allow-no-commit {{.CLI_ARGS}}
echo "OK: dry-run succeeded (no files modified)"
release:check:
desc: Verify the working tree is ready to cut a release
cmds:
- task: release:require-tag
- |
echo "[1/4] checking working tree is clean..."
if [ -n "$(git status --porcelain)" ]; then
echo "FAIL: working tree has uncommitted changes; commit or stash first"
exit 1
fi
echo "[2/4] checking current branch is main..."
BRANCH="$(git symbolic-ref --short HEAD)"
if [ "$BRANCH" != "main" ]; then
echo "FAIL: cz bump must run on main (currently on $BRANCH)"
exit 1
fi
echo "[3/4] fetching origin/main and checking alignment..."
git fetch --quiet origin main
if [ "$(git rev-parse HEAD)" != "$(git rev-parse origin/main)" ]; then
echo "FAIL: local main is not aligned with origin/main; pull/push first"
exit 1
fi
# --allow-no-commit would otherwise re-release an unchanged tree under a new version.
BASE_TAG="v$(uv run cz version --project)"
echo "[4/4] checking main has commits since $BASE_TAG..."
if [ "$(git rev-list --count "$BASE_TAG..HEAD")" -eq 0 ]; then
echo "FAIL: no commits since $BASE_TAG; nothing to release"
exit 1
fi
echo "OK: release pre-flight passed"
release:
desc: Cut a SemVer release with Commitizen (writes CHANGELOG, bumps versions, tags)
cmds:
- task: release:check
- |
PREV="$(uv run cz version --project)"
echo "bumping version with Commitizen (writing files, tagging)..."
uv run cz bump --yes --allow-no-commit {{.CLI_ARGS}}
NEXT="$(uv run cz version --project)"
echo
echo "OK: released v$PREV -> v$NEXT"
echo " bumped version in: pyproject.toml, README.md"
echo " updated: CHANGELOG.md, uv.lock"
echo " created tag: v$NEXT"
echo " publish with: task release:publish"
release:publish:
desc: Push the release commit and its tag to origin (triggers the PyPI publish workflow)
cmds:
- task: release:require-tag
- |
TAG="v$(uv run cz version --project)"
echo "[1/5] checking working tree is clean..."
if [ -n "$(git status --porcelain)" ]; then
echo "FAIL: working tree has uncommitted changes; commit them first"
exit 1
fi
echo "[2/5] checking current branch is main..."
BRANCH="$(git symbolic-ref --short HEAD)"
if [ "$BRANCH" != "main" ]; then
echo "FAIL: releases are published from main (currently on $BRANCH)"
exit 1
fi
echo "[3/5] checking $TAG points at HEAD..."
if [ "$(git rev-parse "$TAG^{commit}")" != "$(git rev-parse HEAD)" ]; then
echo "FAIL: $TAG does not point at HEAD."
echo "The wheel published from this tag must match the commit on main."
echo "This usually means the release PR was squashed or rebased instead"
echo "of merged, so the tagged commit is no longer part of main."
exit 1
fi
echo "[4/5] checking $TAG is not already published..."
git fetch --quiet origin main
if [ -n "$(git ls-remote --tags origin "refs/tags/$TAG")" ]; then
echo "FAIL: origin already has $TAG; PyPI does not allow reusing a version."
echo "Cut a new release instead of republishing this one."
exit 1
fi
echo "[5/5] commits to be pushed to origin/main:"
git --no-pager log --oneline origin/main..HEAD
echo
if [ -t 0 ]; then
printf 'Push main and %s to origin? This publishes %s to PyPI. [y/N] ' "$TAG" "$TAG"
read -r CONFIRMATION
case "$CONFIRMATION" in
y|Y|yes|YES) ;;
*)
echo "OK: aborted, nothing was pushed"
exit 1
;;
esac
fi
git push origin main
git push origin "refs/tags/$TAG"
echo
echo "OK: pushed main and $TAG to origin"
echo " the Publish to PyPI workflow now builds and uploads $TAG"
typos:
desc: Run the spelling checker
cmds:
- task: install:typos
- typos --config typos.toml --force-exclude --sort .
pre-commit:
desc: Run pre-commit hooks on all files
cmd: uv run pre-commit run --all-files
install:ripgrep:
desc: Install ripgrep using the available system package manager
cmds:
- |
if command -v rg >/dev/null 2>&1; then
exit 0
fi
if command -v apt >/dev/null 2>&1; then
sudo apt update && sudo apt install -y ripgrep
elif command -v dnf >/dev/null 2>&1; then
rpm -q spal-release >/dev/null 2>&1 || sudo dnf install -y spal-release
sudo dnf install -y ripgrep
elif command -v yum >/dev/null 2>&1; then
sudo yum install -y ripgrep
elif command -v pacman >/dev/null 2>&1; then
sudo pacman -Sy --noconfirm ripgrep
elif command -v brew >/dev/null 2>&1; then
brew install ripgrep
else
echo "No supported package manager found for automatic ripgrep installation."
echo "Install ripgrep manually, then rerun: task setup"
exit 1
fi
install:typos:
desc: Install typos using Homebrew when available, otherwise download a release binary with curl
cmds:
- |
LOCAL_TYPOS="$HOME/.local/bin/typos"
if command -v typos >/dev/null 2>&1; then
echo "typos already installed: $(command -v typos)"
exit 0
fi
if [ -x "$LOCAL_TYPOS" ]; then
echo "typos already installed: $LOCAL_TYPOS"
exit 0
fi
if command -v brew >/dev/null 2>&1; then
if brew list typos-cli >/dev/null 2>&1 || brew install typos-cli; then
if command -v typos >/dev/null 2>&1; then
echo "Installed typos via Homebrew: $(command -v typos)"
exit 0
fi
fi
fi
if ! command -v curl >/dev/null 2>&1; then
echo "curl is required to download typos automatically."
echo "Install curl or typos manually, then rerun: task setup"
exit 1
fi
if ! command -v tar >/dev/null 2>&1; then
echo "tar is required to unpack the typos release archive."
echo "Install tar or typos manually, then rerun: task setup"
exit 1
fi
if ! command -v install >/dev/null 2>&1; then
echo "install is required to place the typos binary."
echo "Install coreutils or typos manually, then rerun: task setup"
exit 1
fi
VERSION="{{.TYPOS_VERSION}}"
ARCH="$(uname -m)"
case "$ARCH" in
x86_64|amd64)
ARCH="x86_64"
;;
arm64|aarch64)
ARCH="aarch64"
;;
*)
echo "Unsupported typos architecture: $ARCH"
exit 1
;;
esac
OS_NAME="$(uname -s)"
case "$OS_NAME" in
Darwin)
TARGET="$ARCH-apple-darwin"
ARCHIVE_EXT="tar.gz"
;;
Linux)
TARGET="$ARCH-unknown-linux-musl"
ARCHIVE_EXT="tar.gz"
;;
*)
echo "Unsupported typos operating system: $OS_NAME"
echo "This setup supports Ubuntu, AWS Linux, and macOS only."
exit 1
;;
esac
ARCHIVE_NAME="typos-v${VERSION}-${TARGET}.${ARCHIVE_EXT}"
DOWNLOAD_URL="https://github.com/crate-ci/typos/releases/download/v${VERSION}/${ARCHIVE_NAME}"
INSTALL_DIR="$HOME/.local/bin"
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT
curl -fsSL "$DOWNLOAD_URL" -o "$TMP_DIR/$ARCHIVE_NAME"
mkdir -p "$INSTALL_DIR"
tar -xzf "$TMP_DIR/$ARCHIVE_NAME" -C "$TMP_DIR"
install "$TMP_DIR/typos" "$INSTALL_DIR/typos"
echo "Installed typos to $INSTALL_DIR/typos"
case ":$PATH:" in
*":$INSTALL_DIR:"*)
;;
*)
echo "Add $INSTALL_DIR to PATH if you want to invoke typos directly in new shells."
;;
esac