diff --git a/.github/workflows/code-static-check.yml b/.github/workflows/code-static-check.yml new file mode 100644 index 0000000..d0c2cb6 --- /dev/null +++ b/.github/workflows/code-static-check.yml @@ -0,0 +1,25 @@ +name: Code Static Check + +on: + pull_request: + branches: + - main + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3 + - uses: bufbuild/buf-setup-action@9990c72db080fa39cf561230b8d2d7b736681f85 # v1.30.1 + with: + version: "1.28.1" + - uses: actions/setup-go@v4 + with: + go-version: 1.22.2 + - name: Run Buf Lint + run: buf lint + - name: Run Buf format + run: buf format -d --exit-code + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 diff --git a/buf.yaml b/buf.yaml index 75e6afc..45d1085 100644 --- a/buf.yaml +++ b/buf.yaml @@ -3,3 +3,12 @@ name: buf.build/shibukazu/open-ve deps: - buf.build/googleapis/googleapis - buf.build/grpc-ecosystem/grpc-gateway +breaking: + use: + - FILE +lint: + use: + - DEFAULT + except: + - PACKAGE_VERSION_SUFFIX + - PACKAGE_DIRECTORY_MATCH diff --git a/go/pkg/dsl/dsl.go b/go/pkg/dsl/dsl.go index 33cdee9..2cfeefa 100644 --- a/go/pkg/dsl/dsl.go +++ b/go/pkg/dsl/dsl.go @@ -138,7 +138,7 @@ func (r *DSLReader) parseAndSaveDSL(dsl *DSL) error { return err } if err := r.redis.Set(GetVariablesID(v.ID), variablesBytes, 0).Err(); err != nil { - failure.Translate(err, appError.ErrRedisOperationFailed) + return failure.Translate(err, appError.ErrRedisOperationFailed) } celVariables, err := ToCELVariables(v.Variables) diff --git a/proto/dsl/v1/dsl.proto b/proto/dsl/v1/dsl.proto index 02c86f1..c2d095f 100644 --- a/proto/dsl/v1/dsl.proto +++ b/proto/dsl/v1/dsl.proto @@ -5,32 +5,29 @@ import "google/api/annotations.proto"; import "google/api/field_behavior.proto"; import "protoc-gen-openapiv2/options/annotations.proto"; - option go_package = "proto/dsl/v1"; message Validation { - string id = 1 [ - (google.api.field_behavior) = REQUIRED, - (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {example: "\"price\""} - ]; - string cel = 2 [ - (google.api.field_behavior) = REQUIRED, - (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {example: "\"number % 3 == 0 || number < 5\""} - ]; - repeated Variable variables = 3 [ - (google.api.field_behavior) = REQUIRED - ]; + string id = 1 [ + (google.api.field_behavior) = REQUIRED, + (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {example: "\"price\""} + ]; + string cel = 2 [ + (google.api.field_behavior) = REQUIRED, + (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {example: "\"number % 3 == 0 || number < 5\""} + ]; + repeated Variable variables = 3 [(google.api.field_behavior) = REQUIRED]; } message Variable { - string name = 1 [ - (google.api.field_behavior) = REQUIRED, - (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {example: "\"number\""} - ]; - string type = 2 [ - (google.api.field_behavior) = REQUIRED, - (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {example: "\"int\""} - ]; + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {example: "\"number\""} + ]; + string type = 2 [ + (google.api.field_behavior) = REQUIRED, + (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {example: "\"int\""} + ]; } message RegisterRequest { @@ -57,16 +54,14 @@ service DSLService { tags: ["DSL"] operation_id: "Register" }; - }; + } rpc Read(ReadRequest) returns (ReadResponse) { - option (google.api.http) = { - get: "/v1/dsl" - }; + option (google.api.http) = {get: "/v1/dsl"}; option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = { summary: "Read DSL" tags: ["DSL"] operation_id: "Read" }; - }; + } } diff --git a/proto/openapi/v1/openapi.proto b/proto/openapi/v1/openapi.proto index 874d94c..2ee14df 100644 --- a/proto/openapi/v1/openapi.proto +++ b/proto/openapi/v1/openapi.proto @@ -5,18 +5,17 @@ package openapi.v1; import "protoc-gen-openapiv2/options/annotations.proto"; option go_package = "proto/validate/v1"; - option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { info: { - title: "Open-VE"; - description: "Centralized and Consistent Data Validation Engine"; - version: "1.0"; + title: "Open-VE" + description: "Centralized and Consistent Data Validation Engine" + version: "1.0" contact: { - name: "Open-VE"; - url: "https://github.com/shibukazu/open-ve"; - }; - }; - consumes: "application/json"; - produces: "application/json"; - schemes: HTTPS; -}; \ No newline at end of file + name: "Open-VE" + url: "https://github.com/shibukazu/open-ve" + } + } + consumes: "application/json" + produces: "application/json" + schemes: HTTPS +}; diff --git a/proto/validate/v1/validate.proto b/proto/validate/v1/validate.proto index bac058a..e7cae9b 100644 --- a/proto/validate/v1/validate.proto +++ b/proto/validate/v1/validate.proto @@ -1,9 +1,9 @@ syntax = "proto3"; package validate.v1; -import "google/protobuf/any.proto"; import "google/api/annotations.proto"; import "google/api/field_behavior.proto"; +import "google/protobuf/any.proto"; import "protoc-gen-openapiv2/options/annotations.proto"; option go_package = "proto/validate/v1"; @@ -43,4 +43,4 @@ service ValidateService { operation_id: "Check" }; } -} \ No newline at end of file +}