Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add beautified Makefile, Help information, better output #363

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 61 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,78 +5,110 @@ GOFMT_FILES?=$$(find . -name '*.go' | grep -v vendor)
TAG=$(shell git describe --abbrev=0 --tags)


all: build
all: help

$(GOPATH)/bin/golint$(suffix):
go get github.com/golang/lint/golint

$(GOPATH)/bin/goveralls$(suffix):
go get github.com/mattn/goveralls


## build: Build the project
build: bin
@go build -o bin/$(NAME) .

## vandor: verify dependencies have expected conten
vendor:
go mod vendor
@go mod vendor


.bats:
git clone --depth 1 https://github.com/sstephenson/bats.git .bats
@git clone --depth 1 https://github.com/sstephenson/bats.git .bats

## bin: Create the bin directory
bin:
mkdir bin
@mkdir bin

## release: Create a release
release:
goreleaser --rm-dist
@goreleaser --rm-dist

## snapshot: Creating a Snapshot Version
snapshot:
goreleaser --snapshot --skip-publish --rm-dist

build: bin
go build -o bin/$(NAME) .
@goreleaser --snapshot --skip-publish --rm-dist

## lint: Use golint to check the code specification
lint: $(GOPATH)/bin/golint$(suffix)
golint
@golint

## docker: Build and push the docker image
docker:
docker build -t $(IMAGE_NAME):$(TAG) .
docker tag $(IMAGE_NAME):$(TAG) $(IMAGE_NAME):latest
docker push $(IMAGE_NAME):$(TAG)
docker push $(IMAGE_NAME):latest
@docker build -t $(IMAGE_NAME):$(TAG) .
@docker tag $(IMAGE_NAME):$(TAG) $(IMAGE_NAME):latest
@docker push $(IMAGE_NAME):$(TAG)
@docker push $(IMAGE_NAME):latest

## docker-offline: Build and push an offline docker image
docker-offline:
docker build -f Dockerfile.offline -t $(IMAGE_NAME):$(TAG)-offline .
docker tag $(IMAGE_NAME):$(TAG)-offline $(IMAGE_NAME):offline
@docker build -f Dockerfile.offline -t $(IMAGE_NAME):$(TAG)-offline .
@docker tag $(IMAGE_NAME):$(TAG)-offline $(IMAGE_NAME):offline

## vet: Check the code using go vet
vet:
go vet
@go vet

## test: Run the tests
test: vet
go test -race -v -cover ./...
@go test -race -v -cover ./...

## watch: Monitor code changes and run tests automatically
watch:
ls */*.go | entr make test
@ls */*.go | entr make test

## acceptance: Operational acceptance test
acceptance:
docker build -f Dockerfile.acceptance -t $(IMAGE_NAME):$(TAG)-acceptance .
docker tag $(IMAGE_NAME):$(TAG)-acceptance $(IMAGE_NAME):acceptance
@docker build -f Dockerfile.acceptance -t $(IMAGE_NAME):$(TAG)-acceptance .
@docker tag $(IMAGE_NAME):$(TAG)-acceptance $(IMAGE_NAME):acceptance

## cover: Generate code coverage reports
cover:
go test -v ./$(NAME) -coverprofile=coverage.out
go tool cover -html=coverage.out
rm coverage.out
@go test -v ./$(NAME) -coverprofile=coverage.out
@go tool cover -html=coverage.out
@rm coverage.out

## clean: Clear the generated file
clean:
rm -fr dist bin
@rm -fr dist bin

## fmt: Format the code
fmt:
gofmt -w $(GOFMT_FILES)
@gofmt -w $(GOFMT_FILES)

## check: Generates the checksum of the file
dist/$(NAME)-checksum-%:
cd dist && sha256sum [email protected]
@cd dist && sha256sum [email protected]

checksums: dist/$(NAME)-checksum-darwin-amd64 dist/$(NAME)-checksum-windows-386 dist/$(NAME)-checksum-windows-amd64 dist/$(NAME)-checksum-linux-amd64

chocolatey/$(NAME)/$(NAME).$(TAG).nupkg: chocolatey/$(NAME)/$(NAME).nuspec
cd chocolatey/$(NAME) && choco pack
@cd chocolatey/$(NAME) && choco pack

## choco: Build and push the chocolatey package
choco:
cd chocolatey/$(NAME) && choco push $(NAME).$(TAG).nupkg -s https://chocolatey.org/
@cd chocolatey/$(NAME) && choco push $(NAME).$(TAG).nupkg -s https://chocolatey.org/

## help: Display help information
help: Makefile
@echo ""
@echo "Usage:"
@echo ""
@echo " make [target]"
@echo ""
@echo ""
@echo "Targets:"
@echo ""
@awk -F ':|##' '/^[^\.%\t][^\t]*:.*##/{printf " \033[36m%-20s\033[0m %s\n", $$1, $$NF}' $(MAKEFILE_LIST) | sort
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'

.PHONY: release snapshot fmt clean cover acceptance lint docker test vet watch build check choco checksums