From 251b414e4f077fcd48dd040c389112aa2ef0c7af Mon Sep 17 00:00:00 2001 From: Thomas Poignant Date: Wed, 2 Oct 2024 14:13:58 +0200 Subject: [PATCH] WIP Signed-off-by: Thomas Poignant --- .gitignore | 10 +++++++- Makefile | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 Makefile diff --git a/.gitignore b/.gitignore index 70e6dcc..e27a230 100644 --- a/.gitignore +++ b/.gitignore @@ -43,4 +43,12 @@ go-feature-flag-relay-proxy/ node_modules/ oryxBuildBinary -./.sonarlint \ No newline at end of file +./.sonarlint +sonarlint.xml +vcs.xml +workspace.xml +codeStyles/ +inspectionProfiles/ +misc.xml +modules.xml +shelf/ \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6214e66 --- /dev/null +++ b/Makefile @@ -0,0 +1,70 @@ +GOCMD=go +GOTEST=$(GOCMD) test +GOVET=$(GOCMD) vet + +GREEN := $(shell tput -Txterm setaf 2) +YELLOW := $(shell tput -Txterm setaf 3) +WHITE := $(shell tput -Txterm setaf 7) +CYAN := $(shell tput -Txterm setaf 6) +RESET := $(shell tput -Txterm sgr0) + +.PHONY: all test build vendor + + + +all: help +## Build: +build: build-api ## Build all the binaries and put the output in out/bin/ + +create-out-dir: + mkdir -p out/bin + +build-api: create-out-dir ## Build the migration cli in out/bin/ + CGO_ENABLED=0 GO111MODULE=on $(GOCMD) build -mod vendor -o out/bin/goff-api . + +clean: ## Remove build related file + -rm -fr ./bin ./out ./release + -rm -f ./junit-report.xml checkstyle-report.xml ./coverage.xml ./profile.cov yamllint-checkstyle.xml + +vendor: ## Copy of all packages needed to support builds and tests in the vendor directory + $(GOCMD) mod tidy + $(GOCMD) mod vendor + +## Dev: +swagger: ## Build swagger documentation + $(GOCMD) install github.com/swaggo/swag/cmd/swag@latest + cd cmd/relayproxy && swag init --parseDependency --parseDepth=1 --parseInternal --markdownFiles docs + +setup-env: + docker stop goff || true + docker rm goff || true + docker run --name goff -e POSTGRES_DB=gofeatureflag -e POSTGRES_PASSWORD=my-secret-pw -p 5432:5432 -e POSTGRES_USER=goff-user -d postgres + sleep 2 + migrate -source "file://database_migration" -database "postgres://goff-user:my-secret-pw@localhost:5432/gofeatureflag?sslmode=disable" up + +## Test: +test: ## Run the tests of the project + $(GOTEST) -v -race ./... + +coverage: ## Run the tests of the project and export the coverage + $(GOTEST) -cover -covermode=count -tags=docker -coverprofile=coverage.cov.tmp ./... \ + && cat coverage.cov.tmp | grep -v "/examples/" > coverage.cov + + +## Lint: +lint: ## Use golintci-lint on your project + mkdir -p ./bin + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s latest # Install linters + ./bin/golangci-lint run --timeout=5m --timeout=5m ./... --enable-only=gci --fix # Run linters + +## 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)