@@ -10,47 +10,48 @@ VERSION ?= $(shell git describe --tags --match='v[0-9]*' --dirty --always)
10
10
GARM_REF ?= $(shell git rev-parse --abbrev-ref HEAD)
11
11
GO ?= go
12
12
13
+ .PHONY : help
14
+ help : # # Display this help.
15
+ @awk ' BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST )
16
+
13
17
14
18
default : build
15
19
20
+ # #@ Build
21
+
16
22
.PHONY : build-static test install-lint-deps lint go-test fmt fmtcheck verify-vendor verify create-release-files release
17
- build-static :
23
+ build-static : # # Build garm statically
18
24
@echo Building garm
19
25
docker build --tag $(IMAGE_TAG ) -f Dockerfile.build-static .
20
26
docker run --rm -e USER_ID=$(USER_ID ) -e GARM_REF=$(GARM_REF ) -e USER_GROUP=$(USER_GROUP ) -v $(PWD ) /build:/build/output:z $(IMAGE_TAG ) /build-static.sh
21
27
@echo Binaries are available in $(PWD ) /build
22
28
23
- create-release-files :
24
- ./scripts/make-release.sh
25
-
26
- release : build-static create-release-files
27
-
28
- clean :
29
+ clean : # # Clean up build artifacts
29
30
@rm -rf ./bin ./build ./release
30
31
31
- build :
32
+ build : # # Build garm
32
33
@echo Building garm ${VERSION}
33
34
$(shell mkdir -p ./bin)
34
35
@$(GO ) build -ldflags " -s -w -X main.Version=${VERSION} " -tags osusergo,netgo,sqlite_omit_load_extension -o bin/garm ./cmd/garm
35
36
@$(GO ) build -ldflags " -s -w -X github.com/cloudbase/garm/cmd/garm-cli/cmd.Version=${VERSION} " -tags osusergo,netgo,sqlite_omit_load_extension -o bin/garm-cli ./cmd/garm-cli
36
37
@echo Binaries are available in $(PWD ) /bin
37
38
38
- test : verify go-test
39
+ test : verify go-test # # Run tests
39
40
40
- install-lint-deps :
41
- @$(GO ) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
41
+ # #@ Release
42
+ create-release-files :
43
+ ./scripts/make-release.sh
42
44
43
- lint :
44
- @golangci-lint run --timeout=8m --build-tags testing
45
+ release : build-static create-release-files # # Create a release
45
46
46
- go-test :
47
- @$(GO ) test -race -mod=vendor -tags testing -v $(TEST_ARGS ) -timeout=15m -parallel=4 -count=1 ./...
48
-
49
- fmt :
50
- @$(GO ) fmt $$(go list ./... )
47
+ # #@ Lint / Verify
48
+ .PHONY : lint
49
+ lint : golangci-lint $(GOLANGCI_LINT ) # # Run linting.
50
+ $(GOLANGCI_LINT ) run -v $(GOLANGCI_LINT_EXTRA_ARGS )
51
51
52
- fmtcheck :
53
- @gofmt -l -s $$(go list ./... | sed 's|github.com/cloudbase/garm/||g' ) | grep " .*\.go" ; if [ " $$ ?" -eq 0 ]; then echo " gofmt check failed; please run gofmt -w -s" ; exit 1; fi
52
+ .PHONY : lint-fix
53
+ lint-fix : golangci-lint $(GOLANGCI_LINT ) # # Lint the codebase and run auto-fixers if supported by the linte
54
+ GOLANGCI_LINT_EXTRA_ARGS=--fix $(MAKE ) lint
54
55
55
56
verify-vendor : # # verify if all the go.mod/go.sum files are up-to-date
56
57
$(eval TMPDIR := $(shell mktemp -d) )
@@ -59,4 +60,32 @@ verify-vendor: ## verify if all the go.mod/go.sum files are up-to-date
59
60
@diff -r -u -q ${ROOTDIR} ${TMPDIR} /garm > /dev/null 2>&1 ; if [ " $$ ?" -ne 0 ]; then echo " please run: go mod tidy && go mod vendor" ; exit 1; fi
60
61
@rm -rf ${TMPDIR}
61
62
62
- verify : verify-vendor lint fmtcheck
63
+ verify : verify-vendor lint fmtcheck # # Run all verify-* targets
64
+
65
+ # #@ Development
66
+
67
+ go-test : # # Run tests
68
+ @$(GO ) test -race -mod=vendor -tags testing -v $(TEST_ARGS ) -timeout=15m -parallel=4 -count=1 ./...
69
+
70
+ fmt : # # Run go fmt against code.
71
+ @$(GO ) fmt $$(go list ./... )
72
+
73
+
74
+ # #@ Build Dependencies
75
+
76
+ # # Location to install dependencies to
77
+ LOCALBIN ?= $(shell pwd) /bin
78
+ $(LOCALBIN ) :
79
+ mkdir -p $(LOCALBIN )
80
+
81
+ # # Tool Binaries
82
+ GOLANGCI_LINT ?= $(LOCALBIN ) /golangci-lint
83
+
84
+ # # Tool Versions
85
+ GOLANGCI_LINT_VERSION ?= v1.55.2
86
+
87
+ .PHONY : golangci-lint
88
+ golangci-lint : $(GOLANGCI_LINT ) # # Download golangci-lint locally if necessary. If wrong version is installed, it will be overwritten.
89
+ $(GOLANGCI_LINT ) : $(LOCALBIN )
90
+ test -s $(LOCALBIN ) /golangci-lint && $(LOCALBIN ) /golangci-lint --version | grep -q $(GOLANGCI_LINT_VERSION ) || \
91
+ GOBIN=$(LOCALBIN ) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION )
0 commit comments