-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathMakefile
More file actions
106 lines (89 loc) · 3.98 KB
/
Makefile
File metadata and controls
106 lines (89 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# See https://tech.davis-hansson.com/p/make/
SHELL := bash
.DELETE_ON_ERROR:
.SHELLFLAGS := -eu -o pipefail -c
.DEFAULT_GOAL := all
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-print-directory
BIN := .tmp/bin
export PATH := $(BIN):$(PATH)
export GOBIN := $(abspath $(BIN))
export PYTHONPATH ?= gen
BUF_VERSION := 1.62.1
CONFORMANCE_ARGS ?= --strict_message --expected_failures=test/conformance/nonconforming.yaml --timeout 10s
ADD_LICENSE_HEADER := $(BIN)/license-header \
--license-type apache \
--copyright-holder "Buf Technologies, Inc." \
--year-range "2023-2025"
PROTOVALIDATE_VERSION ?= 895eefca6d1346f742fc18b9983d40478820906d
# Version of the cel-spec that this implementation is conformant with
# This should be kept in sync with the version in test/test_format.py
CEL_SPEC_VERSION ?= v0.25.1
TESTDATA_FILE := test/testdata/string_ext_$(CEL_SPEC_VERSION).textproto
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)
endif
.PHONY: help
help: ## Describe useful make targets
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "%-15s %s\n", $$1, $$2}'
.PHONY: all
all: test conformance lint ## Run all tests and lint (default)
.PHONY: clean
clean: ## Delete intermediate build artifacts
@# -X only removes untracked files, -d recurses into directories, -f actually removes files/dirs
git clean -Xdf
@echo $(CEL_SPEC_VERSION)
.PHONY: generate
generate: $(BIN)/buf $(BIN)/license-header upstream ## Regenerate code and license headers
rm -rf gen
$(BIN)/buf generate $(PROTOVALIDATE_PROTO_PATH)
$(BIN)/buf generate $(PROTOVALIDATE_TESTING_PROTO_PATH)
$(BIN)/buf generate buf.build/google/cel-spec:$(CEL_SPEC_VERSION) --exclude-path cel/expr/conformance/proto2 --exclude-path cel/expr/conformance/proto3
$(BIN)/buf generate
$(ADD_LICENSE_HEADER)
.PHONY: upstream
upstream: $(BIN)/buf
rm -rf upstream
$(BIN)/buf export $(PROTOVALIDATE_PROTO_PATH) -o upstream/proto
$(ADD_LICENSE_HEADER)
.PHONY: format
format: install $(BIN)/buf $(BIN)/license-header ## Format code
$(ADD_LICENSE_HEADER)
buf format --write .
uv run -- ruff format protovalidate test
uv run -- ruff check --fix protovalidate test
.PHONY: test
test: generate install $(TESTDATA_FILE) ## Run unit tests
uv run -- pytest
.PHONY: conformance
conformance: $(BIN)/protovalidate-conformance generate install ## Run conformance tests
protovalidate-conformance $(CONFORMANCE_ARGS) uv run test/conformance/runner.py
.PHONY: lint
lint: install $(BIN)/buf ## Lint code
buf format -d --exit-code
uv run -- ruff format --check --diff protovalidate test
uv run -- mypy protovalidate
uv run -- ruff check protovalidate test
uv lock --check
.PHONY: install
install: ## Install dependencies
uv sync --dev
.PHONY: checkgenerate
checkgenerate: generate
@# Used in CI to verify that `make generate` doesn't produce a diff.
test -z "$$(git status --porcelain | tee /dev/stderr)"
$(TESTDATA_FILE):
mkdir -p $(dir @)
curl -fsSL -o $@ https://raw.githubusercontent.com/google/cel-spec/refs/tags/$(CEL_SPEC_VERSION)/tests/simple/testdata/string_ext.textproto
$(BIN):
@mkdir -p $(BIN)
$(BIN)/buf: $(BIN) Makefile
go install github.com/bufbuild/buf/cmd/buf@v${BUF_VERSION}
$(BIN)/license-header: $(BIN) Makefile
go install github.com/bufbuild/buf/private/pkg/licenseheader/cmd/license-header@v${BUF_VERSION}
$(BIN)/protovalidate-conformance: $(BIN) Makefile
go install github.com/bufbuild/protovalidate/tools/protovalidate-conformance@$(PROTOVALIDATE_VERSION)