-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjustfile
More file actions
412 lines (357 loc) · 11.9 KB
/
Copy pathjustfile
File metadata and controls
412 lines (357 loc) · 11.9 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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
# Development workflow automation
# Show workflow cheat sheet
default:
@echo "=== Development Workflow ==="
@echo ""
@echo "📝 Starting work:"
@echo " just feature <name> → Start new feature branch (from dev)"
@echo " just bugfix <name> → Start new bugfix branch (from dev)"
@echo " just refactor <name> → Start refactor branch (from dev)"
@echo " just chore <name> → Start maintenance branch (from dev)"
@echo " just docs <name> → Start docs-only branch (from dev)"
@echo " just hotfix <name> → Start urgent fix branch (from main!)"
@echo ""
@echo "🔍 Before pushing:"
@echo " just pre-push → Run fmt, clippy, tests"
@echo " just lint → Just format + clippy"
@echo " just test → Just run tests"
@echo ""
@echo "🔀 Finishing work:"
@echo " just merge-to-dev → Merge current branch to dev + tag it (local)"
@echo " just pr → Create PR to dev (auto-tags on merge)"
@echo ""
@echo "🚀 Release cycle:"
@echo " just freeze <reason> → Lock tree for release (bugfixes only)"
@echo " just thaw → Unlock tree for features again"
@echo " just changelog → Regenerate CHANGELOG.md (requires git-cliff)"
@echo " just release 0.x.y → Squash dev→main, run tests, tag release"
@echo " just push-release 0.x.y → Push release to github"
@echo " just update-deps → Update dependencies post-release"
@echo ""
@echo "🔎 Archaeology:"
@echo " just list-features → Show all feature/bugfix tags"
@echo " just show-feature <name> → What did this feature change?"
@echo " just blame <file> → Per-commit attribution"
@echo " just history <file> → Full change history"
@echo ""
@echo "📚 Documentation:"
@echo " just rustdoc → Build & open docs locally"
@echo ""
@echo "🛠️ Utility:"
@echo " just clean → Remove build artifacts"
@echo " just rebuild → Clean + rebuild release"
@echo ""
@echo "Run 'just --list' to see all available commands"
# List all available commands
list:
@just --list
# === Tree Freeze (Release Discipline) ===
# Lock the tree for release preparation (bugfixes only)
freeze reason:
#!/usr/bin/env bash
set -e
if [ -f .freeze ]; then
echo "⚠️ Tree is already frozen:"
cat .freeze
exit 1
fi
echo "{{reason}}" > .freeze
echo "frozen: $(date -Iseconds)" >> .freeze
git add .freeze
echo "🧊 Tree frozen: {{reason}}"
echo " Use 'just push-bugfix' for bugfix commits"
echo " Use 'just thaw' when ready to unfreeze"
# Unlock the tree for normal development
thaw:
#!/usr/bin/env bash
set -e
if [ ! -f .freeze ]; then
echo "Tree isn't frozen, nothing to thaw~"
exit 0
fi
rm -f .freeze
git add .freeze 2>/dev/null || true
echo "🌸 Tree unfrozen, features welcome again~"
# Check if tree is frozen (used by pre-push)
check-freeze:
#!/usr/bin/env bash
if [ -f .freeze ]; then
echo ""
echo "⚠️ TREE IS FROZEN ⚠️"
echo "$(head -1 .freeze)"
echo ""
echo "Options:"
echo " • If this is a bugfix: just push-bugfix"
echo " • To unfreeze: just thaw"
echo ""
exit 1
fi
# Push during freeze (confirms this is a bugfix)
push-bugfix: _frozen-guard lint test
#!/usr/bin/env bash
set -e
BRANCH=$(git branch --show-current)
echo "🐛 Pushing bugfix on $BRANCH during freeze..."
git push
# Internal: ensure tree IS frozen (for push-bugfix)
_frozen-guard:
#!/usr/bin/env bash
if [ ! -f .freeze ]; then
echo "Tree isn't frozen — just use regular 'git push' or 'just pre-push'"
exit 1
fi
# === Development Commands ===
# Start a new feature branch from dev
feature name: check-freeze
#!/usr/bin/env bash
set -e
git checkout dev
git pull
git checkout -b "feature/{{name}}"
echo "✓ Created and switched to feature/{{name}}"
# Start a new bugfix branch from dev
bugfix name:
#!/usr/bin/env bash
set -e
git checkout dev
git pull
git checkout -b "bugfix/{{name}}"
echo "✓ Created and switched to bugfix/{{name}}"
# Start a new refactor branch from dev
refactor name: check-freeze
#!/usr/bin/env bash
set -e
git checkout dev
git pull
git checkout -b "refactor/{{name}}"
echo "✓ Created and switched to refactor/{{name}}"
# Start a new chore branch from dev
chore name: check-freeze
#!/usr/bin/env bash
set -e
git checkout dev
git pull
git checkout -b "chore/{{name}}"
echo "✓ Created and switched to chore/{{name}}"
# Start a new docs branch from dev
docs name:
#!/usr/bin/env bash
set -e
git checkout dev
git pull
git checkout -b "docs/{{name}}"
echo "✓ Created and switched to docs/{{name}}"
# Start a new hotfix branch from main (for urgent production fixes)
hotfix name:
#!/usr/bin/env bash
set -e
git checkout main
git pull
git checkout -b "hotfix/{{name}}"
echo "✓ Created and switched to hotfix/{{name}}"
echo "⚠️ This branch is from main, not dev!"
echo " After merging to main, sync back to dev with: git checkout dev && git merge main"
# Merge current branch into dev and tag it (local merge, for quick changes)
merge-to-dev: _merge-freeze-check
#!/usr/bin/env bash
set -e
BRANCH=$(git branch --show-current)
if [ "$BRANCH" = "dev" ] || [ "$BRANCH" = "main" ]; then
echo "Error: Cannot merge dev or main into itself"
exit 1
fi
git checkout dev
git pull
git merge --no-ff "$BRANCH" -m "Merge branch '$BRANCH' into dev"
git tag "$BRANCH"
echo "✓ Merged $BRANCH into dev and tagged as $BRANCH"
echo " Branch $BRANCH is now preserved as a tag"
echo " You can delete the branch with: git branch -d $BRANCH"
# Internal: check freeze status for merge (allows bugfix/* and docs/*)
_merge-freeze-check:
#!/usr/bin/env bash
if [ -f .freeze ]; then
BRANCH=$(git branch --show-current)
if [[ "$BRANCH" == bugfix/* ]] || [[ "$BRANCH" == docs/* ]] || [[ "$BRANCH" == hotfix/* ]]; then
echo "🐛 Merging $BRANCH during freeze (allowed)"
else
echo ""
echo "⚠️ TREE IS FROZEN ⚠️"
echo "$(head -1 .freeze)"
echo ""
echo "Only bugfix/*, docs/*, and hotfix/* branches can be merged during freeze."
echo "To unfreeze: just thaw"
echo ""
exit 1
fi
fi
# Create a pull request to dev (auto-tags on merge via GitHub Actions)
pr: _merge-freeze-check
#!/usr/bin/env bash
set -e
BRANCH=$(git branch --show-current)
if [ "$BRANCH" = "dev" ] || [ "$BRANCH" = "main" ]; then
echo "Error: Cannot create PR from dev or main"
exit 1
fi
# Push branch if not already pushed
git push -u origin "$BRANCH" 2>/dev/null || git push origin "$BRANCH"
# Create PR
gh pr create --base dev --fill
echo "✓ PR created to dev"
echo " When merged, GitHub Actions will automatically tag it as $BRANCH"
# === Linting & Testing ===
# Run formatting and clippy checks
lint:
cargo fmt
cargo clippy --all-targets --locked -- -D warnings
# Check formatting and clippy without modifying files
check:
cargo fmt --check
cargo clippy --all-targets --locked -- -D warnings
# Run all tests
test:
cargo nextest run --all-targets --locked
# Full pre-push check (format, clippy, tests)
pre-push: check-freeze lint test
@echo "✓ All checks passed, ready to push"
# Push with freeze check and all validations
push: pre-push
git push
# Install all binary crates to ~/.cargo/bin
install:
#!/usr/bin/env bash
set -e
BINS=$(cargo metadata --format-version=1 --no-deps 2>/dev/null \
| jq -r '
.workspace_root as $root |
[.packages[] | select(any(.targets[]; .kind[] == "bin")) | .manifest_path] |
unique | .[] |
if . == ($root + "/Cargo.toml") then "."
else (ltrimstr($root + "/") | rtrimstr("/Cargo.toml"))
end')
if [ -z "$BINS" ]; then
echo "❌ No binary crates found"
exit 1
fi
for crate in $BINS; do
echo "Installing ${crate}..."
cargo install --path "$crate"
done
# === Documentation ===
# Regenerate the hook reference section in docs/hooks.md from HOOK_METADATA.
# Must be run after changing HOOK_METADATA in hooks.rs.
# The test `test_hooks_docs_markdown_freshness` fails if docs/hooks.md is stale.
generate-docs:
cargo test -p chibi-core --test generate_docs -- --nocapture
# Build and open documentation locally
rustdoc:
cargo doc --no-deps --open
# Build documentation for all dependencies (slower)
rustdoc-all:
cargo doc --open
# === Release Cycle Commands ===
# Normalize version input: strip leading 'v' if present, validate semver-ish format.
# Sets VER (bare: "0.7.1") and TAG (prefixed: "v0.7.1").
# Accepts "v0.7.1", "0.7.1", or "v0.7.1-rc.1" etc.
[private]
@_parse-version version:
echo "{{version}}" | sed 's/^v//' | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+' \
|| (echo "❌ Invalid version '{{version}}'. Expected semver, e.g. 0.7.1 or v0.7.1" && exit 1)
# Regenerate CHANGELOG.md from git history (requires git-cliff)
changelog:
git-cliff --output CHANGELOG.md
# Lock the tree for release (squash-merge dev to main, tag release)
release version: (_parse-version version)
#!/usr/bin/env bash
set -e
VER="$(echo "{{version}}" | sed 's/^v//')"
TAG="v${VER}"
echo "Preparing release ${TAG}..."
# Ensure we're on dev and up to date
git checkout dev
git pull
# Run full checks before release
echo "Running pre-release checks..."
cargo fmt --check || (echo "❌ Code needs formatting. Run 'just lint' first." && exit 1)
cargo clippy --all-targets --locked -- -D warnings || (echo "❌ Clippy errors found." && exit 1)
cargo nextest run --all-targets --locked || (echo "❌ Tests failed." && exit 1)
# Tag dev HEAD so git-cliff can generate the changelog correctly
git tag "${TAG}" HEAD
# Generate changelog with the new version tag
git-cliff --output CHANGELOG.md
git add CHANGELOG.md
git commit -m "docs: update CHANGELOG for ${TAG}"
# Create release commit on main with dev's tree (no merge conflicts, no history leak)
git checkout main
git pull
RELEASE_COMMIT=$(git commit-tree dev^{tree} -p HEAD -m "Release ${TAG}")
git reset --hard "$RELEASE_COMMIT"
# Tag main too (annotated, for GitHub releases)
git tag -a "${TAG}" -m "Release ${TAG}" -f
echo "✓ Release ${TAG} prepared on main"
echo " Review with: git show HEAD"
echo " Push with: just push-release ${VER}"
# Push a release to remote (after review)
push-release version: (_parse-version version)
#!/usr/bin/env bash
set -e
VER="$(echo "{{version}}" | sed 's/^v//')"
TAG="v${VER}"
git checkout main
git push origin main
git push origin "${TAG}"
# Return to dev
git checkout dev
echo "✓ Released ${TAG}"
# Update dependencies after release
update-deps:
#!/usr/bin/env bash
set -e
git checkout dev
git pull
echo "Updating dependencies..."
cargo update
cargo build
cargo test
git add Cargo.lock
git commit -m "chore: update dependencies post-release"
git push origin dev
echo "✓ Dependencies updated on dev"
# === Archaeology Commands ===
# Show what a specific feature changed
show-feature name:
#!/usr/bin/env bash
set -e
git checkout dev
if ! git rev-parse "feature/{{name}}" >/dev/null 2>&1; then
echo "Error: Tag feature/{{name}} not found"
exit 1
fi
echo "=== Feature: feature/{{name}} ==="
git show "feature/{{name}}"
echo ""
echo "=== All commits in this feature ==="
git log "feature/{{name}}^..feature/{{name}}" --oneline
# Show what changed in a file, with per-commit attribution
blame file:
git checkout dev
git blame "{{file}}"
# Show full history of changes to a file
history file:
git checkout dev
git log -p "{{file}}"
# List all feature tags
list-features:
@echo "=== Feature tags ==="
@git tag -l 'feature/*'
@echo ""
@echo "=== Bugfix tags ==="
@git tag -l 'bugfix/*'
# === Utility Commands ===
# Clean build artifacts
clean:
cargo clean
# Full clean rebuild
rebuild: clean
cargo build --release