Makefile: add lint check for Go version in Dockerfile and YAML

Implemented linter scripts to ensure consistency of the Go version
specified in Dockerfiles and YAML files. These scripts verify that the
Go version used across these files is uniform, enhancing maintainability
and reducing configuration errors.

This commit also introduces a `GO_VERSION` Makefile variable to control
the Go version used throughout the project.
This commit is contained in:
ffranr
2023-11-20 18:19:43 +00:00
parent 077e6682fa
commit 2a6e54016f
3 changed files with 162 additions and 2 deletions

View File

@@ -32,6 +32,11 @@ ifeq ($(shell expr $(ACTIVE_GO_VERSION_MINOR) \>= 21), 1)
LOOPVARFIX := GOEXPERIMENT=loopvar
endif
# GO_VERSION is the Go version used for the release build, docker files, and
# GitHub Actions. This is the reference version for the project. All other Go
# versions are checked against this version.
GO_VERSION = 1.22.5
GOBUILD := $(LOOPVARFIX) go build -v
GOINSTALL := $(LOOPVARFIX) go install -v
GOTEST := $(LOOPVARFIX) go test
@@ -298,11 +303,27 @@ fmt-check: fmt
@$(call print, "Checking fmt results.")
if test -n "$$(git status --porcelain)"; then echo "code not formatted correctly, please run `make fmt` again!"; git status; git diff; exit 1; fi
#? lint: Run static code analysis
lint: docker-tools
#? check-go-version-yaml: Verify that the Go version is correct in all YAML files
check-go-version-yaml:
@$(call print, "Checking for target Go version (v$(GO_VERSION)) in YAML files (*.yaml, *.yml)")
./scripts/check-go-version-yaml.sh $(GO_VERSION)
#? check-go-version-dockerfile: Verify that the Go version is correct in all Dockerfile files
check-go-version-dockerfile:
@$(call print, "Checking for target Go version (v$(GO_VERSION)) in Dockerfile files (*Dockerfile)")
./scripts/check-go-version-dockerfile.sh $(GO_VERSION)
#? check-go-version: Verify that the Go version is correct in all project files
check-go-version: check-go-version-dockerfile check-go-version-yaml
#? lint-source: Run static code analysis
lint-source: docker-tools
@$(call print, "Linting source.")
$(DOCKER_TOOLS) golangci-lint run -v $(LINT_WORKERS)
#? lint: Run static code analysis
lint: check-go-version lint-source
#? protolint: Lint proto files using protolint
protolint:
@$(call print, "Linting proto files.")