From ffd394a8af4dac748ae303f3cfacad7786286716 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Greinhofer?= Date: Sun, 23 Jun 2019 11:46:09 -0500 Subject: [PATCH] Add a Makefile (#2) Adds a `Makefile` to simplify the maintenance tasks. --- .gitignore | 12 ++++-------- Makefile | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ go.sum | 1 + 3 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 Makefile diff --git a/.gitignore b/.gitignore index f1c181e..1e1f31e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,8 @@ -# Binaries for programs and plugins +*.dll +*.dylib *.exe *.exe~ -*.dll +*.out *.so -*.dylib - -# Test binary, build with `go test -c` *.test - -# Output of the go coverage tool, specifically when used with LiteIDE -*.out +dist/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e7b1663 --- /dev/null +++ b/Makefile @@ -0,0 +1,56 @@ +# Project name. +PROJECT_NAME = keeparelease + +# Makefile parameters. +TAG ?= $(shell git describe) + +# General. +SHELL = /bin/bash +TOPDIR = $(shell git rev-parse --show-toplevel) + +# Project specifics. +BUILD_DIR = dist +PLATFORMS = linux darwin +OS = $(word 1, $@) +GOOS = $(shell uname -s | tr A-Z a-z) +GOARCH = amd64 + +default: build + +.PHONY: help +help: # Display help + @awk -F ':|##' \ + '/^[^\t].+?:.*?##/ { + printf "\033[36m%-30s\033[0m %s\n", $$1, $$NF \ + }' $(MAKEFILE_LIST) | sort + +.PHONY: build +build: ## Build the project for the current platform + mkdir -p $(BUILD_DIR) + GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $(BUILD_DIR)/$(PROJECT_NAME)-$(TAG)-$(GOOS)-$(GOARCH) + +.PHONY: test +test: ## Run the unit tests + go test .../keeparelease + +.PHONY: clean +clean: clean-code ## Clean everything (!DESTRUCTIVE!) + +.PHONY: clean-code +clean-code: ## Remove unwanted files in this project (!DESTRUCTIVE!) + @cd $(TOPDIR) && git clean -ffdx && git reset --hard + +dist: $(PLATFORMS) ## Package the project for all available platforms + +.PHONY: publish +publish: dist ## Create GitHub release + keeparelease -a dist/* + +.PHONY: setup +setup: ## Setup the full environment (default) + go mod tidy + +$(PLATFORMS): # Build the project for all available platforms + mkdir -p $(BUILD_DIR) + GOOS=$(OS) GOARCH=$(GOARCH) go build -o $(BUILD_DIR)/$(PROJECT_NAME)-$(TAG)-$(OS)-$(GOARCH) +.PHONY: $(PLATFORMS) diff --git a/go.sum b/go.sum index 44c2ae5..cd53231 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,7 @@ github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNU github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=