From 1250777a7265d9df98dc2623e7178abe33cdf4b0 Mon Sep 17 00:00:00 2001 From: ysugimoto Date: Sun, 28 Apr 2024 02:05:35 +0900 Subject: [PATCH 1/9] use github actions, update go and golangci-lint version --- .github/workflows/build.yml | 40 +++++++++++++++++++++++ .golangci.yml | 5 --- graphql/graphql.pb.go | 4 +-- protoc-gen-graphql/generator/generator.go | 2 +- protoc-gen-graphql/spec/enum.go | 2 +- protoc-gen-graphql/spec/file.go | 10 +++--- protoc-gen-graphql/spec/message.go | 2 +- protoc-gen-graphql/spec/mutation.go | 1 - protoc-gen-graphql/spec/params.go | 2 +- protoc-gen-graphql/spec/service.go | 2 +- 10 files changed, 52 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..69af6e8 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,40 @@ +name: Build application + +on: + push: {} + +env: + PROTOC_VERSION: 3.14.0 + GO_VERSION: 1.21.1 + +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup go + uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + - name: Setup protobuf + run: | + PROTOC_ZIP=protoc-${{ env.PROTOC_VERSION }}-linux-x86_64.zip + curl -OL https://github.com/google/protobuf/releases/download/v${{ env.PROTOC_VERSION }}/$PROTOC_ZIP + sudo unzip -o $PROTOC_ZIP -d /usr/local/protoc + sudo chmod +xr -R /usr/local/protoc + sudo ln -s /usr/local/protoc/bin/protoc /usr/local/bin + sudo ln -s /usr/local/protoc/include/google /usr/local/include/google + go get -u github.com/golang/protobuf/protoc-gen-go + - name: Lint programs + uses: golangci/golangci-lint-action@v3 + with: + version: v1.54 + skip-pkg-cache: true + skip-build-cache: true + skip-go-installation: true + - name: Build app + run: make all tag=ci + + diff --git a/.golangci.yml b/.golangci.yml index fde4c23..a9e59aa 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -26,11 +26,7 @@ linters: - staticcheck - unused - gosimple - - structcheck - - varcheck - ineffassign - - interfacer - - deadcode - dogsled - dupl - funlen @@ -41,7 +37,6 @@ linters: - gofmt - gomnd - lll - - maligned - misspell - whitespace - unparam diff --git a/graphql/graphql.pb.go b/graphql/graphql.pb.go index 943032e..6d22913 100644 --- a/graphql/graphql.pb.go +++ b/graphql/graphql.pb.go @@ -7,8 +7,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0 -// protoc v3.17.3 +// protoc-gen-go v1.27.1 +// protoc v3.21.12 // source: graphql.proto package graphql diff --git a/protoc-gen-graphql/generator/generator.go b/protoc-gen-graphql/generator/generator.go index 9464a97..b9fe70b 100644 --- a/protoc-gen-graphql/generator/generator.go +++ b/protoc-gen-graphql/generator/generator.go @@ -247,7 +247,7 @@ func (g *Generator) generateFile(file *spec.File, tmpl string, services []*spec. out, err := format.Source(buf.Bytes()) if err != nil { - ioutil.WriteFile("/tmp/"+root.Name+".go", buf.Bytes(), 0666) // nolint: errcheck + ioutil.WriteFile("/tmp/"+root.Name+".go", buf.Bytes(), 0o666) // nolint: gomnd,errcheck return nil, err } diff --git a/protoc-gen-graphql/spec/enum.go b/protoc-gen-graphql/spec/enum.go index a359ff7..15c1873 100644 --- a/protoc-gen-graphql/spec/enum.go +++ b/protoc-gen-graphql/spec/enum.go @@ -37,7 +37,7 @@ func NewEnum( for i, v := range d.GetValue() { ps := make([]int, len(paths)) copy(ps, paths) - e.values = append(e.values, NewEnumValue(v, f, append(ps, 2, i)...)) + e.values = append(e.values, NewEnumValue(v, f, append(ps, 2, i)...)) // nolint: gomnd } return e } diff --git a/protoc-gen-graphql/spec/file.go b/protoc-gen-graphql/spec/file.go index bc093aa..be628f4 100644 --- a/protoc-gen-graphql/spec/file.go +++ b/protoc-gen-graphql/spec/file.go @@ -42,13 +42,13 @@ func NewFile( isCamel: isCamel, } for i, s := range d.GetService() { - f.services = append(f.services, NewService(s, f, 6, i)) + f.services = append(f.services, NewService(s, f, 6, i)) // nolint: gomnd } for i, m := range d.GetMessageType() { - f.messages = append(f.messages, f.messagesRecursive(m, []string{}, 4, i)...) + f.messages = append(f.messages, f.messagesRecursive(m, []string{}, 4, i)...) // nolint: gomnd } for i, e := range d.GetEnumType() { - f.enums = append(f.enums, NewEnum(e, f, []string{}, 5, i)) + f.enums = append(f.enums, NewEnum(e, f, []string{}, 5, i)) // nolint: gomnd } return f } @@ -80,7 +80,7 @@ func (f *File) messagesRecursive(d *descriptor.DescriptorProto, prefix []string, for i, e := range d.GetEnumType() { p := make([]int, len(paths)) copy(p, paths) - f.enums = append(f.enums, NewEnum(e, f, prefix, append(p, 5, i)...)) + f.enums = append(f.enums, NewEnum(e, f, prefix, append(p, 5, i)...)) // nolint: gomnd } for i, m := range d.GetNestedType() { @@ -88,7 +88,7 @@ func (f *File) messagesRecursive(d *descriptor.DescriptorProto, prefix []string, copy(p, paths) messages = append( messages, - f.messagesRecursive(m, prefix, append(p, 3, i)...)..., + f.messagesRecursive(m, prefix, append(p, 3, i)...)..., // nolint: gomnd ) } return messages diff --git a/protoc-gen-graphql/spec/message.go b/protoc-gen-graphql/spec/message.go index b4cbbd4..65795d6 100644 --- a/protoc-gen-graphql/spec/message.go +++ b/protoc-gen-graphql/spec/message.go @@ -41,7 +41,7 @@ func NewMessage( for i, field := range d.GetField() { ps := make([]int, len(paths)) copy(ps, paths) - ff := NewField(field, f, isCamel, append(ps, 2, i)...) + ff := NewField(field, f, isCamel, append(ps, 2, i)...) // nolint: gomnd if !ff.IsOmit() { m.fields = append(m.fields, ff) } diff --git a/protoc-gen-graphql/spec/mutation.go b/protoc-gen-graphql/spec/mutation.go index cdfce74..fa69dd0 100644 --- a/protoc-gen-graphql/spec/mutation.go +++ b/protoc-gen-graphql/spec/mutation.go @@ -159,7 +159,6 @@ func (m *Mutation) OutputName() string { return typeName } -// func (m *Mutation) InputType() string { if m.Method.GoPackage() != m.Input.GoPackage() { return m.Input.StructName(false) diff --git a/protoc-gen-graphql/spec/params.go b/protoc-gen-graphql/spec/params.go index 5fb89e0..fd99c34 100644 --- a/protoc-gen-graphql/spec/params.go +++ b/protoc-gen-graphql/spec/params.go @@ -29,7 +29,7 @@ func NewParams(p string) (*Params, error) { } for _, v := range strings.Split(p, ",") { - kv := strings.SplitN(v, "=", 2) + kv := strings.SplitN(v, "=", 2) // nolint: gomnd switch kv[0] { case "verbose": params.Verbose = true diff --git a/protoc-gen-graphql/spec/service.go b/protoc-gen-graphql/spec/service.go index 5a3e577..a54b89d 100644 --- a/protoc-gen-graphql/spec/service.go +++ b/protoc-gen-graphql/spec/service.go @@ -47,7 +47,7 @@ func NewService( for i, m := range d.GetMethod() { ps := make([]int, len(paths)) copy(ps, paths) - s.methods = append(s.methods, NewMethod(m, s, append(ps, 4, i)...)) + s.methods = append(s.methods, NewMethod(m, s, append(ps, 4, i)...)) // nolint: gomnd } return s } From 646517c85c0b6cfb82dc61ff0b7284750d5be561 Mon Sep 17 00:00:00 2001 From: ysugimoto Date: Sun, 28 Apr 2024 02:10:22 +0900 Subject: [PATCH 2/9] fix actions --- .github/workflows/build.yml | 5 +++-- go.mod | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 69af6e8..e92fbc3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,7 +26,6 @@ jobs: sudo chmod +xr -R /usr/local/protoc sudo ln -s /usr/local/protoc/bin/protoc /usr/local/bin sudo ln -s /usr/local/protoc/include/google /usr/local/include/google - go get -u github.com/golang/protobuf/protoc-gen-go - name: Lint programs uses: golangci/golangci-lint-action@v3 with: @@ -35,6 +34,8 @@ jobs: skip-build-cache: true skip-go-installation: true - name: Build app - run: make all tag=ci + run: | + go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.31.0 + make all tag=ci diff --git a/go.mod b/go.mod index d749aaa..c37dd44 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/ysugimoto/grpc-graphql-gateway -go 1.15 +go 1.21 require ( github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0 From 87f96bb96f48b51e5a3b7651ed83bd55717dc45f Mon Sep 17 00:00:00 2001 From: ysugimoto Date: Sun, 28 Apr 2024 02:19:29 +0900 Subject: [PATCH 3/9] use golang 1.21.1 --- .golangci.yml | 6 +----- go.mod | 12 ++++++++++-- go.sum | 2 -- protoc-gen-graphql/generator/generator.go | 6 +++--- runtime/request.go | 4 ++-- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index a9e59aa..b549c71 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,7 +10,7 @@ run: issues: exclude-rules: - ## Add file patters to exclude linter + ## Add file patterns to exclude linter - path: grpc\/main\.go linters: - gomnd @@ -132,16 +132,12 @@ linters-settings: simplify: true golint: min-confidence: 0.8 - govet: - check-shadowing: true gomnd: settings: mnd: checks: argument,assign,operation,return lll: line-length: 120 - maligned: - suggest-new: true misspell: locale: US ignore-words: diff --git a/go.mod b/go.mod index c37dd44..23c966e 100644 --- a/go.mod +++ b/go.mod @@ -6,9 +6,17 @@ require ( github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0 github.com/graphql-go/graphql v0.7.8 github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334 - github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.6.1 - golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae // indirect google.golang.org/grpc v1.27.0 google.golang.org/protobuf v1.21.0 ) + +require ( + github.com/davecgh/go-spew v1.1.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + golang.org/x/net v0.0.0-20190311183353-d8887717615a // indirect + golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae // indirect + golang.org/x/text v0.3.0 // indirect + google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 // indirect + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect +) diff --git a/go.sum b/go.sum index 576bdaa..7bf60f6 100644 --- a/go.sum +++ b/go.sum @@ -25,8 +25,6 @@ github.com/graphql-go/graphql v0.7.8 h1:769CR/2JNAhLG9+aa8pfLkKdR0H+r5lsQqling5W github.com/graphql-go/graphql v0.7.8/go.mod h1:k6yrAYQaSP59DC5UVxbgxESlmVyojThKdORUqGDGmrI= github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334 h1:VHgatEHNcBFEB7inlalqfNqw65aNkM1lGX2yt3NmbS8= github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= diff --git a/protoc-gen-graphql/generator/generator.go b/protoc-gen-graphql/generator/generator.go index b9fe70b..28f1278 100644 --- a/protoc-gen-graphql/generator/generator.go +++ b/protoc-gen-graphql/generator/generator.go @@ -4,11 +4,11 @@ import ( "bytes" "errors" "fmt" + "io" "os" "sort" "go/format" - "io/ioutil" "text/template" // nolint: staticcheck @@ -53,7 +53,7 @@ func New(files []*spec.File, args *spec.Params) *Generator { } } - w := ioutil.Discard + w := io.Discard if args.Verbose { w = os.Stderr } @@ -247,7 +247,7 @@ func (g *Generator) generateFile(file *spec.File, tmpl string, services []*spec. out, err := format.Source(buf.Bytes()) if err != nil { - ioutil.WriteFile("/tmp/"+root.Name+".go", buf.Bytes(), 0o666) // nolint: gomnd,errcheck + os.WriteFile("/tmp/"+root.Name+".go", buf.Bytes(), 0o666) // nolint: gomnd,errcheck return nil, err } diff --git a/runtime/request.go b/runtime/request.go index 9b71ac9..d53312b 100644 --- a/runtime/request.go +++ b/runtime/request.go @@ -4,7 +4,7 @@ import ( "errors" "encoding/json" - "io/ioutil" + "io" "net/http" "github.com/iancoleman/strcase" @@ -23,7 +23,7 @@ func parseRequest(r *http.Request) (*GraphqlRequest, error) { // Get request body switch r.Method { case http.MethodPost: - buf, err := ioutil.ReadAll(r.Body) + buf, err := io.ReadAll(r.Body) if err != nil { return nil, errors.New("malformed request body, " + err.Error()) } From 917149200fde0f129431a63bbc65f37e5a0e8b6c Mon Sep 17 00:00:00 2001 From: ysugimoto Date: Sun, 28 Apr 2024 02:27:07 +0900 Subject: [PATCH 4/9] add release actions --- .github/workflows/build.yml | 4 ++- .github/workflows/publish.yml | 58 +++++++++++++++++++++++++++++++++++ Makefile | 1 + 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e92fbc3..cb875dd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,7 +1,9 @@ name: Build application on: - push: {} + push: + tags-ignore: + - "*" env: PROTOC_VERSION: 3.14.0 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..31067d1 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,58 @@ +name: Publish application + +on: + push: + tags: + - "*" + +env: + PROTOC_VERSION: 3.14.0 + GO_VERSION: 1.21.1 + +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup go + uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + - name: Setup protobuf + run: | + PROTOC_ZIP=protoc-${{ env.PROTOC_VERSION }}-linux-x86_64.zip + curl -OL https://github.com/google/protobuf/releases/download/v${{ env.PROTOC_VERSION }}/$PROTOC_ZIP + sudo unzip -o $PROTOC_ZIP -d /usr/local/protoc + sudo chmod +xr -R /usr/local/protoc + sudo ln -s /usr/local/protoc/bin/protoc /usr/local/bin + sudo ln -s /usr/local/protoc/include/google /usr/local/include/google + - name: Lint programs + uses: golangci/golangci-lint-action@v3 + with: + version: v1.54 + skip-pkg-cache: true + skip-build-cache: true + skip-go-installation: true + - name: Set version + id: version + run: | + VERSION=$(echo ${{ github.ref }} | sed -e "s#refs/tags/##g") + echo "version=$VERSION" >> $GITHUB_OUTPUT + - name: Build app + run: | + go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.31.0 + make all tag=${{ steps.version.outputs.version }} + - name: Release app + uses: softprops/action-gh-release@v2 + if: startsWith(github.ref, 'refs/tags/') + with: + files: | + dist/protoc-gen-graphql.darwin + dist/protoc-gen-graphql.darwin.arm64 + dist/protoc-gen-graphql.linux + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + diff --git a/Makefile b/Makefile index 3e3470e..6b32428 100644 --- a/Makefile +++ b/Makefile @@ -38,4 +38,5 @@ clean: all: clean build cd ${GRAPHQL_CMD} && GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.version=${VERSION}" -o ../dist/${GRAPHQL_CMD}.darwin + cd ${GRAPHQL_CMD} && GOOS=darwin GOARCH=arm64 go build -ldflags "-X main.version=${VERSION}" -o ../dist/${GRAPHQL_CMD}.darwin.arm64 cd ${GRAPHQL_CMD} && GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=${VERSION}" -o ../dist/${GRAPHQL_CMD}.linux From bcb4eb907a42af5c8316d22df42daa2f1a6c1587 Mon Sep 17 00:00:00 2001 From: ysugimoto Date: Sun, 28 Apr 2024 02:28:56 +0900 Subject: [PATCH 5/9] fix build branches --- .github/workflows/build.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cb875dd..a764aca 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,8 +2,10 @@ name: Build application on: push: - tags-ignore: + branches: - "*" + tags-ignore: + - "v*.*.*" env: PROTOC_VERSION: 3.14.0 From ad3eddc6c16ccfd7887dd8874c9774ee42296481 Mon Sep 17 00:00:00 2001 From: ysugimoto Date: Sun, 28 Apr 2024 02:29:42 +0900 Subject: [PATCH 6/9] fix publish actions --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 31067d1..b35c965 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -3,7 +3,7 @@ name: Publish application on: push: tags: - - "*" + - "v*.*.*" env: PROTOC_VERSION: 3.14.0 From 8c90aaa1ca4b64695e2390fb64544bdcfb85e691 Mon Sep 17 00:00:00 2001 From: ysugimoto Date: Sun, 28 Apr 2024 02:32:57 +0900 Subject: [PATCH 7/9] remove circleci --- .circleci/config.yml | 60 -------------------------------------------- README.md | 2 -- 2 files changed, 62 deletions(-) delete mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 4c0b894..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,60 +0,0 @@ -version: 2 - -definitions: - workspace: &workspace - docker: - # specify the version - - image: circleci/golang:1.15 - - job_presets: &job_presets - build: - <<: *workspace - steps: - - checkout - - run: - command: | - PROTOC_ZIP=protoc-3.14.0-linux-x86_64.zip - curl -OL https://github.com/google/protobuf/releases/download/v3.14.0/$PROTOC_ZIP - sudo unzip -o $PROTOC_ZIP -d /usr/local/protoc - sudo chmod +xr -R /usr/local/protoc - sudo ln -s /usr/local/protoc/bin/protoc /usr/local/bin - sudo ln -s /usr/local/protoc/include/google /usr/local/include/google - go get -u github.com/golang/protobuf/protoc-gen-go - curl -sSfL https://github.com/golangci/golangci-lint/releases/download/v1.31.0/golangci-lint-1.31.0-linux-amd64.tar.gz | tar zx -C /tmp/ - sudo mv /tmp/golangci-lint-1.31.0-linux-amd64/golangci-lint /usr/local/bin - sudo chmod +x /usr/local/bin/golangci-lint - - run: make lint - - run: make all tag=${CIRCLE_TAG} - - persist_to_workspace: - root: . - paths: - - ./* - publish: - <<: *workspace - steps: - - attach_workspace: - at: . - - run: - command: | - sudo apt-get install jq file - sh ./misc/github-release.sh - -jobs: - <<: *job_presets - -workflows: - version: 2 - build_and_publish: - jobs: - - build: - filters: - tags: - only: /v[0-9]+(\.[0-9]+)*/ - - publish: - requires: - - build - filters: - branches: - ignore: /.*/ - tags: - only: /v[0-9]+(\.[0-9]+)*/ diff --git a/README.md b/README.md index cf88d86..b6ec150 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # grpc-graphql-gateway -[![CircleCI](https://circleci.com/gh/ysugimoto/grpc-graphql-gateway/tree/master.svg?style=svg)](https://circleci.com/gh/ysugimoto/grpc-graphql-gateway/tree/master) - `grpc-graphql-gateway` is a protoc plugin that generates graphql execution code from Protocol Buffers. ![image](https://raw.githubusercontent.com/ysugimoto/grpc-graphql-gateway/master/misc/grpc-graphql-gateway.png) From 74773f279e2fc79ac58f30eec5497a056e60c06a Mon Sep 17 00:00:00 2001 From: ysugimoto Date: Sun, 28 Apr 2024 02:34:39 +0900 Subject: [PATCH 8/9] Trigger plan From 78744872250695cc935a4d7017063202932fda17 Mon Sep 17 00:00:00 2001 From: ysugimoto Date: Sun, 28 Apr 2024 02:36:48 +0900 Subject: [PATCH 9/9] Trigger CI