mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 00:05:18 +00:00
774e2efce8
* chore(lint): Update local make lint to match CI This updates the `make lint` behavior to match the command being run in CI. In addition, we refactor the make lint command to use docker in order to to ease cross platform install, use a local build cache that integrates with make clean, use the same version file, and encapsulate the logic in its own make include. We also remove the old lint logic as to not introduce a duplicate target and avoid confusion from a difference in behavior. While solutions like act for running github actions locally work, it is not as straightfoward, is slower, and uses the local git repository instead of a clone (though I am not sure how the checkout step works within act). * fix(lint): Use shared timeout with .golangci.yml Instead of using a local and different timeout in the lint makefile target we can rely on golangci to load this configuration from .golangci.yml instead and share this setting with CI. * fix(lint): Fix golangci-lint cache mount path This uses the correct cache dir default of ~/.cache enabling use of cache between lint calls. * fix(lint): Fix lint caching This includes a couple fixes - 1) It adds support for full caching of go mod and go build, speeding up the lint process quite a bit. And 2) does not mix lint cache with make clean files -- the docker container creates root owned files that cause make clean to error and we choose not to require make clean to run with higher permissions. The cache must be deleted manually.
46 lines
1.6 KiB
Makefile
46 lines
1.6 KiB
Makefile
################################################################################
|
|
### Required Variables ###
|
|
################################################################################
|
|
ifndef DOCKER
|
|
$(error DOCKER not set)
|
|
endif
|
|
|
|
ifndef BUILD_DIR
|
|
$(error BUILD_DIR not set)
|
|
endif
|
|
|
|
################################################################################
|
|
### Lint Settings ###
|
|
################################################################################
|
|
|
|
LINT_FROM_REV ?= $(shell git merge-base origin/master HEAD)
|
|
|
|
GOLANGCI_VERSION ?= $(shell cat .golangci-version)
|
|
GOLANGCI_IMAGE_TAG ?= golangci/golangci-lint:$(GOLANGCI_VERSION)
|
|
|
|
GOLANGCI_DIR ?= $(CURDIR)/$(BUILD_DIR)/.golangci-lint
|
|
|
|
GOLANGCI_CACHE_DIR ?= $(GOLANGCI_DIR)/$(GOLANGCI_VERSION)-cache
|
|
GOLANGCI_MOD_CACHE_DIR ?= $(GOLANGCI_DIR)/go-mod
|
|
|
|
################################################################################
|
|
### Lint Target ###
|
|
################################################################################
|
|
|
|
.PHONY: lint
|
|
lint: $(GOLANGCI_CACHE_DIR) $(GOLANGCI_MOD_CACHE_DIR)
|
|
@echo "Running lint from rev $(LINT_FROM_REV), use LINT_FROM_REV var to override."
|
|
$(DOCKER) run -t --rm \
|
|
-v $(GOLANGCI_CACHE_DIR):/root/.cache \
|
|
-v $(GOLANGCI_MOD_CACHE_DIR):/go/pkg/mod \
|
|
-v $(CURDIR):/app \
|
|
-w /app \
|
|
$(GOLANGCI_IMAGE_TAG) \
|
|
golangci-lint run -v --new-from-rev $(LINT_FROM_REV)
|
|
|
|
$(GOLANGCI_CACHE_DIR):
|
|
@mkdir -p $@
|
|
|
|
$(GOLANGCI_MOD_CACHE_DIR):
|
|
@mkdir -p $@
|