Skip to content

Commit

Permalink
Make copyfrommakego (#2838)
Browse files Browse the repository at this point in the history
  • Loading branch information
bufdev authored Mar 24, 2024
1 parent 0190449 commit 23ec3e0
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 15 deletions.
7 changes: 6 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
run:
skip-dirs-use-default: false
exclude-dirs-use-default: false
linters-settings:
errcheck:
check-type-assertions: true
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions make/buf/all.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion make/go/base.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions make/go/dep_buf.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions make/go/dep_golangci_lint.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions make/go/dep_protoc_gen_connect_go.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 42 additions & 0 deletions make/go/dep_yq.mk
Original file line number Diff line number Diff line change
@@ -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)
18 changes: 13 additions & 5 deletions make/go/go.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -39,6 +42,7 @@ else
GO_TEST_FLAGS :=
endif


.DEFAULT_GOAL := shortall

.PHONY: all
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand Down
67 changes: 67 additions & 0 deletions make/go/scripts/checknolintlint.bash
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions windows/test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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/://')"
Expand Down

0 comments on commit 23ec3e0

Please sign in to comment.