-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
74 lines (59 loc) · 2.42 KB
/
Makefile
File metadata and controls
74 lines (59 loc) · 2.42 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
# /Makefile
PKG ?= ./...
COVER ?= .build/coverage.out
MINCOV ?= 95
GO ?= go
OSARCHES ?= linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64
.PHONY: init tidy fmt strip lint vet test test-race fuzz cover build clean
init: ## download and verify modules
@$(GO) mod download
@$(GO) mod verify
@$(GO) version
@if command -v terraform >/dev/null 2>&1; then \
terraform version; \
fi
@$(GO) run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1 version
tidy: ## tidy modules
@$(GO) mod tidy -v
fmt: ## format code and regenerate test fixtures
@$(GO) run mvdan.cc/gofumpt@v0.8.0 -l -w .
@if command -v terraform >/dev/null 2>&1; then \
terraform fmt -recursive tests/cases; \
else \
echo "terraform not found; skipping terraform fmt"; \
fi
@find tests/cases -name in.tf -print0 | \
xargs -0 -n1 -I{} sh -c 'dir=$$(dirname {}); $(GO) run ./cmd/hclalign --stdin --stdout < {} > $$dir/fmt.tf; $(GO) run ./cmd/hclalign --stdin --stdout --all < {} > $$dir/aligned.tf'
strip: ## normalize Go file comments and enforce policy
@$(GO) run ./tools/strip --repo-root .
@$(GO) run ./cmd/commentcheck
@git diff --exit-code
lint: ## run linters
@$(GO) run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1 run --timeout=5m
vet: ## vet code
@$(GO) vet $(PKG)
test: ## run tests with race detector and coverage gate
@mkdir -p $(dir $(COVER))
@$(GO) test -race -shuffle=on -cover -coverprofile=$(COVER) $(PKG)
@$(GO) tool cover -func=$(COVER) | $(GO) run ./tools/covercheck $(MINCOV)
test-race: test ## legacy alias
fuzz: ## run fuzz tests
@$(GO) test ./... -run=^$ -fuzz=Fuzz -fuzztime=5s
@$(GO) test -run=^$$ -fuzz=Fuzz -fuzztime=10s ./internal/align
@$(GO) test -run=^$$ -fuzz=Fuzz -fuzztime=10s ./internal/engine
@$(GO) test -run=^$$ -fuzz=Fuzz -fuzztime=10s ./internal/hcl
cover: ## run coverage check
@mkdir -p $(dir $(COVER))
@$(GO) test -shuffle=on -covermode=atomic -coverpkg=./... -coverprofile=$(COVER) ./...
@$(GO) tool cover -func=$(COVER) | $(GO) run ./tools/covercheck $(MINCOV)
build: ## build binaries
@for target in $(OSARCHES); do \
os=$${target%/*}; arch=$${target#*/}; \
out=.build/$${os}-$${arch}; \
ext=""; [ $$os = windows ] && ext=.exe; \
echo "building $$os/$$arch"; \
mkdir -p $$out; \
CGO_ENABLED=0 GOOS=$$os GOARCH=$$arch $(GO) build -trimpath -ldflags="-s -w" -buildvcs=false -o $$out/hclalign$$ext ./cmd/hclalign; \
done
clean: ## remove build artifacts
@rm -rf .build $(COVER)