Skip to content

Instantly share code, notes, and snippets.

@rodrigozrusso
Created July 13, 2022 10:04
Show Gist options
  • Save rodrigozrusso/b016d2ec5d72453ba045d718105cd497 to your computer and use it in GitHub Desktop.
Save rodrigozrusso/b016d2ec5d72453ba045d718105cd497 to your computer and use it in GitHub Desktop.
Makefile for go projects - Replace <<<project-name>>> with your project name
.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