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/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..a764aca --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,45 @@ +name: Build application + +on: + push: + branches: + - "*" + tags-ignore: + - "v*.*.*" + +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: Build app + run: | + go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.31.0 + make all tag=ci + + diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..b35c965 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,58 @@ +name: Publish application + +on: + push: + tags: + - "v*.*.*" + +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/.golangci.yml b/.golangci.yml index fde4c23..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 @@ -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 @@ -137,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/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 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) diff --git a/go.mod b/go.mod index d749aaa..23c966e 100644 --- a/go.mod +++ b/go.mod @@ -1,14 +1,22 @@ 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 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/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..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(), 0666) // nolint: errcheck + os.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 } 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()) }