Skip to content

Commit 5a2affe

Browse files
authored
Merge pull request #6 from jakec-dev/feat/I-3-git-hooks
feat: setup pre-commit hooks
2 parents 4282785 + a494ded commit 5a2affe

File tree

4 files changed

+46
-17
lines changed

4 files changed

+46
-17
lines changed

.lefthook.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
pre-commit:
2+
parallel: true
3+
commands:
4+
golangci-lint:
5+
glob: "*.go"
6+
run: golangci-lint run --fix --fast-only {staged_files}
7+
stage_fixed: true
8+
go-mod-tidy:
9+
glob: "go.mod"
10+
run: go mod tidy && git add go.mod go.sum

CONTRIBUTING.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,26 @@ Thanks for your interest in contributing to **aws-local-sync**! This guide outli
1717
cd aws-local-sync
1818
```
1919

20-
2. **Explore available commands**
20+
2. **Install Git hooks**
21+
22+
```sh
23+
make hooks # Install pre-commit hooks via lefthook
24+
```
25+
26+
3. **Explore available commands**
2127

2228
```sh
2329
make help
2430
```
2531

26-
3. **Build and run**
32+
4. **Build and run**
2733

2834
```sh
2935
make build # Build with version info
3036
make run # Build and execute
3137
```
3238

33-
4. **Run tests and quality checks**
39+
5. **Run tests and quality checks**
3440

3541
```sh
3642
make test # Run tests with race detection and coverage
@@ -40,16 +46,28 @@ Thanks for your interest in contributing to **aws-local-sync**! This guide outli
4046

4147
## Development Workflow
4248

49+
### Git Hooks
50+
51+
This project uses [lefthook](https://github.com/evilmartians/lefthook) for Git hooks to ensure code quality:
52+
53+
- **Pre-commit hooks** automatically run:
54+
- `golangci-lint` with auto-fix for formatting issues
55+
- `go mod tidy` when go.mod changes are staged
56+
- **Manual hook execution**: `make hooks-run`
57+
- **Bypass hooks** when necessary: `git commit --no-verify`
58+
4359
### Making Changes
4460

4561
1. **Before coding**: Run `make audit` to ensure a clean baseline
46-
2. **Format code**: Automatic via golangci-lint (includes goimports)
62+
2. **Format code**: Automatic via pre-commit hooks or `make lint`
4763
3. **Test your changes**: `make test` generates coverage reports
48-
4. **Lint check**: `make lint` catches style and potential issues
49-
5. **Final audit**: `make audit` before committing
64+
4. **Lint check**: Automatic via pre-commit hooks or `make lint`
65+
5. **Final audit**: `make audit` before pushing
5066

5167
### Useful Make Targets
5268

69+
- `make hooks` - Install Git hooks
70+
- `make hooks-run` - Manually run pre-commit checks
5371
- `make tidy` - Clean up dependencies and format code
5472
- `make clean` - Remove build artifacts
5573
- `make upgradeable` - Check for dependency updates

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ tidy: ## Clean up go.mod/go.sum and format all Go source files
7575
build: ## Build the Go binary with version, commit, and build time metadata
7676
go build -trimpath -ldflags $(LDFLAGS) -o ${BUILD_DIR}/${BINARY_NAME} ${MAIN_PACKAGE}
7777

78+
.PHONY: hooks
79+
hooks: ## Install git hooks via lefthook
80+
@command -v lefthook >/dev/null 2>&1 || \
81+
(echo "Installing lefthook..." && go install github.com/evilmartians/lefthook@latest)
82+
@lefthook install
83+
@echo "Git hooks installed successfully"
84+
85+
.PHONY: hooks-run
86+
hooks-run: ## Run pre-commit hooks manually on all files
87+
@lefthook run pre-commit
88+
7889
.PHONY: build-static
7990
build-static: ## Build a statically linked binary for release (CGO disabled)
8091
CGO_ENABLED=0 go build -trimpath -ldflags $(LDFLAGS) \

cmd/aws-local-sync/main.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
package main
22

3-
import "fmt"
4-
5-
var (
6-
Version = "dev"
7-
GitCommit = "none"
8-
BuildTime = "unknown"
9-
)
10-
113
func main() {
12-
fmt.Printf("Version:\t%s\n", Version)
13-
fmt.Printf("Commit sha:\t%s\n", GitCommit)
14-
fmt.Printf("Built at:\t%s\n", BuildTime)
4+
// Placeholder
155
}

0 commit comments

Comments
 (0)