Created
July 13, 2022 10:04
-
-
Save rodrigozrusso/b016d2ec5d72453ba045d718105cd497 to your computer and use it in GitHub Desktop.
Makefile for go projects - Replace <<<project-name>>> with your project name
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: all clean | |
BINARY=bin/<<<project-name>>> | |
VERSION=$(shell git tag | tail -1) | |
BUILD=$(shell git rev-parse HEAD) | |
LDFLAGS=-ldflags "-X <<<project-name>>>.Version=$(VERSION) -X <<<project-name>>>.Build=$(BUILD)" | |
all: test coverage build | |
.PHONY: build | |
build: | |
go build $(LDFLAGS) -o $(BINARY) ./cmd/main.go | |
.PHONY: test | |
test: | |
go test -v -cover -coverprofile=coverage.out $$(go list ./... | grep -v '/vendor/') | |
fmt: | |
go fmt ./cmd/* ./pkg/* | |
clean: | |
-rm $(BINARY) | |
coverage: | |
go tool cover -html=coverage.out -o coverage.html | |
dependencies: | |
go mod download && go mod verify |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment