Skip to content

Instantly share code, notes, and snippets.

@euskadi31
Created January 6, 2017 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save euskadi31/d8479a71745db057539e2b316b2a2004 to your computer and use it in GitHub Desktop.
Save euskadi31/d8479a71745db057539e2b316b2a2004 to your computer and use it in GitHub Desktop.
Example of Makefile for go project
.PHONY: all clean deps fmt vet test docker
EXECUTABLE ?= drone-webhook
IMAGE ?= plugins/$(EXECUTABLE)
COMMIT ?= $(shell git rev-parse --short HEAD)
LDFLAGS = -X "main.buildCommit=$(COMMIT)"
PACKAGES = $(shell go list ./... | grep -v /vendor/)
all: deps build test
clean:
go clean -i ./...
deps:
go get -t ./...
fmt:
go fmt $(PACKAGES)
vet:
go vet $(PACKAGES)
test:
@for PKG in $(PACKAGES); do go test -cover -coverprofile $$GOPATH/src/$$PKG/coverage.out $$PKG || exit 1; done;
docker:
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '-s -w $(LDFLAGS)'
docker build --rm -t $(IMAGE) .
$(EXECUTABLE): $(wildcard *.go)
go build -ldflags '-s -w $(LDFLAGS)'
build: $(EXECUTABLE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment