diff --git a/.github/workflows/buf.yaml b/.github/workflows/buf.yaml new file mode 100644 index 0000000..14202ee --- /dev/null +++ b/.github/workflows/buf.yaml @@ -0,0 +1,18 @@ +name: Buf +on: + push: + branches: [master] + paths: ['api/proto/**'] + pull_request: + paths: ['api/proto/**'] + +jobs: + buf: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: bufbuild/buf-action@v1 + with: + token: ${{ secrets.BUF_TOKEN }} + input: api/proto + push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} diff --git a/.gitignore b/.gitignore index 78d6394..94fbfc0 100644 --- a/.gitignore +++ b/.gitignore @@ -157,4 +157,7 @@ Temporary Items # End of https://www.toptal.com/developers/gitignore/api/macos,intellij,go -/myshoes* \ No newline at end of file +/myshoes* + +# Buf +.buf/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index b4b9421..6d5febe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,7 @@ WORKDIR /go/src/github.com/whywaita/myshoes RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.34.2 RUN go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.5.1 +RUN go install github.com/bufbuild/buf/cmd/buf@latest RUN apt-get update -y \ && apt-get install -y protobuf-compiler diff --git a/Makefile b/Makefile index a08aa06..1a07a75 100644 --- a/Makefile +++ b/Makefile @@ -17,13 +17,11 @@ build-linux: ## Build for Linux make build-proto GOOS=linux GOARCH=amd64 go build -o myshoes-linux-amd64 -ldflags $(BUILD_LDFLAGS) cmd/server/cmd.go -build-proto: ## Build proto file - mkdir -p tmp/proto-go - rm -rf api/proto.go +build-proto: ## Build proto file with buf + cd api/proto && buf generate - protoc -I=api/proto/ --go_out=tmp/proto-go/ --go-grpc_out=tmp/proto-go/ api/proto/**.proto - mv tmp/proto-go/github.com/whywaita/myshoes/api/proto.go api/ - rm -rf tmp +lint-proto: ## Lint proto files + cd api/proto && buf lint test: ## Exec test go test -v ./... \ No newline at end of file diff --git a/api/proto.go/myshoes.pb.go b/api/proto.go/myshoes.pb.go index 57e8fd5..4bc0c4c 100644 --- a/api/proto.go/myshoes.pb.go +++ b/api/proto.go/myshoes.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.36.11 -// protoc v5.29.3 +// protoc (unknown) // source: myshoes.proto package proto_go diff --git a/api/proto.go/myshoes_grpc.pb.go b/api/proto.go/myshoes_grpc.pb.go index 2fd1042..4bbdfbb 100644 --- a/api/proto.go/myshoes_grpc.pb.go +++ b/api/proto.go/myshoes_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.6.0 -// - protoc v5.29.3 +// - protoc (unknown) // source: myshoes.proto package proto_go diff --git a/api/proto/buf.gen.yaml b/api/proto/buf.gen.yaml new file mode 100644 index 0000000..1bd4b3b --- /dev/null +++ b/api/proto/buf.gen.yaml @@ -0,0 +1,11 @@ +version: v2 +clean: true +plugins: + - remote: buf.build/protocolbuffers/go + out: ../proto.go + opt: + - paths=source_relative + - remote: buf.build/grpc/go + out: ../proto.go + opt: + - paths=source_relative diff --git a/api/proto/buf.yaml b/api/proto/buf.yaml new file mode 100644 index 0000000..01b983d --- /dev/null +++ b/api/proto/buf.yaml @@ -0,0 +1,17 @@ +version: v2 +modules: + - path: . + name: buf.build/whywaita/myshoes +lint: + use: + - STANDARD + except: + - PACKAGE_DIRECTORY_MATCH + - ENUM_ZERO_VALUE_SUFFIX + - PACKAGE_VERSION_SUFFIX + - SERVICE_SUFFIX + - ENUM_VALUE_PREFIX + - ENUM_VALUE_UPPER_SNAKE_CASE +breaking: + use: + - FILE diff --git a/api/proto/myshoes.proto b/api/proto/myshoes.proto index 72ab027..c2c107b 100644 --- a/api/proto/myshoes.proto +++ b/api/proto/myshoes.proto @@ -1,6 +1,7 @@ syntax = "proto3"; package whywaita.myshoes; + option go_package = "github.com/whywaita/myshoes/api/proto.go"; service Shoes { @@ -40,4 +41,4 @@ message DeleteInstanceRequest { repeated string labels = 2; } -message DeleteInstanceResponse {} \ No newline at end of file +message DeleteInstanceResponse {}