Last active
January 8, 2020 03:44
-
-
Save damnever/a82755a8d5676cdb9792d597290d3dc4 to your computer and use it in GitHub Desktop.
Makefile for golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY: help build test deps clean | |
# Ref: https://gist.github.com/prwhite/8168133 | |
help: ## Display this help | |
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n\nTargets:\n"} \ | |
/^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-10s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST) | |
GOOS ?= $(shell go env GOOS) | |
GOARCH ?= $(shell go env GOARCH) | |
NOW = $(shell date '+%Y-%m-%d') | |
REV = $(shell git rev-parse --short HEAD || echo unknown) | |
LDFLAGS = -ldflags '-X github.com/damnever/ylem/version.GitRev=$(REV) \ | |
-X github.com/damnever/ylem/version.Date=$(NOW)' | |
build: ## Build executable files. (Args: GOOS=$(go env GOOS) GOARCH=$(go env GOARCH)) | |
env GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o 'bin/ylem-master' $(LDFLAGS) ./cmd/ylem-master/ | |
env GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o 'bin/ylem-storage' $(LDFLAGS) ./cmd/ylem-storage/ | |
GOLANGCI_LINT_VERSION ?= "latest" | |
test: ## Run test cases. (Args: GOLANGCI_LINT_VERSION=latest) | |
GOLANGCI_LINT_CMD=golangci-lint; \ | |
if [[ ! -x $$(command -v golangci-lint) ]]; then \ | |
if [[ ! -e ./bin/golangci-lint ]]; then \ | |
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s $(GOLANGCI_LINT_VERSION); \ | |
fi; \ | |
GOLANGCI_LINT_CMD=./bin/golangci-lint; \ | |
fi; \ | |
$${GOLANGCI_LINT_CMD} run . | |
go test -v -race -coverprofile=coverage.out ./... | |
go tool cover -html=coverage.out # -o coverage.html | |
deps: ## Update vendor. | |
go mod verify | |
go mod tidy -v | |
rm -rf vendor | |
go mod vendor -v | |
clean: ## Clean up useless files. | |
rm -rf bin | |
find . -type f -name '*.out' -exec rm -f {} + | |
find . -type f -name '.DS_Store' -exec rm -f {} + | |
find . -type f -name '*.test' -exec rm -f {} + | |
find . -type f -name '*.prof' -exec rm -f {} + | |
find . -type s -name 'localhost:*' -exec rm -f {} + | |
find . -type s -name '127.0.0.1:*' -exec rm -f {} + |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment