-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
59 lines (47 loc) · 2.43 KB
/
Makefile
File metadata and controls
59 lines (47 loc) · 2.43 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
start:
@go run ./cmd/main.go
clean-modules:
@echo "clean unused module in go.mod and go.sum"
@go mod tidy
air-windows:
@air -c .air.win.toml
air-unix:
@~/go/bin/air -c .air.unix.toml
pre-commit:
@echo "Checking staged Go files..."
@STAGED_GO_FILES=$$(git diff --cached --name-only --diff-filter=ACM | grep '\.go$$' || true); \
if [ -n "$$STAGED_GO_FILES" ]; then \
echo "Running go fmt on staged files..."; \
UNFORMATTED=$$(gofmt -l $$STAGED_GO_FILES); \
if [ -n "$$UNFORMATTED" ]; then \
echo "[FAIL] The following staged Go files are not properly formatted:"; \
echo "$$UNFORMATTED"; \
exit 1; \
else \
echo "[SUCCESS] All staged Go files are properly formatted."; \
fi \
else \
echo "No staged Go files to check."; \
fi
@echo "Running go vet..."
@go vet ./... || (echo "[FAIL] go vet failed." && exit 1)
@echo "Run golangci-lint run..."
@~/go/bin/golangci-lint run --timeout=5m
# build docker image first to be tested later
@echo "build user-service:test image"
@chmod +x ./bin/build-precommit-test.sh
@./bin/build-precommit-test.sh
@echo "Running go test (unit testing)..."
@go test ./test/ut/... -v || (echo "[FAIL] Unit testing failed." && exit 1)
@echo "Running go test (integration testing)..."
@go test ./test/it/... -v || (echo "[FAIL] Integration testing failed." && exit 1)
@echo "[SUCCESS] Pre-commit checks passed!"
# remove docker images for the service cause latest is not updating automatically. force to always pulling
@echo "Removing services image"
@if docker images docker-registry.anandadf.my.id/micros-template/auth-service:latest | awk 'NR>1 {print $1}' | grep -q .; then docker rmi docker-registry.anandadf.my.id/micros-template/auth-service:latest; fi
@if docker images docker-registry.anandadf.my.id/micros-template/user-service:test | awk 'NR>1 {print $1}' | grep -q .; then docker rmi docker-registry.anandadf.my.id/micros-template/user-service:test; fi
@if docker images docker-registry.anandadf.my.id/micros-template/file-service:latest | awk 'NR>1 {print $1}' | grep -q .; then docker rmi docker-registry.anandadf.my.id/micros-template/file-service:latest; fi
@if docker images docker-registry.anandadf.my.id/micros-template/notification-service:latest | awk 'NR>1 {print $1}' | grep -q .; then docker rmi docker-registry.anandadf.my.id/micros-template/notification-service:latest; fi
pre-commit-preparation:
@cp ./bin/pre-commit ./.git/hooks/pre-commit
@chmod +x ./.git/hooks/pre-commit