drone/Makefile
Enver Bisevac 66f2dadb7a [MAINT] fixing linter errors (#19)
* fix linter errors

* fix exhaust linter error

* fix exhaust linter error

* fix linter errors

* golangci-lint timeout increased

* golangci-lint verbose flag
2022-09-22 16:08:41 +02:00

159 lines
5.4 KiB
Makefile

ifndef GOPATH
GOPATH := $(shell go env GOPATH)
endif
ifndef GOBIN
GOBIN := $(shell go env GOPATH)/bin
endif
ifndef DOCKER_BUILD_OPTS
DOCKER_BUILD_OPTS :=
endif
tools = $(addprefix $(GOBIN)/, golangci-lint goimports govulncheck)
deps = $(addprefix $(GOBIN)/, wire dbmate mockgen)
ifneq (,$(wildcard ./.local.env))
include ./.local.env
export
endif
.DEFAULT_GOAL := all
init: ## Install git hooks to perform pre-commit checks
git config core.hooksPath .githooks
git config commit.template .gitmessage
all: dep tools generate lint build test ## Build and run the test for gitness
@echo "Run `make start` to start the services"
dep: $(deps) ## Install the deps required to generate code and build gitness
@echo "Installing dependencies"
@go mod download
tools: $(tools) ## Install tools required for the build
@echo "Installed tools"
mocks: $(mocks)
@echo "Generating Test Mocks"
generate: $(mocks) cli/server/wire_gen.go mocks/mock_client.go
@echo "Generating Code"
build: generate ## Build the gitness service binary
@echo "Building Gitness Server"
CGO_ENABLED=0 go build -ldflags="-X github.com/harness/gitness/version.GitCommit=${GIT_COMMIT} -X github.com/harness/gitness/version.Version=${GITNESS_VERSION}" -o ./gitness .
test: generate ## Run the go tests
@echo "Running tests"
go test -v -coverprofile=coverage.out ./internal/...
go tool cover -html=coverage.out
run: dep ## Run the gitness binary from source
@go run -race -ldflags="-X github.com/harness/gitness/version.Version=1.0.0" .
clean-db: ## delete all data from local database
psql postgresql://gitness:gitness@localhost:5432/gitness -f scripts/db/cleanup.sql
populate-db: ## inject sample data into local database
psql postgresql://gitness:gitness@localhost:5432/gitness -f scripts/db/sample_data.sql
update-tools: delete-tools $(tools) ## Update the tools by deleting and re-installing
delete-tools: ## Delete the tools
@rm $(tools) || true
#########################################
# Docker environment commands
# The following targets relate to running gitness and its dependent services
#########################################
start: ## Run all dependent services and start the gitness server locally - the service will listen on :3000 by default
docker-compose -f ./docker/docker-compose.yml up ${DOCKER_BUILD_OPTS} --remove-orphans
stop: ## Stop all services
docker-compose -f ./docker/docker-compose.yml down --remove-orphans
dev: ## Run local dev environment this starts the services which gitness depends on
docker-compose -f ./docker/docker-compose.yml up ${DOCKER_BUILD_OPTS} --remove-orphans db redis
test-env: stop ## Run test environment - this runs all services and the gitness in test mode.
docker-compose -f ./docker/docker-compose.yml -f ./docker/docker-compose.test.yml up -d ${DOCKER_BUILD_OPTS} --remove-orphans
image: ## Build the gitness docker image
@echo "Building Gitness Image"
@docker build --build-arg GITNESS_VERSION=latest \
--build-arg GIT_COMMIT=${GIT_COMMIT} \
--build-arg GITHUB_ACCESS_TOKEN=${GITHUB_ACCESS_TOKEN} \
-t gitness:latest \
-f ./docker/Dockerfile .
e2e: generate test-env ## Run e2e tests
chmod +x wait-for-gitness.sh && ./wait-for-gitness.sh
go test -p 1 -v -coverprofile=e2e_cov.out ./tests/... -env=".env.local"
###########################################
# Code Formatting and linting
###########################################
format: tools # Format go code and error if any changes are made
@echo "Formating ..."
@goimports -w .
@echo "Formatting complete"
sec:
@echo "Vulnerability detection $(1)"
@govulncheck ./...
lint: tools generate # lint the golang code
@echo "Linting $(1)"
@golangci-lint run --timeout=3m --verbose
###########################################
# Code Generation
#
# Some code generation can be slow, so we only run it if
# the source file has changed.
###########################################
cli/server/wire_gen.go: cli/server/wire.go ## Update the wire dependency injection if wire.go has changed.
@echo "Updating wire_gen.go"
go generate ./cli/server/wire_gen.go
mocks/mock_client.go: internal/store/store.go client/client.go
go generate mocks/mock.go
###########################################
# Install Tools and deps
#
# These targets specify the full path to where the tool is installed
# If the tool already exists it wont be re-installed.
###########################################
# Install golangci-lint
$(GOBIN)/golangci-lint:
@echo "🔘 Installing golangci-lint... (`date '+%H:%M:%S'`)"
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin
# Install goimports to format code
$(GOBIN)/goimports:
@echo "🔘 Installing goimports ... (`date '+%H:%M:%S'`)"
@go install golang.org/x/tools/cmd/goimports
# Install wire to generate dependency injection
$(GOBIN)/wire:
go install github.com/google/wire/cmd/wire@latest
# Install dbmate to perform db migrations
$(GOBIN)/dbmate:
go install github.com/amacneil/dbmate@v1.15.0
# Install mockgen to generate mocks
$(GOBIN)/mockgen:
go install github.com/golang/mock/mockgen@latest
$(GOBIN)/govulncheck:
go install golang.org/x/vuln/cmd/govulncheck@latest
help: ## show help message
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[$$()% 0-9a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
.PHONY: delete-tools update-tools help format lint