Skip to content

Instantly share code, notes, and snippets.

@mattli001
Last active April 21, 2018 02:07
Show Gist options
  • Save mattli001/98ec450d1ef61b4df03c317aa1634087 to your computer and use it in GitHub Desktop.
Save mattli001/98ec450d1ef61b4df03c317aa1634087 to your computer and use it in GitHub Desktop.
A Makefile based CI/CD chain for Go
# http://le-gall.bzh/post/makefile-based-ci-chain-for-go/
SHELL := $(shell which bash) # set default shell
# OS / Arch we will build our binaries for
OSARCH := "linux/amd64 linux/386 windows/amd64 windows/386 darwin/amd64 darwin/386"
ENV = /usr/bin/env
.SHELLFLAGS = -c # Run commands in a -c flag
.SILENT: ; # no need for @
.ONESHELL: ; # recipes execute in same shell
.NOTPARALLEL: ; # wait for this target to finish
.EXPORT_ALL_VARIABLES: ; # send all vars to shell
.PHONY: all # All targets are accessible for user
.DEFAULT: help # Running Make will run the help target
help: ## Show Help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
dep: ## Get build dependencies
go get -v -u github.com/golang/dep/cmd/dep && \
go get github.com/mitchellh/gox && \
go get github.com/mattn/goveralls
build: ## Build the app
dep ensure && go build
cross-build: ## Build the app for multiple os/arch
gox -osarch=$(OSARCH) -output "bin/blackbeard_{{.OS}}_{{.Arch}}"
test: ## Launch tests
go test -v ./…
test-cover: ## Launch tests coverage and send it to coverall
$(ENV) ./scripts/test-coverage.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment