github.com/crosseyed/versionbump@v1.1.0/Makefile (about) 1 # Project 2 BINARY := versionbump 3 VERSION ?= $(shell cat VERSION) 4 COMMIT := $(shell git rev-parse --short HEAD) 5 BUILD_INFO := $(COMMIT)-$(shell date -u +"%Y-%m-%dT%H:%M:%SZ") 6 BRANCH := $(shell git rev-parse --abbrev-ref HEAD) 7 8 # Utilities 9 DOTENV := godotenv -f $(HOME)/.env,.env 10 11 # Variables 12 OS = $(word 1, $@) 13 14 # Go 15 GOMODOPTS = GO111MODULE=on 16 GOGETOPTS = GO111MODULE=off 17 GODIRS = $(shell find . -type d -maxdepth 1 -mindepth 1 | egrep 'cmd|internal|pkg|api') 18 19 .PHONY: build _build _build_xcompile browsetest cattest clean deps _deps depsdev deploy lint release \ 20 test _test _test_setup 21 22 cmd/versionbump/version.go: VERSION 23 @echo "// This file is generated do not edit" > $@ 24 @echo "package main" >> $@ 25 @echo "var Version = \"$(VERSION)\"" >> $@ 26 27 build: cmd/versionbump/version.go 28 @$(DOTENV) make _build 29 30 _build: 31 go fmt ./... 32 ifneq ($(XCOMPILE),true) 33 @make _build_simple 34 else 35 @make _build_xcompile 36 endif 37 38 _build_simple: 39 go build -ldflags "-X main.Version=$(VERSION)-$(BUILD_INFO)" ./cmd/$(BINARY) 40 41 _build_xcompile: 42 make $(PLATFORMS) 43 44 PLATFORMS := linux darwin 45 .PHONY: $(PLATFORMS) 46 $(PLATFORMS): 47 @mkdir -p dist 48 GOOS=$(OS) GOARCH=amd64 CGO_ENABLED=0 go build \ 49 -o dist/$(BINARY)-$(OS)-$(VERSION) \ 50 -a -installsuffix cgo \ 51 -ldflags "-X main.Version=$(VERSION)-$(BUILD_INFO)" \ 52 ./cmd/$(BINARY) 53 54 bumpminor: 55 git fetch --tags 56 versionbump minor --checktags VERSION 57 make cmd/versionbump/version.go 58 59 bumpmajor: 60 git fetch --tags 61 versionbump major --checktags VERSION 62 make cmd/versionbump/version.go 63 64 clean: 65 rm -rf dist reports tmp vendor versionbump 66 67 deps: 68 @$(DOTENV) make _deps 69 70 _deps: 71 $(GOMODOPTS) go mod tidy 72 $(GOMODOPTS) go mod vendor 73 $(GOGETOPTS) make depsdev 74 75 depsdev: 76 @$(DOTENV) make $(GOGETS) 77 78 GOGETS := github.com/crosseyed/versionbump/cmd/versionbump github.com/jstemmer/go-junit-report \ 79 github.com/golangci/golangci-lint/cmd/golangci-lint github.com/ains/go-test-html \ 80 github.com/fzipp/gocyclo github.com/joho/godotenv/cmd/godotenv \ 81 github.com/stretchr/testify 82 .PHONY: $(GOGETS) 83 $(GOGETS): 84 $(GOGETOPTS) go get -u $@ 85 86 test: 87 @$(DOTENV) make _test 88 89 _test: 90 make _test_setup 91 @mkdir -p reports/html 92 @echo "### Unit Tests"; \ 93 go test -covermode atomic -coverprofile=./reports/coverage.out -v ./... 2>&1 | tee reports/test.txt; \ 94 EXITCODE="$${PIPESTATUS[0]}"; \ 95 cat ./reports/test.txt | go-junit-report > reports/junit.xml; \ 96 echo "### Code Coverage"; \ 97 go tool cover -func=./reports/coverage.out | tee ./reports/coverage.txt; \ 98 go tool cover -html=reports/coverage.out -o reports/html/coverage.html; \ 99 echo "### Cyclomatix Complexity Report"; \ 100 gocyclo -avg $(GODIRS) | grep -v _test.go | tee reports/cyclocomplexity.txt; \ 101 exit $(EXITCODE) 102 103 _test_setup: 104 @mkdir -p tmp 105 @cp -r test/fixtures tmp/testfiles 106 @-chmod 600 tmp/testfiles/version_no_access.txt 2>&1 > /dev/null 107 @cp tmp/testfiles/{version.txt,version_no_access.txt} 108 @chmod 000 tmp/testfiles/version_no_access.txt 109 110 deploy: 111 @echo TODO 112 113 release: 114 ifeq ($(BRANCH),master) 115 git fetch --tags 116 git tag v$(VERSION) && git push origin v$(VERSION) 117 endif 118 119 lint: 120 golangci-lint run --enable=gocyclo 121 122 REPORTS := reports/html/coverage.html 123 .PHONY: $(REPORTS) 124 $(REPORTS): 125 @test -f $@ && open $@ 126 127 browsetest: $(REPORTS) 128 129 cattest: 130 @echo "### Unit Tests" 131 @cat reports/test.txt 132 @echo "### Code Coverage" 133 @cat ./reports/coverage.txt 134 @echo "### Cyclomatix Complexity Report" 135 @cat reports/cyclocomplexity.txt