Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@ LICENSE_IGNORE := -e internal/testdata/
GO ?= go
ARGS ?= --strict_message --strict_error
GOLANGCI_LINT_VERSION ?= v2.4.0
# Set to use a different version of protovalidate-conformance.
# Should be kept in sync with the version referenced in buf.yaml and
# 'buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go' in go.mod.
CONFORMANCE_VERSION ?= v1.1.0
# Set to use a different version of protovalidate
PROTOVALIDATE_VERSION ?= 895eefca6d1346f742fc18b9983d40478820906d
PROTOVALIDATE_RELEASE_VERSION := TRUE

PROTOVALIDATE_PROTO_PATH := buf.build/bufbuild/protovalidate:$(PROTOVALIDATE_VERSION)
PROTOVALIDATE_TESTING_PROTO_PATH := buf.build/bufbuild/protovalidate-testing:$(PROTOVALIDATE_VERSION)
ifneq ($(shell echo ${PROTOVALIDATE_VERSION} | grep -E "^v\d+\.\d+.\d+(-.+)?$$"), $(PROTOVALIDATE_VERSION))
PROTOVALIDATE_PROTO_PATH = https://github.com/bufbuild/protovalidate.git\#subdir=proto/protovalidate,ref=$(PROTOVALIDATE_VERSION)
PROTOVALIDATE_TESTING_PROTO_PATH = https://github.com/bufbuild/protovalidate.git\#subdir=proto/protovalidate-testing,ref=$(PROTOVALIDATE_VERSION)
PROTOVALIDATE_RELEASE_VERSION = FALSE
else
PROTOBUF_GO_VERSION := $(shell go list -json -m google.golang.org/protobuf | jq -r '.Version')
PROTOVALIDATE_GEN_SDK_VERSION := $(shell buf registry sdk version --module=buf.build/bufbuild/protovalidate:$(PROTOVALIDATE_VERSION) --plugin=buf.build/protocolbuffers/go:$(PROTOBUF_GO_VERSION))
endif

.PHONY: help
help: ## Describe useful make targets
Expand Down Expand Up @@ -49,7 +59,7 @@ lint-go: $(BIN)/golangci-lint
$(BIN)/golangci-lint fmt --diff

.PHONY: lint-proto
lint-proto: $(BIN)/buf
lint-proto: $(BIN)/buf upstream
$(BIN)/buf lint

.PHONY: lint-fix
Expand All @@ -70,10 +80,23 @@ generate: generate-proto generate-license ## Regenerate code and license headers
$(GO) mod tidy

.PHONY: generate-proto
generate-proto: $(BIN)/buf
generate-proto: $(BIN)/buf upstream
rm -rf internal/gen/*/
$(BIN)/buf generate buf.build/bufbuild/protovalidate-testing:$(CONFORMANCE_VERSION)
$(BIN)/buf generate
$(BIN)/buf generate $(PROTOVALIDATE_TESTING_PROTO_PATH)
$(BIN)/buf generate proto

.PHONY: upstream
upstream: $(BIN)/buf
rm -rf upstream
$(BIN)/buf export $(PROTOVALIDATE_PROTO_PATH) -o upstream/proto
ifeq ($(PROTOVALIDATE_RELEASE_VERSION), TRUE)
go mod edit -dropreplace=buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go
go get buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go@$(PROTOVALIDATE_GEN_SDK_VERSION)
else
$(BIN)/buf generate --template buf.gen.upstream.yaml $(PROTOVALIDATE_PROTO_PATH)
echo "go 1.24.0" >> upstream/module/go.mod
go mod edit -replace=buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go=./upstream/module
endif
Comment on lines +90 to +97
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although replace directive doesn't impact downstream users, this ensures that at release time the version matches gen sdk version and removes the replace directive


.PHONY: generate-license
generate-license: $(BIN)/license-header
Expand Down Expand Up @@ -132,7 +155,7 @@ $(BIN)/golangci-lint: $(BIN) Makefile

$(BIN)/protovalidate-conformance: $(BIN) Makefile
GOBIN=$(abspath $(BIN)) $(GO) install \
github.com/bufbuild/protovalidate/tools/protovalidate-conformance@$(CONFORMANCE_VERSION)
github.com/bufbuild/protovalidate/tools/protovalidate-conformance@$(PROTOVALIDATE_VERSION)

.PHONY: protovalidate-conformance-go
protovalidate-conformance-go: $(BIN)
Expand Down
8 changes: 8 additions & 0 deletions buf.gen.upstream.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: v2
clean: true
plugins:
- remote: buf.build/protocolbuffers/go:v1.36.6
out: upstream/module
opt:
- paths=source_relative
- default_api_level=API_HYBRID
3 changes: 0 additions & 3 deletions buf.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Generated by buf. DO NOT EDIT.
version: v2
deps:
- name: buf.build/bufbuild/protovalidate
commit: 2a1774d888024a9b93ce7eb4b59f6a83
digest: b5:6b7f9bc919b65e5b79d7b726ffc03d6f815a412d6b792970fa6f065cae162107bd0a9d47272c8ab1a2c9514e87b13d3fbf71df614374d62d2183afb64be2d30a
- name: buf.build/rodaine/protogofakeit
commit: 9caf0fc578d3413590962a1764b81b94
digest: b5:eeead7373f2f598ebc8f91aa3a68d6b50630076341d875b22dc6760126bc56c82cf1e98f5a2eff9815ba55fa48ab81745c93a5aeefd5e4697bf43c9ea4694735
7 changes: 5 additions & 2 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
version: v2
modules:
- path: proto
deps:
- buf.build/bufbuild/protovalidate:v1.1.0
- path: upstream/proto
name: buf.build/bufbuild/protovalidate
deps:
- buf.build/rodaine/protogofakeit
lint:
use:
Expand All @@ -12,6 +13,8 @@ lint:
- proto/tests/example/v1/validations.proto
- proto/tests/example/v1/filter.proto
- proto/tests/example/v1/compile.proto
ignore:
- upstream/proto
breaking:
use:
- FILE
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ require (
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go => ./upstream/module
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
buf.build/gen/go/bufbuild/hyperpb-examples/protocolbuffers/go v1.36.7-20250725192734-0dd56aa9cbbc.1 h1:bFnppdLYActzr2F0iomSrkjUnGgVufb0DtZxjKgTLGc=
buf.build/gen/go/bufbuild/hyperpb-examples/protocolbuffers/go v1.36.7-20250725192734-0dd56aa9cbbc.1/go.mod h1:x7jYNX5/7EPnsKHEq596krkOGzvR97/MsZw2fw3Mrq0=
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.11-20251209175733-2a1774d88802.1 h1:j9yeqTWEFrtimt8Nng2MIeRrpoCvQzM9/g25XTvqUGg=
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.11-20251209175733-2a1774d88802.1/go.mod h1:tvtbpgaVXZX4g6Pn+AnzFycuRK3MOz5HJfEGeEllXYM=
buf.build/go/hyperpb v0.1.3 h1:wiw2F7POvAe2VA2kkB0TAsFwj91lXbFrKM41D3ZgU1w=
buf.build/go/hyperpb v0.1.3/go.mod h1:IHXAM5qnS0/Fsnd7/HGDghFNvUET646WoHmq1FDZXIE=
cel.dev/expr v0.24.0 h1:56OvJKSH3hDGL0ml5uSxZmz3/3Pq4tJ+fb1unVLAFcY=
Expand Down
Loading