Created
January 6, 2017 12:49
-
-
Save euskadi31/d8479a71745db057539e2b316b2a2004 to your computer and use it in GitHub Desktop.
Example of Makefile for go project
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 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