Pass build tags to golangci-lint and go test commands. (#102206)

* Pass build tag to golangci-lint.

* Pass build tags to go test command.
pull/102275/head
Peter Štibraný 3 months ago committed by GitHub
parent 3e5975367c
commit 3ec3085416
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 18
      Makefile

@ -17,6 +17,7 @@ GO_RACE_FLAG := $(if $(GO_RACE),-race)
GO_BUILD_FLAGS += $(if $(GO_BUILD_DEV),-dev) GO_BUILD_FLAGS += $(if $(GO_BUILD_DEV),-dev)
GO_BUILD_FLAGS += $(if $(GO_BUILD_TAGS),-build-tags=$(GO_BUILD_TAGS)) GO_BUILD_FLAGS += $(if $(GO_BUILD_TAGS),-build-tags=$(GO_BUILD_TAGS))
GO_BUILD_FLAGS += $(GO_RACE_FLAG) GO_BUILD_FLAGS += $(GO_RACE_FLAG)
GO_TEST_FLAGS += $(if $(GO_BUILD_TAGS),-tags=$(GO_BUILD_TAGS))
GO_TEST_OUTPUT := $(shell [ -n "$(GO_TEST_OUTPUT)" ] && echo '-json | tee $(GO_TEST_OUTPUT) | tparse -all') GO_TEST_OUTPUT := $(shell [ -n "$(GO_TEST_OUTPUT)" ] && echo '-json | tee $(GO_TEST_OUTPUT) | tparse -all')
GO_UNIT_COVERAGE ?= true GO_UNIT_COVERAGE ?= true
GO_UNIT_COVER_PROFILE ?= unit.cov GO_UNIT_COVER_PROFILE ?= unit.cov
@ -250,12 +251,12 @@ test-go: test-go-unit test-go-integration
.PHONY: test-go-unit .PHONY: test-go-unit
test-go-unit: ## Run unit tests for backend with flags. test-go-unit: ## Run unit tests for backend with flags.
@echo "backend unit tests" @echo "backend unit tests"
$(GO) test $(GO_RACE_FLAG) -v -short -timeout=30m $(GO_TEST_FILES) $(GO_TEST_OUTPUT) $(GO) test $(GO_RACE_FLAG) $(GO_TEST_FLAGS) -v -short -timeout=30m $(GO_TEST_FILES) $(GO_TEST_OUTPUT)
.PHONY: test-go-unit-cov .PHONY: test-go-unit-cov
test-go-unit-cov: ## Run unit tests for backend with flags and coverage test-go-unit-cov: ## Run unit tests for backend with flags and coverage
@echo "backend unit tests with coverage" @echo "backend unit tests with coverage"
$(GO) test $(GO_RACE_FLAG) -v -short $(if $(filter true,$(GO_UNIT_COVERAGE)),-covermode=atomic -coverprofile=$(GO_UNIT_COVER_PROFILE) $(if $(GO_UNIT_TEST_COVERPKG),-coverpkg=$(GO_UNIT_TEST_COVERPKG)),) -timeout=30m $(GO_TEST_FILES) $(GO_TEST_OUTPUT) $(GO) test $(GO_RACE_FLAG) $(GO_TEST_FLAGS) -v -short $(if $(filter true,$(GO_UNIT_COVERAGE)),-covermode=atomic -coverprofile=$(GO_UNIT_COVER_PROFILE) $(if $(GO_UNIT_TEST_COVERPKG),-coverpkg=$(GO_UNIT_TEST_COVERPKG)),) -timeout=30m $(GO_TEST_FILES) $(GO_TEST_OUTPUT)
.PHONY: test-go-unit-pretty .PHONY: test-go-unit-pretty
test-go-unit-pretty: check-tparse test-go-unit-pretty: check-tparse
@ -263,12 +264,12 @@ test-go-unit-pretty: check-tparse
echo "Notice: FILES variable is not set. Try \"make test-go-unit-pretty FILES=./pkg/services/mysvc\""; \ echo "Notice: FILES variable is not set. Try \"make test-go-unit-pretty FILES=./pkg/services/mysvc\""; \
exit 1; \ exit 1; \
fi fi
$(GO) test $(GO_RACE_FLAG) -timeout=10s $(FILES) -json | tparse -all $(GO) test $(GO_RACE_FLAG) $(GO_TEST_FLAGS) -timeout=10s $(FILES) -json | tparse -all
.PHONY: test-go-integration .PHONY: test-go-integration
test-go-integration: ## Run integration tests for backend with flags. test-go-integration: ## Run integration tests for backend with flags.
@echo "test backend integration tests" @echo "test backend integration tests"
$(GO) test $(GO_RACE_FLAG) -count=1 -run "^TestIntegration" -covermode=atomic -coverprofile=$(GO_INTEGRATION_COVER_PROFILE) -timeout=5m $(GO_INTEGRATION_TESTS) $(GO_TEST_OUTPUT) $(GO) test $(GO_RACE_FLAG) $(GO_TEST_FLAGS) -count=1 -run "^TestIntegration" -covermode=atomic -coverprofile=$(GO_INTEGRATION_COVER_PROFILE) -timeout=5m $(GO_INTEGRATION_TESTS) $(GO_TEST_OUTPUT)
.PHONY: test-go-integration-alertmanager .PHONY: test-go-integration-alertmanager
test-go-integration-alertmanager: ## Run integration tests for the remote alertmanager (config taken from the mimir_backend block). test-go-integration-alertmanager: ## Run integration tests for the remote alertmanager (config taken from the mimir_backend block).
@ -290,25 +291,25 @@ test-go-integration-postgres: devenv-postgres ## Run integration tests for postg
@echo "test backend integration postgres tests" @echo "test backend integration postgres tests"
$(GO) clean -testcache $(GO) clean -testcache
GRAFANA_TEST_DB=postgres \ GRAFANA_TEST_DB=postgres \
$(GO) test $(GO_RACE_FLAG) -p=1 -count=1 -run "^TestIntegration" -covermode=atomic -timeout=10m $(GO_INTEGRATION_TESTS) $(GO) test $(GO_RACE_FLAG) $(GO_TEST_FLAGS) -p=1 -count=1 -run "^TestIntegration" -covermode=atomic -timeout=10m $(GO_INTEGRATION_TESTS)
.PHONY: test-go-integration-mysql .PHONY: test-go-integration-mysql
test-go-integration-mysql: devenv-mysql ## Run integration tests for mysql backend with flags. test-go-integration-mysql: devenv-mysql ## Run integration tests for mysql backend with flags.
@echo "test backend integration mysql tests" @echo "test backend integration mysql tests"
GRAFANA_TEST_DB=mysql \ GRAFANA_TEST_DB=mysql \
$(GO) test $(GO_RACE_FLAG) -p=1 -count=1 -run "^TestIntegration" -covermode=atomic -timeout=10m $(GO_INTEGRATION_TESTS) $(GO) test $(GO_RACE_FLAG) $(GO_TEST_FLAGS) -p=1 -count=1 -run "^TestIntegration" -covermode=atomic -timeout=10m $(GO_INTEGRATION_TESTS)
.PHONY: test-go-integration-redis .PHONY: test-go-integration-redis
test-go-integration-redis: ## Run integration tests for redis cache. test-go-integration-redis: ## Run integration tests for redis cache.
@echo "test backend integration redis tests" @echo "test backend integration redis tests"
$(GO) clean -testcache $(GO) clean -testcache
REDIS_URL=localhost:6379 $(GO) test $(GO_RACE_FLAG) -run IntegrationRedis -covermode=atomic -timeout=2m $(GO_INTEGRATION_TESTS) REDIS_URL=localhost:6379 $(GO) test $(GO_TEST_FLAGS) -run IntegrationRedis -covermode=atomic -timeout=2m $(GO_INTEGRATION_TESTS)
.PHONY: test-go-integration-memcached .PHONY: test-go-integration-memcached
test-go-integration-memcached: ## Run integration tests for memcached cache. test-go-integration-memcached: ## Run integration tests for memcached cache.
@echo "test backend integration memcached tests" @echo "test backend integration memcached tests"
$(GO) clean -testcache $(GO) clean -testcache
MEMCACHED_HOSTS=localhost:11211 $(GO) test $(GO_RACE_FLAG) -run IntegrationMemcached -covermode=atomic -timeout=2m $(GO_INTEGRATION_TESTS) MEMCACHED_HOSTS=localhost:11211 $(GO) test $(GO_RACE_FLAG) $(GO_TEST_FLAGS) -run IntegrationMemcached -covermode=atomic -timeout=2m $(GO_INTEGRATION_TESTS)
.PHONY: test-js .PHONY: test-js
test-js: ## Run tests for frontend. test-js: ## Run tests for frontend.
@ -324,6 +325,7 @@ golangci-lint:
@echo "lint via golangci-lint" @echo "lint via golangci-lint"
$(GO) tool golangci-lint run \ $(GO) tool golangci-lint run \
--config .golangci.yml \ --config .golangci.yml \
$(if $(GO_BUILD_TAGS),--build-tags $(GO_BUILD_TAGS)) \
$(GO_LINT_FILES) $(GO_LINT_FILES)
.PHONY: lint-go .PHONY: lint-go

Loading…
Cancel
Save