Skip to content

Commit 14df283

Browse files
committed
chore: use prek for local pre-commit workflow
1 parent 84cde70 commit 14df283

1 file changed

Lines changed: 25 additions & 34 deletions

File tree

Makefile

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Makefile for slack-rs
22

3-
.PHONY: build help install release test clean fmt lint check setup pre-commit-hooks bump-patch bump-minor bump-major index publish publish-tag
3+
.PHONY: build help install release test clean fmt lint check setup pre-commit pre-commit-hooks bump-patch bump-minor bump-major index publish publish-tag
44

55
# Default target - build debug version
66
build:
@@ -21,6 +21,7 @@ help:
2121
@echo " make check - Run fmt, lint, and test"
2222
@echo " make index - Build Serena symbol index (.serena/cache)"
2323
@echo " make setup - Setup development environment"
24+
@echo " make pre-commit - Run prek on all files"
2425
@echo " make pre-commit-hooks - Install git pre-commit hooks"
2526
@echo " make bump-patch - Bump patch version (0.1.0 -> 0.1.1) without publish"
2627
@echo " make bump-minor - Bump minor version (0.1.0 -> 0.2.0) without publish"
@@ -79,41 +80,31 @@ setup: pre-commit-hooks
7980
@command -v cargo-release >/dev/null 2>&1 || cargo install cargo-release
8081
@echo "Development environment setup complete!"
8182

83+
# Run prek checks locally (matches CI lint job)
84+
pre-commit:
85+
@set -e; \
86+
if command -v prek >/dev/null 2>&1; then PREK=prek; \
87+
elif [ -x "$$HOME/.local/bin/prek" ]; then PREK="$$HOME/.local/bin/prek"; \
88+
else \
89+
echo "prek not found. Run 'make pre-commit-hooks' to install it."; \
90+
exit 1; \
91+
fi; \
92+
"$$PREK" run --all-files
93+
8294
# Install pre-commit hooks
8395
pre-commit-hooks:
84-
@echo "Installing pre-commit hooks..."
85-
@mkdir -p .git/hooks
86-
@printf '%s\n' \
87-
'#!/bin/bash' \
88-
'set -e' \
89-
'' \
90-
'echo "Running pre-commit checks..."' \
91-
'' \
92-
'# Check formatting' \
93-
'echo "Checking code formatting..."' \
94-
'if ! cargo fmt -- --check; then' \
95-
' echo "❌ Code formatting check failed. Run '\''cargo fmt'\'' to fix."' \
96-
' exit 1' \
97-
'fi' \
98-
'' \
99-
'# Run clippy' \
100-
'echo "Running clippy..."' \
101-
'if ! cargo clippy -- -D warnings; then' \
102-
' echo "❌ Clippy check failed. Fix the warnings above."' \
103-
' exit 1' \
104-
'fi' \
105-
'' \
106-
'# Run tests' \
107-
'echo "Running tests..."' \
108-
'if ! cargo test --quiet; then' \
109-
' echo "❌ Tests failed. Fix the failing tests."' \
110-
' exit 1' \
111-
'fi' \
112-
'' \
113-
'echo "✅ All pre-commit checks passed!"' \
114-
> .git/hooks/pre-commit
115-
@chmod +x .git/hooks/pre-commit
116-
@echo "Pre-commit hooks installed successfully!"
96+
@set -e; \
97+
echo "Installing pre-commit hooks (prek)..."; \
98+
if command -v prek >/dev/null 2>&1; then PREK=prek; \
99+
elif [ -x "$$HOME/.local/bin/prek" ]; then PREK="$$HOME/.local/bin/prek"; \
100+
else \
101+
echo "prek not found. Installing to $$HOME/.local/bin..."; \
102+
mkdir -p "$$HOME/.local/bin"; \
103+
curl -LsSf https://github.com/j178/prek/releases/latest/download/prek-installer.sh | sh; \
104+
PREK="$$HOME/.local/bin/prek"; \
105+
fi; \
106+
"$$PREK" install --overwrite --hook-type pre-commit; \
107+
echo "Pre-commit hook installed. Run 'make pre-commit' to verify."
117108

118109
# Bump patch version (0.1.0 -> 0.1.1) and create git tag (no publish)
119110
bump-patch:

0 commit comments

Comments
 (0)