mirror of https://github.com/fmartingr/bazaar.git
Added makefile and helper scripts
This commit is contained in:
parent
96f10c798f
commit
07dcd73c3c
|
@ -8,8 +8,8 @@
|
|||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
# Output of the go coverage tool
|
||||
coverage.*
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
PROJECT := bazaar
|
||||
VERSION_COMMIT := $git rev-parse --short HEAD)
|
||||
SOURCE_FILES ?=./internal/... ./cmd/... ./pkg/...
|
||||
TEST_OPTIONS ?= -v -failfast -race -bench=. -benchtime=100000x -cover -coverprofile=coverage.out
|
||||
TEST_TIMEOUT ?=1m
|
||||
CLEAN_OPTIONS ?=-modcache -testcache
|
||||
LD_FLAGS := -X main.version=$(VERSION) -s -w
|
||||
BUILDS_PATH := ./build
|
||||
FROM_MAKEFILE := y
|
||||
|
||||
# Common exports
|
||||
export FROM_MAKEFILE
|
||||
export VERSION_COMMIT
|
||||
|
||||
export LD_FLAGS
|
||||
export SOURCE_FILES
|
||||
export TEST_OPTIONS
|
||||
export TEST_TIMEOUT
|
||||
export BUILDS_PATH
|
||||
|
||||
.PHONY: all
|
||||
all: help
|
||||
|
||||
# this is godly
|
||||
# https://news.ycombinator.com/item?id=11939200
|
||||
.PHONY: help
|
||||
help: ### this screen. Keep it first target to be default
|
||||
ifeq ($(UNAME), Linux)
|
||||
@grep -P '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
|
||||
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
|
||||
else
|
||||
@# this is not tested, but prepared in advance for you, Mac drivers
|
||||
@awk -F ':.*###' '$$0 ~ FS {printf "%15s%s\n", $$1 ":", $$2}' \
|
||||
$(MAKEFILE_LIST) | grep -v '@awk' | sort
|
||||
endif
|
||||
|
||||
.PHONY: clean
|
||||
clean: ### clean test cache, build files
|
||||
$(info: Make: Clean)
|
||||
@rm -rf ${BUILDS_PATH}
|
||||
@go clean ${CLEAN_OPTIONS}
|
||||
|
||||
.PHONY: build
|
||||
build: clean ### builds the project for the setup os/arch combinations
|
||||
$(info: Make: Build)
|
||||
@go build -a -v -ldflags "${LD_FLAGS}" -o ${BUILDS_PATH}/bazaar ./cmd/bazaar/*.go
|
||||
@chmod +x ${BUILDS_PATH}/bazaar
|
||||
|
||||
.PHONY: quick-run
|
||||
quick-run: ### Executes the project using golang
|
||||
@go run ./cmd/bazaar/*.go
|
||||
|
||||
.PHONY: run
|
||||
run: ### Executes the project build locally
|
||||
@make build
|
||||
${BUILDS_PATH}/bazaar
|
||||
|
||||
.PHONY: format
|
||||
format: ### Executes the formatting pipeline on the project
|
||||
$(info: Make: Format)
|
||||
@bash scripts/format.sh
|
||||
|
||||
.PHONY: lint
|
||||
lint: ### Check the project for errors
|
||||
$(info: Make: Lint)
|
||||
@bash scripts/lint.sh
|
||||
|
||||
.PHONY: test
|
||||
test: ### Runs the test suite
|
||||
@bash scripts/test.sh
|
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
if [ -z "$FROM_MAKEFILE" ]; then
|
||||
echo "Do not call this file directly - use the make command"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Enable/Disable formatters
|
||||
GOFMT_ENABLED=${GOFMT_ENABLED:-y}
|
||||
|
||||
# Add go binaries path to current $PATH
|
||||
PATH=$PATH:$(go env GOPATH)/bin
|
||||
|
||||
files=$(find . -name '*.go')
|
||||
|
||||
for file in $files
|
||||
do
|
||||
if [ "$GOFMT_ENABLED" == "y" ]; then
|
||||
gofmt -w -s $file
|
||||
fi
|
||||
done
|
|
@ -0,0 +1,9 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
if [ -z "$FROM_MAKEFILE" ]; then
|
||||
echo "Do not call this file directly - use the make command"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
golangci-lint run --tests=false
|
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
if [ -z "$FROM_MAKEFILE" ]; then
|
||||
echo "Do not call this file directly - use the make command"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
COVERAGE_PATH=coverage.out
|
||||
COVERAGE_HTML_PATH=coverage.html
|
||||
|
||||
go test ${TEST_OPTIONS} ${SOURCE_FILES} -timeout=${TEST_TIMEOUT}
|
||||
|
||||
echo
|
||||
echo "== Coverage report =="
|
||||
echo
|
||||
|
||||
go tool cover -html=${COVERAGE_PATH} -o ${COVERAGE_HTML_PATH}
|
||||
go tool cover -func=${COVERAGE_PATH}
|
Loading…
Reference in New Issue