forked from SchwarzIT/go-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
107 lines (78 loc) · 3.01 KB
/
Makefile
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
SHELL=/bin/bash -e -o pipefail
PWD = $(shell pwd)
# constants
GOLANGCI_VERSION = 1.48.0
all: git-hooks generate ## Initializes all tools and files
out:
@mkdir -pv "$(@)"
test-build: ## Tests whether the code compiles
@go build -o /dev/null ./...
build: out/bin ## Builds all binaries
GO_BUILD = mkdir -pv "$(@)" && go build -ldflags="-w -s" -o "$(@)" ./...
.PHONY: out/bin
out/bin:
$(GO_BUILD)
git-hooks:
@git config --local core.hooksPath .githooks/
download: ## Downloads the dependencies
@go mod download
fmt: ## Formats all code with go fmt
@go fmt ./...
run: fmt ## Run a controller from your host
@go run ./main.go
generate: ## Generates files
@go run cmd/dotembed/main.go -target _template -o embed_gen.go -pkg gotemplate -var FS
@go run cmd/options2md/main.go -o docs/options.md
@go run github.com/nix-community/gomod2nix@latest --outdir nix
GOLANGCI_LINT = bin/golangci-lint-$(GOLANGCI_VERSION)
$(GOLANGCI_LINT):
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- -b bin v$(GOLANGCI_VERSION)
@mv bin/golangci-lint "$(@)"
lint: fmt $(GOLANGCI_LINT) download ## Lints all code with golangci-lint
@$(GOLANGCI_LINT) run
lint-reports: out/lint.xml
.PHONY: out/lint.xml
out/lint.xml: $(GOLANGCI_LINT) out download
$(GOLANGCI_LINT) run ./... --out-format checkstyle | tee "$(@)"
test: ## Runs all tests
@go test ./...
coverage: out/report.json ## Displays coverage per func on cli
go tool cover -func=out/cover.out
html-coverage: out/report.json ## Displays the coverage results in the browser
go tool cover -html=out/cover.out
test-reports: out/report.json
.PHONY: out/report.json
out/report.json: out
go test ./... -coverprofile=out/cover.out --json | tee "$(@)"
clean-test-project: ## Removes test-project
@rm -rf testing-project
clean: clean-test-project ## Cleans up everything
@rm -rf bin out
ci: lint-reports test-reports
.PHONY: testing-project
testing-project: clean-test-project ## Creates a testing-project from the template
@go run cmd/gt/*.go new -c $$VALUES_FILE
.PHONY: testing-project-ci-single
testing-project-ci-single: ## Creates a testing-project from the template and run make ci within it
@make testing-project VALUES_FILE=$$VALUES_FILE
@make -C testing-project ci
@make -C testing-project all
.PHONY: testing-project-default
testing-project-default: ## Creates the default testing-project from the template
@make testing-project VALUES_FILE=pkg/gotemplate/testdata/values.yml
.PHONY: testing-project-ci
testing-project-ci: ## Creates for all yml files in ./test_project_values a test project and run `make ci`
for VALUES in ./test_project_values/*.yml; do \
make testing-project-ci-single VALUES_FILE=$$VALUES; \
done
.PHONY: release
release: ## Create a new release version
@./hack/release.sh
help:
@echo 'Usage: make <OPTIONS> ... <TARGETS>'
@echo ''
@echo 'Available targets are:'
@echo ''
@grep -E '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@echo ''