github.com/wtfutil/wtf@v0.43.0/Makefile (about) 1 .PHONY: build clean contrib_check coverage docker-build docker-install help install isntall lint run size test uninstall 2 3 # detect GOPATH if not set 4 ifndef $(GOPATH) 5 $(info GOPATH is not set, autodetecting..) 6 TESTPATH := $(dir $(abspath ../../..)) 7 DIRS := bin pkg src 8 9 # create a ; separated line of tests and pass it to shell 10 MISSING_DIRS := $(shell $(foreach entry,$(DIRS),test -d "$(TESTPATH)$(entry)" || echo "$(entry)";)) 11 ifeq ($(MISSING_DIRS),) 12 $(info Found GOPATH: $(TESTPATH)) 13 export GOPATH := $(TESTPATH) 14 else 15 $(info ..missing dirs "$(MISSING_DIRS)" in "$(TESTDIR)") 16 $(info GOPATH autodetection failed) 17 endif 18 endif 19 20 # Set go modules to on and use GoCenter for immutable modules 21 export GO111MODULE = on 22 export GOPROXY = https://proxy.golang.org,direct 23 24 # Determines the path to this Makefile 25 THIS_FILE := $(lastword $(MAKEFILE_LIST)) 26 27 GOBIN := $(GOPATH)/bin 28 29 APP=wtfutil 30 31 define HEADER 32 ____ __ ____ .___________. _______ 33 \ \ / \ / / | || ____| 34 \ \/ \/ / `---| |----`| |__ 35 \ / | | | __| 36 \ /\ / | | | | 37 \__/ \__/ |__| |__| 38 39 endef 40 export HEADER 41 42 # -------------------- Actions -------------------- # 43 44 ## build: builds a local version 45 build: 46 @echo "$$HEADER" 47 @echo "Building..." 48 go build -o bin/${APP} 49 @echo "Done building" 50 51 ## clean: removes old build cruft 52 clean: 53 rm -rf ./dist 54 rm -rf ./bin/${APP} 55 @echo "Done cleaning" 56 57 ## contrib-check: checks for any contributors who have not been given due credit 58 contrib-check: 59 npx all-contributors-cli check 60 61 ## coverage: figures out and displays test code coverage 62 coverage: 63 go test -coverprofile=coverage.out ./... 64 go tool cover -html=coverage.out 65 66 ## docker-build: builds in docker 67 docker-build: 68 @echo "Building ${APP} in Docker..." 69 docker build -t wtfutil:build --build-arg=version=master -f Dockerfile.build . 70 @echo "Done with docker build" 71 72 ## docker-install: installs a local version of the app from docker build 73 docker-install: 74 @echo "Installing..." 75 docker create --name wtf_build wtfutil:build 76 docker cp wtf_build:/usr/local/bin/wtfutil ~/.local/bin/ 77 $(eval INSTALLPATH = $(shell which ${APP})) 78 @echo "${APP} installed into ${INSTALLPATH}" 79 docker rm wtf_build 80 81 ## gosec: runs the gosec static security scanner against the source code 82 gosec: $(GOBIN)/gosec 83 gosec -tests ./... 84 85 $(GOBIN)/gosec: 86 cd && go install github.com/securego/gosec/v2/cmd/gosec@latest 87 88 ## help: prints this help message 89 help: 90 @echo "Usage: \n" 91 @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /' 92 93 ## isntall: an alias for 'install' 94 isntall: 95 @$(MAKE) -f $(THIS_FILE) install 96 97 ## install: installs a local version of the app 98 install: 99 $(eval GOVERS = $(shell go version)) 100 @echo "$$HEADER" 101 @echo "Installing ${APP} with ${GOVERS}..." 102 @go clean 103 @go install -ldflags="-s -w" 104 @mv $(GOBIN)/wtf $(GOBIN)/${APP} 105 $(eval INSTALLPATH = $(shell which ${APP})) 106 @echo "${APP} installed into ${INSTALLPATH}" 107 108 ## lint: runs a number of code quality checks against the source code 109 lint: $(GOBIN)/golangci-lint 110 golangci-lint cache clean 111 golangci-lint run 112 113 $(GOBIN)/golangci-lint: 114 cd && go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest 115 116 # lint: 117 # @echo "\033[35mhttps://github.com/kisielk/errcheck\033[0m" 118 # errcheck ./app 119 # errcheck ./cfg 120 # errcheck ./flags 121 # errcheck ./help 122 # errcheck ./logger 123 # errcheck ./modules/... 124 # errcheck ./utils 125 # errcheck ./view 126 # errcheck ./wtf 127 # errcheck ./main.go 128 129 # @echo "\033[35mhttps://golang.org/cmd/vet/k\033[0m" 130 # go vet ./app 131 # go vet ./cfg 132 # go vet ./flags 133 # go vet ./help 134 # go vet ./logger 135 # go vet ./modules/... 136 # go vet ./utils 137 # go vet ./view 138 # go vet ./wtf 139 # go vet ./main.go 140 141 # @echo "\033[35m# https://staticcheck.io/docs/k\033[0m" 142 # staticcheck ./app 143 # staticcheck ./cfg 144 # staticcheck ./flags 145 # staticcheck ./help 146 # staticcheck ./logger 147 # staticcheck ./modules/... 148 # staticcheck ./utils 149 # staticcheck ./view 150 # staticcheck ./wtf 151 # staticcheck ./main.go 152 153 # @echo "\033[35m# https://github.com/mdempsky/unconvert\033[0m" 154 # unconvert ./... 155 156 ## loc: displays the lines of code (LoC) count 157 loc: 158 @loc --exclude _sample_configs/ _site/ docs/ Makefile *.md 159 160 ## run: executes the locally-installed version 161 run: build 162 @echo "$$HEADER" 163 bin/${APP} 164 165 ## test: runs the test suite 166 test: build 167 @echo "$$HEADER" 168 go test ./... 169 170 ## uninstall: uninstals a locally-installed version 171 uninstall: 172 @rm $(GOBIN)/${APP}