|
| 1 | +#### Environment #### |
| 2 | + |
| 3 | +# Enforce usage of the Go modules system. |
| 4 | +export GO111MODULE := on |
| 5 | + |
| 6 | +# Determine where `go get` will install binaries to. |
| 7 | +GOBIN := $(HOME)/go/bin |
| 8 | +ifdef GOPATH |
| 9 | + GOBIN := $(GOPATH)/bin |
| 10 | +endif |
| 11 | + |
| 12 | +# Current operating system name. |
| 13 | +PLATFORM := $(shell uname -s) |
| 14 | + |
| 15 | +# All target for when make is run on its own. |
| 16 | +.PHONY: all |
| 17 | +all: test lint |
| 18 | + |
| 19 | +#### Binary Dependencies #### |
| 20 | + |
| 21 | +# Install binary for goimports. |
| 22 | +goimports := $(GOBIN)/goimports |
| 23 | +$(goimports): |
| 24 | + @cd /tmp && go get -u golang.org/x/tools/cmd/goimports |
| 25 | + |
| 26 | +# Install binary for golangci-lint. |
| 27 | +golangci-lint := $(GOBIN)/golangci-lint |
| 28 | +$(golangci-lint): |
| 29 | + @./scripts/install-golangci-lint $(golangci-lint) |
| 30 | + |
| 31 | +# Install binary for goreleaser. |
| 32 | +goreleaser := $(GOBIN)/goreleaser |
| 33 | +$(goreleaser): |
| 34 | + @./scripts/install-goreleaser $(goreleaser) |
| 35 | + |
| 36 | +# Install binary for upx. |
| 37 | +ifeq "$(PLATFORM)" "Linux" |
| 38 | +upx := $(GOBIN)/upx |
| 39 | +else |
| 40 | +upx := /usr/local/bin/upx |
| 41 | +endif |
| 42 | +$(upx): |
| 43 | + @./scripts/install-upx $(upx) |
| 44 | + |
| 45 | +#### Linting #### |
| 46 | + |
| 47 | +# Run code linters. |
| 48 | +.PHONY: lint |
| 49 | +lint: $(golangci-lint) style |
| 50 | + $(golangci-lint) run |
| 51 | + |
| 52 | +# Run code formatters. Unformatted code will fail in CircleCI. |
| 53 | +.PHONY: style |
| 54 | +style: $(goimports) |
| 55 | +ifdef GITHUB_ACTIONS |
| 56 | + $(goimports) -l . |
| 57 | +else |
| 58 | + $(goimports) -l -w . |
| 59 | +endif |
| 60 | + |
| 61 | +#### Testing #### |
| 62 | + |
| 63 | +# Run Go tests and generate a JUnit XML style test report for ingestion by CircleCI. |
| 64 | +.PHONY: test |
| 65 | +test: $(go-junit-report) |
| 66 | + @go test -v -race -cover ./... |
| 67 | + |
| 68 | +#### Release #### |
| 69 | + |
| 70 | +.PHONY: compress |
| 71 | +compress: $(upx) |
| 72 | + $(upx) --best --ultra-brute dist/retry_*/retry* |
| 73 | + |
| 74 | +.PHONY: release |
| 75 | +release: $(goreleaser) |
| 76 | +ifdef GITHUB_ACTIONS |
| 77 | + $(goreleaser) release |
| 78 | +else |
| 79 | + $(goreleaser) --rm-dist --skip-publish --skip-validate --snapshot |
| 80 | +endif |
0 commit comments