From 23ec3e0d6c761be21a81003a0835412a246e69a0 Mon Sep 17 00:00:00 2001 From: bufdev <4228796+bufdev@users.noreply.github.com> Date: Sun, 24 Mar 2024 22:51:57 +0100 Subject: [PATCH] Make copyfrommakego (#2838) --- .golangci.yml | 7 ++- make/buf/all.mk | 2 + make/go/base.mk | 2 +- make/go/dep_buf.mk | 4 +- make/go/dep_golangci_lint.mk | 4 +- make/go/dep_protoc_gen_connect_go.mk | 4 +- make/go/dep_yq.mk | 42 +++++++++++++++++ make/go/go.mk | 18 +++++--- make/go/scripts/checknolintlint.bash | 67 ++++++++++++++++++++++++++++ windows/test.bash | 4 +- 10 files changed, 139 insertions(+), 15 deletions(-) create mode 100644 make/go/dep_yq.mk create mode 100644 make/go/scripts/checknolintlint.bash diff --git a/.golangci.yml b/.golangci.yml index 5b44a56eb7..e04984f6ff 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,5 +1,5 @@ run: - skip-dirs-use-default: false + exclude-dirs-use-default: false linters-settings: errcheck: check-type-assertions: true @@ -30,6 +30,11 @@ linters-settings: alias: modulev1 - pkg: github.com/bufbuild/buf/private/gen/proto/go/buf/alpha/registry/v1alpha1 alias: registryv1alpha1 + nolintlint: + allow-unused: false + allow-no-explanation: [] + require-explanation: true + require-specific: true linters: enable: - asciicheck diff --git a/make/buf/all.mk b/make/buf/all.mk index 4be06597f4..0086d650f4 100644 --- a/make/buf/all.mk +++ b/make/buf/all.mk @@ -40,6 +40,8 @@ BUF_BREAKING_INPUT := . BUF_BREAKING_AGAINST_INPUT ?= .git\#branch=main BUF_FORMAT_INPUT := . +DISALLOW_NOLINT := true + include make/go/bootstrap.mk include make/go/dep_buf.mk include make/go/dep_minisign.mk diff --git a/make/go/base.mk b/make/go/base.mk index 9031bf73d1..615d685661 100644 --- a/make/go/base.mk +++ b/make/go/base.mk @@ -220,7 +220,7 @@ upgradenopost: copyfrommakego: @rm -rf $(TMP)/makego @mkdir -p $(TMP) - git clone $(MAKEGO_REMOTE) $(TMP)/makego + git clone --depth 1 $(MAKEGO_REMOTE) $(TMP)/makego rm -rf $(MAKEGO) cp -R $(TMP)/makego/make/go $(MAKEGO) @rm -rf $(TMP)/makego diff --git a/make/go/dep_buf.mk b/make/go/dep_buf.mk index aafa33bfe1..e5b8ff641b 100644 --- a/make/go/dep_buf.mk +++ b/make/go/dep_buf.mk @@ -7,8 +7,8 @@ $(call _assert_var,CACHE_VERSIONS) $(call _assert_var,CACHE_BIN) # Settable -# https://github.com/bufbuild/buf/releases 20240124 checked 20240126 -BUF_VERSION ?= v1.29.0 +# https://github.com/bufbuild/buf/releases 20240307 checked 20240320 +BUF_VERSION ?= v1.30.0 # Settable # # If set, this path will be installed every time someone depends on $(BUF) diff --git a/make/go/dep_golangci_lint.mk b/make/go/dep_golangci_lint.mk index 4cee6a5752..30ab2152d1 100644 --- a/make/go/dep_golangci_lint.mk +++ b/make/go/dep_golangci_lint.mk @@ -7,9 +7,9 @@ $(call _assert_var,CACHE_VERSIONS) $(call _assert_var,CACHE_BIN) # Settable -# https://github.com/golangci/golangci-lint/releases 20240208 checked 20240209 +# https://github.com/golangci/golangci-lint/releases 20240320 checked 20240320 # Contrast golangci-lint configuration with the one in https://github.com/connectrpc/connect-go/blob/main/.golangci.yml when upgrading -GOLANGCI_LINT_VERSION ?= v1.56.1 +GOLANGCI_LINT_VERSION ?= v1.57.1 GOLANGCI_LINT := $(CACHE_VERSIONS)/golangci-lint/$(GOLANGCI_LINT_VERSION) $(GOLANGCI_LINT): diff --git a/make/go/dep_protoc_gen_connect_go.mk b/make/go/dep_protoc_gen_connect_go.mk index 30d641026c..8ec4169ba5 100644 --- a/make/go/dep_protoc_gen_connect_go.mk +++ b/make/go/dep_protoc_gen_connect_go.mk @@ -7,8 +7,8 @@ $(call _assert_var,CACHE_VERSIONS) $(call _assert_var,CACHE_BIN) # Settable -# https://github.com/connectrpc/connect-go 20240216 checked 20240216 -CONNECT_VERSION ?= v1.15.0 +# https://github.com/connectrpc/connect-go 20240320 checked 20240320 +CONNECT_VERSION ?= v1.16.0 GO_GET_PKGS := $(GO_GET_PKGS) \ connectrpc.com/connect@$(CONNECT_VERSION) diff --git a/make/go/dep_yq.mk b/make/go/dep_yq.mk new file mode 100644 index 0000000000..fe347bba1c --- /dev/null +++ b/make/go/dep_yq.mk @@ -0,0 +1,42 @@ +# Managed by makego. DO NOT EDIT. + +# Must be set +$(call _assert_var,MAKEGO) +$(call _conditional_include,$(MAKEGO)/base.mk) +$(call _assert_var,UNAME_OS) +$(call _assert_var,UNAME_ARCH) +$(call _assert_var,CACHE_VERSIONS) +$(call _assert_var,CACHE_BIN) + +# Settable +# https://github.com/mikefarah/yq/releases 20240225 checked 20240320 +YQ_VERSION ?= v4.42.1 + +ifeq ($(UNAME_OS),Darwin) +YQ_OS := darwin +ifeq ($(UNAME_ARCH),x86_64) +YQ_ARCH := amd64 +endif +ifeq ($(UNAME_ARCH),arm64) +YQ_ARCH := arm64 +endif +endif + +ifeq ($(UNAME_ARCH),x86_64) +ifeq ($(UNAME_OS),Linux) +YQ_OS := linux +YQ_ARCH := amd64 +endif +endif + +YQ := $(CACHE_VERSIONS)/yq/$(YQ_VERSION) +$(YQ): + @rm -f $(CACHE_BIN)/yq + @mkdir -p $(CACHE_BIN) + curl -sSL \ + https://github.com/mikefarah/yq/releases/download/$(YQ_VERSION)/yq_$(YQ_OS)_$(YQ_ARCH) \ + -o $(CACHE_BIN)/yq + chmod +x $(CACHE_BIN)/yq + @rm -rf $(dir $(YQ)) + @mkdir -p $(dir $(YQ)) + @touch $(YQ) diff --git a/make/go/go.mk b/make/go/go.mk index 64ebd49036..b0d57276fd 100644 --- a/make/go/go.mk +++ b/make/go/go.mk @@ -4,6 +4,7 @@ $(call _assert_var,MAKEGO) $(call _conditional_include,$(MAKEGO)/base.mk) $(call _conditional_include,$(MAKEGO)/dep_golangci_lint.mk) +$(call _conditional_include,$(MAKEGO)/dep_yq.mk) # Must be set $(call _assert_var,GO_MODULE) $(call _assert_var,GOLANGCI_LINT) @@ -22,6 +23,8 @@ GO_MOD_VERSION ?= 1.20 GO_ALL_REPO_PKGS ?= ./cmd/... ./internal/... # Settable SKIP_GOLANGCI_LINT ?= +# Settable +DISALLOW_NOLINT ?= # Runtime GOPKGS ?= $(GO_ALL_REPO_PKGS) @@ -39,6 +42,7 @@ else GO_TEST_FLAGS := endif + .DEFAULT_GOAL := shortall .PHONY: all @@ -84,17 +88,21 @@ godeps: deps .PHONY: gofmtmodtidy gofmtmodtidy: @echo gofmt -s -w ALL_GO_FILES - @gofmt -s -w $(shell find . -name '*.go') + @gofmt -s -w . go mod tidy -v format:: gofmtmodtidy -.PHONY: checknonolint -checknonolint: - @if grep '//nolint' $(shell find . -name '*.go'); then \ +.PHONY: checknolintlint +checknolintlint: $(YQ) +ifneq ($(DISALLOW_NOLINT),) + @if grep -r --include "*.go" '//nolint'; then \ echo '//nolint directives found, surface ignores in .golangci.yml instead' >&2; \ exit 1; \ fi +else + bash $(MAKEGO)/scripts/checknolintlint.bash +endif .PHONY: golangcilint golangcilint: $(GOLANGCI_LINT) @@ -113,7 +121,7 @@ postlonglint:: .PHONY: shortlint shortlint: ## Run all linters but exclude long-running linters. @$(MAKE) checknodiffgenerated - @$(MAKE) checknonolint golangcilint postlint + @$(MAKE) checknolintlint golangcilint postlint .PHONY: lint lint: ## Run all linters. diff --git a/make/go/scripts/checknolintlint.bash b/make/go/scripts/checknolintlint.bash new file mode 100644 index 0000000000..6b41886bfa --- /dev/null +++ b/make/go/scripts/checknolintlint.bash @@ -0,0 +1,67 @@ +#!/usr/bin/env bash + +# Managed by makego. DO NOT EDIT. + +## checknolintlint exits with exit code 0 if nolintlint is enabled and configured according to standards. +## Otherwise, it exits with exit code 1. + +set -euo pipefail + +if [[ ! -f .golangci.yml ]]; then + echo "nolintlint not enabled in .golangci.yml" >&2 + exit 1 +fi + +# Check if nolintlint linter is enabled in config +NOLINTLINT_ENABLED=0 +if [[ `yq '.linters.enable // [] | any_c(. == "nolintlint")' .golangci.yml` == "true" ]]; then + # Enabled individually + NOLINTLINT_ENABLED=1 +elif [[ `yq '.linters.enable-all' .golangci.yml` == "true" ]]; then + # Enabled with enable-all + NOLINTLINT_ENABLED=1 +fi +if [ "${NOLINTLINT_ENABLED}" -eq 1 ]; then + # Ensure it isn't disabled individually + if [[ `yq '.linters.disable // [] | any_c(. == "nolintlint")' .golangci.yml` == "true" ]]; then + NOLINTLINT_ENABLED=0 + fi +fi +if [ "${NOLINTLINT_ENABLED}" -eq 0 ]; then + echo "nolintlint not enabled in .golangci.yml" >&2 + exit 1 +fi + +# Check if nolintlint is configured according to standards. +# +# linters-settings: +# nolintlint: +# allow-unused: false +# allow-no-explanation: [] +# require-explanation: true +# require-specific: true +# + +# These values will be set below by the yq command (if set in the file). +allow_unused= +require_explanation= +require_specific= +allow_no_explanation_0= + +eval $(yq --output-format shell '.linters-settings.nolintlint' .golangci.yml) +if [[ "${allow_unused}" != "false" ]]; then + echo ".golangci.yml: nolintlint allow-unused must be set to false" >&2 + exit 1 +fi +if [[ "${require_explanation}" != "true" ]]; then + echo ".golangci.yml: nolintlint require-explanation must be set to true" >&2 + exit 1 +fi +if [[ "${require_specific}" != "true" ]]; then + echo ".golangci.yml: nolintlint require-specific must be set to true" >&2 + exit 1 +fi +if [[ -n "${allow_no_explanation_0}" ]]; then + echo ".golangci.yml: nolintlint allow-no-explanation must be empty" >&2 + exit 1 +fi diff --git a/windows/test.bash b/windows/test.bash index ad0721c987..e27a41e165 100644 --- a/windows/test.bash +++ b/windows/test.bash @@ -3,8 +3,8 @@ set -eo pipefail PROTOC_VERSION="25.0" -PROTOC_GEN_GO_VERSION="v1.32.0" -CONNECT_VERSION="v1.14.0" +PROTOC_GEN_GO_VERSION="v1.33.0" +CONNECT_VERSION="v1.16.0" # Convert DOWNLOAD_CACHE from d:\path to /d/path DOWNLOAD_CACHE="$(echo "/${DOWNLOAD_CACHE}" | sed 's|\\|/|g' | sed 's/://')"