Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/eze-kiel/gomf

Go project Makefile generator
https://github.com/eze-kiel/gomf

Last synced: 4 days ago
JSON representation

Go project Makefile generator

Awesome Lists containing this project

README

        

# gomf

Golang projects' Makefile generator

## Gettin' started

```
$ git clone https://github.com/eze-kiel/gomf.git
$ cd gomf/
$ make build
```

## Usage

The usage is very simple:

```
$ gomf
```

For example, if you want to create a Makefile for a project in your current directory:

```
$ gomf .
```

It will ask you a couple of questions to configure the Makefile.

## The Makefile

The Makefile's template looks like this:

```Makefile
GOCMD=go
GOTEST=$(GOCMD) test
GOVET=$(GOCMD) vet
BINARY_NAME={{.BinaryName}}
VERSION?=0.0.0
DOCKER_REGISTRY?={{.DockerRegistry}}

GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)

.PHONY: all build clean

all: help

## Build:
build: ## Build the Go project
mkdir -p out/bin
GO111MODULE=on $(GOCMD) build -o out/bin/$(BINARY_NAME) .

clean: ## Clean all the files and binaries generated by the Makefile
rm -rf ./out

## Test:
test: ## Run the tests of the project
ifeq ($(EXPORT_RESULT), true)
GO111MODULE=off go get -u github.com/jstemmer/go-junit-report
$(eval OUTPUT_OPTIONS = | tee /dev/tty | go-junit-report -set-exit-code > junit-report.xml)
endif
$(GOTEST) -v -race ./... $(OUTPUT_OPTIONS)

coverage: ## Run the tests of the project and export the coverage
$(GOTEST) -cover -covermode=count -coverprofile=profile.cov ./...
$(GOCMD) tool cover -func profile.cov
ifeq ($(EXPORT_RESULT), true)
GO111MODULE=off go get -u github.com/AlekSi/gocov-xml
GO111MODULE=off go get -u github.com/axw/gocov/gocov
gocov convert profile.cov | gocov-xml > coverage.xml
endif

## Docker:
docker-build: ## Use the Dockerfile to build the container
docker build --rm --tag $(BINARY_NAME) .

docker-release: ## Release the container with tag latest and version
docker tag $(BINARY_NAME) $(DOCKER_REGISTRY)/$(BINARY_NAME):latest
docker tag $(BINARY_NAME) $(DOCKER_REGISTRY)/$(BINARY_NAME):$(VERSION)

docker push $(DOCKER_REGISTRY)/$(BINARY_NAME):latest
docker push $(DOCKER_REGISTRY)/$(BINARY_NAME):$(VERSION)

## Help:
help: ## Show this help
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}${RESET}'
@echo ''
@echo 'Targets:'
@awk 'BEGIN {FS = ":.*?## "} { \
if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-20s${GREEN}%s${RESET}\n", $$1, $$2} \
else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \
}' $(MAKEFILE_LIST)
```