diff --git a/.github/workflows/buf.yaml b/.github/workflows/buf.yaml index 4c83cf2..eb068f6 100644 --- a/.github/workflows/buf.yaml +++ b/.github/workflows/buf.yaml @@ -1,17 +1,15 @@ name: Buf on: - pull_request: - paths: - - 'proto/**' push: - paths: - - 'proto/**' - delete: - paths: - - 'proto/**' + branches: [ main ] + tags: [ 'v*' ] + pull_request: + branches: [ main ] + workflow_dispatch: { } # support manual runs -env: - BUF_TOKEN: ${{ secrets.BUF_TOKEN }} +permissions: + contents: read + pull-requests: write jobs: validate-protos: @@ -22,17 +20,16 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: - fetch-depth: 1 - - name: Install buf - uses: bufbuild/buf-setup-action@v1 + fetch-depth: 2 + - name: Buf CI + uses: bufbuild/buf-action@v1 with: github_token: ${{ github.token }} - - name: Buf format - run: buf format -d --exit-code - - name: Buf lint - uses: bufbuild/buf-lint-action@v1 - - name: Buf generate - run: | - mkdir -p .tmp/bin - cp $(which buf) .tmp/bin/buf - make checkgenerate + token: ${{ secrets.BUF_TOKEN }} + format: true + lint: true + breaking: true + push: false + archive: false + - name: Check Generate + run: make checkgenerate diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0a084fd..44b8f55 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,7 +18,11 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go-version: [ 1.20.x, 1.21.x, 1.22.x ] + go-version: + - 1.20.x + - 1.21.x + - 1.22.x + - 1.23.x steps: - name: Checkout code uses: actions/checkout@v4 @@ -33,8 +37,5 @@ jobs: - name: Lint # Often, lint guidelines depend on the Go version. To prevent # conflicting guidance, run only on the most recent supported version. - if: matrix.go-version == '1.22.x' - run: make lint - - name: Check Generate - if: matrix.go-version == '1.22.x' - run: make checkgenerate \ No newline at end of file + if: matrix.go-version == '1.23.x' + run: make lint-go diff --git a/Makefile b/Makefile index cec72b5..afc47d1 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ LICENSE_IGNORE := -e internal/testdata/ # Set to use a different compiler. For example, `GO=go1.18rc1 make test`. GO ?= go ARGS ?= --strict --strict_message --strict_error -GOLANGCI_LINT_VERSION ?= v1.59.1 +GOLANGCI_LINT_VERSION ?= v1.60.1 # Set to use a different version of protovalidate-conformance. # Should be kept in sync with the version referenced in proto/buf.lock and # 'buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go' in go.mod. diff --git a/proto/tests/example/v1/example.proto b/proto/tests/example/v1/example.proto index 4ea069e..1dee77a 100644 --- a/proto/tests/example/v1/example.proto +++ b/proto/tests/example/v1/example.proto @@ -24,8 +24,8 @@ message Person { string email = 2 [(buf.validate.field).string.email = true]; string name = 3 [(buf.validate.field).string = { - pattern: "^[[:alpha:]]+( [[:alpha:]]+)*$", - max_bytes: 256, + pattern: "^[[:alpha:]]+( [[:alpha:]]+)*$" + max_bytes: 256 }]; Coordinates home = 4; @@ -33,11 +33,11 @@ message Person { message Coordinates { double lat = 1 [(buf.validate.field).double = { - gte: -90, + gte: -90 lte: 90 }]; double lng = 2 [(buf.validate.field).double = { - gte: -180, + gte: -180 lte: 180 }]; } diff --git a/proto/tests/example/v1/legacy.proto b/proto/tests/example/v1/legacy.proto index c065b21..d438a75 100644 --- a/proto/tests/example/v1/legacy.proto +++ b/proto/tests/example/v1/legacy.proto @@ -113,7 +113,7 @@ message LegacyMixedFields { message LegacyIgnoreEmpty { int32 x = 1 [(validate.rules).int32 = { - gt: 123, + gt: 123 ignore_empty: true }]; } diff --git a/proto/tests/example/v1/validations.proto b/proto/tests/example/v1/validations.proto index 8de169d..c258fbf 100644 --- a/proto/tests/example/v1/validations.proto +++ b/proto/tests/example/v1/validations.proto @@ -23,29 +23,29 @@ import "google/protobuf/field_mask.proto"; message HasMsgExprs { option (buf.validate.message).cel = { - id: "x_lt_y", - message: "x must be less than y", - expression: "this.x < this.y", + id: "x_lt_y" + message: "x must be less than y" + expression: "this.x < this.y" }; option (buf.validate.message).cel = { - id: "y_gt_42", + id: "y_gt_42" expression: "this.y > 42 ? ''" - ": 'y must be greater than 42'", + ": 'y must be greater than 42'" }; int32 x = 1 [ (buf.validate.field).cel = { - id: "x_even", - message: "x must be even", + id: "x_even" + message: "x must be even" expression: "this % 2 == 0" }, (buf.validate.field).cel = { - id: "x_coprime_3", + id: "x_coprime_3" expression: "this % 3 != 0 ? ''" - ": 'x must not be divisible by 3'", + ": 'x must not be divisible by 3'" } ]; int32 y = 2; @@ -53,16 +53,16 @@ message HasMsgExprs { message SelfRecursive { option (buf.validate.message).cel = { - id: "unique_turtles", - message: "adjacent turtles must be unique", - expression: "this.x != this.turtle.x", + id: "unique_turtles" + message: "adjacent turtles must be unique" + expression: "this.x != this.turtle.x" }; int32 x = 1; SelfRecursive turtle = 2 [(buf.validate.field).cel = { - id: "non_zero_baby_turtle", - message: "embedded turtle's x value must not be zero", - expression: "this.x > 0", + id: "non_zero_baby_turtle" + message: "embedded turtle's x value must not be zero" + expression: "this.x > 0" }]; } @@ -76,15 +76,15 @@ message LoopRecursiveB { message MsgHasOneof { option (buf.validate.message).cel = { - id: "test x", + id: "test x" expression: "this.x == '' ? '' : \n" - "!this.x.startsWith('foo') ? 'does not have prefix `foo`' : ''", + "!this.x.startsWith('foo') ? 'does not have prefix `foo`' : ''" }; option (buf.validate.message).cel = { - id: "text y", - expression: "this.y >= 0", + id: "text y" + expression: "this.y >= 0" }; oneof o { @@ -97,16 +97,16 @@ message MsgHasOneof { message MsgHasRepeated { repeated float x = 1 [(buf.validate.field).repeated = { - max_items: 3, - min_items: 1, + max_items: 3 + min_items: 1 items: { cel: { - expression: "true", + expression: "true" message: "intentional false" } float: {gt: 0} } - unique: true, + unique: true }]; repeated string y = 2 [(buf.validate.field).repeated.unique = true]; repeated HasMsgExprs z = 3 [(buf.validate.field).repeated = {max_items: 2}]; @@ -114,10 +114,10 @@ message MsgHasRepeated { message MsgHasMap { map int32map = 1 [(buf.validate.field).map = { - min_pairs: 3, + min_pairs: 3 keys: { int32: {gt: 0} - }, + } values: { int32: {lt: 0} } @@ -128,16 +128,16 @@ message MsgHasMap { message TransitiveFieldConstraint { google.protobuf.FieldMask mask = 1 [(buf.validate.field).cel = { - id: "mask.paths", - message: "mask.paths must not be empty", - expression: "has(this.paths)", + id: "mask.paths" + message: "mask.paths must not be empty" + expression: "has(this.paths)" }]; } message MultipleStepsTransitiveFieldConstraints { google.protobuf.Api api = 1 [(buf.validate.field).cel = { - id: "api.source_context.file_name", - message: "api's source context file name must not be empty", + id: "api.source_context.file_name" + message: "api's source context file name must not be empty" expression: "has(this.source_context.file_name)" }]; } @@ -148,8 +148,8 @@ message Simple { message FieldOfTypeAny { google.protobuf.Any any = 1 [(buf.validate.field).cel = { - id: "any_type", - message: "this should never fail", + id: "any_type" + message: "this should never fail" expression: "this == this" }]; } @@ -157,7 +157,7 @@ message FieldOfTypeAny { // https://github.com/bufbuild/protovalidate/issues/92 message CelMapOnARepeated { repeated Value values = 1 [(buf.validate.field).cel = { - id: "env.vars.unique", + id: "env.vars.unique" expression: "this.map(v, v.name).unique() ? '' : 'value names must be unique'" }]; @@ -168,7 +168,7 @@ message CelMapOnARepeated { message RepeatedItemCel { repeated string paths = 1 [(buf.validate.field).repeated.items.cel = { - id: "paths.no_space", + id: "paths.no_space" expression: "!this.startsWith(' ')" }]; }