Skip to content

Commit

Permalink
Merge branch 'grpc-ecosystem:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Ccheers authored Mar 4, 2025
2 parents 3dd3f08 + 470a32d commit a6f597f
Show file tree
Hide file tree
Showing 16 changed files with 91 additions and 196 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: actions/cache@0c907a75c2c80ebcb7f088228285e798b750cf8f # v4
- uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4
with:
path: /home/vscode/.cache/_grpc_gateway_bazel
key: v1-bazel-cache-${{ hashFiles('repositories.bzl') }}
Expand Down Expand Up @@ -104,7 +104,7 @@ jobs:
with:
go-version: 1.24
check-latest: true
- run: go run golang.org/x/exp/cmd/gorelease@latest -base=v2.26.1
- run: go run golang.org/x/exp/cmd/gorelease@latest -base=v2.26.2
proto_lint:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
actions: read # To read the workflow path.
id-token: write # To sign the provenance.
contents: write # To add assets to a release.
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v2.0.0
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v2.1.0
with:
compile-generator: true # Workaround for https://github.com/slsa-framework/slsa-github-generator/issues/1163
base64-subjects: "${{ needs.goreleaser.outputs.hashes }}"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/renovate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
with:
fetch-depth: 0
token: ${{ secrets.GH_PUSH_TOKEN }}
- uses: actions/cache@0c907a75c2c80ebcb7f088228285e798b750cf8f # v4
- uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4
with:
path: /home/vscode/.cache/_grpc_gateway_bazel
key: v1-bazel-cache-${{ hashFiles('repositories.bzl') }}
Expand Down
4 changes: 2 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module(
# Bazel Central Registry modules.
bazel_dep(name = "bazel_features", version = "1.26.0")
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "rules_python", version = "1.1.0")
bazel_dep(name = "rules_python", version = "1.2.0")
bazel_dep(name = "rules_proto", version = "7.1.0")
bazel_dep(name = "rules_go", version = "0.53.0", repo_name = "io_bazel_rules_go")
bazel_dep(name = "gazelle", version = "0.42.0", repo_name = "bazel_gazelle")
Expand All @@ -19,7 +19,7 @@ bazel_dep(name = "googleapis", version = "0.0.0-20241220-5e258e33")
# This is required as a transitive dependency and not directly needed by this module.
# We have this version pinned to solve for differences in the MODULE.bazel.lock file
# when running CI.
bazel_dep(name = "rules_rust", version = "0.57.1")
bazel_dep(name = "rules_rust", version = "0.58.0")

go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.24.0")
Expand Down
13 changes: 7 additions & 6 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,48 @@ This will place four binaries in your `$GOBIN`;

Make sure that your `$GOBIN` is in your `$PATH`.

### **Using the `tool` Directive in Go 1.24**

Starting from Go 1.24, the `tool` directive in `go.mod` provides a structured way to track and manage executable dependencies. This replaces the previous workaround of using a separate `tools.go` file with blank imports.

#### **Tracking Tools in `go.mod`**

Instead of manually importing tool dependencies in a Go source file, you can now use the `tool` directive in `go.mod` to declare the tools your project depends on. For example:

```go
module tools

go 1.24

tool (
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2
google.golang.org/grpc/cmd/protoc-gen-go-grpc
google.golang.org/protobuf/cmd/protoc-gen-go
)
```

#### **Managing Tool Dependencies**

To add tools to your module, use the `-tool` flag with `go get`:

```sh
go get -tool github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway
go get -tool github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2
go get -tool google.golang.org/protobuf/cmd/protoc-gen-go
go get -tool google.golang.org/grpc/cmd/protoc-gen-go-grpc
```

This automatically updates `go.mod`, adding the tools under the `tool` directive along with `require` statements to ensure version tracking.

### Install Tools

Once the tool dependencies are properly recorded in the `go.mod` file, simply execute the following command in the root directory of your project:

```sh
go install ./...
```

### Download the binaries

You may alternatively download the binaries from the [GitHub releases page](https://github.com/grpc-ecosystem/grpc-gateway/releases/latest).
Expand Down
12 changes: 6 additions & 6 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ bazel_features_deps()

http_archive(
name = "rules_python",
sha256 = "9c6e26911a79fbf510a8f06d8eedb40f412023cf7fa6d1461def27116bff022c",
strip_prefix = "rules_python-1.1.0",
url = "https://github.com/bazelbuild/rules_python/releases/download/1.1.0/rules_python-1.1.0.tar.gz",
sha256 = "2ef40fdcd797e07f0b6abda446d1d84e2d9570d234fddf8fcd2aa262da852d1c",
strip_prefix = "rules_python-1.2.0",
url = "https://github.com/bazelbuild/rules_python/releases/download/1.2.0/rules_python-1.2.0.tar.gz",
)

load("@rules_python//python:repositories.bzl", "py_repositories")
Expand All @@ -42,10 +42,10 @@ http_archive(

http_archive(
name = "googleapis",
sha256 = "afb65ebefc9dc842a358c6e35e7bd47a55996d192dee166bb369a4a0f34bdd8d",
strip_prefix = "googleapis-fbbbf5023815f9a662c85aa8af8f3b72467fcb6f",
sha256 = "3cba2e74700fc94543f7dfb514f5f6ca9a27c39cb5a51ef585e90d2544234b80",
strip_prefix = "googleapis-05f571eb755baad00ed592fb946004fc9c12d2cc",
urls = [
"https://github.com/googleapis/googleapis/archive/fbbbf5023815f9a662c85aa8af8f3b72467fcb6f.zip",
"https://github.com/googleapis/googleapis/archive/05f571eb755baad00ed592fb946004fc9c12d2cc.zip",
],
)

Expand Down
1 change: 0 additions & 1 deletion examples/internal/integration/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ go_test(
"@org_golang_google_protobuf//encoding/protojson",
"@org_golang_google_protobuf//proto",
"@org_golang_google_protobuf//testing/protocmp",
"@org_golang_google_protobuf//types/known/durationpb",
"@org_golang_google_protobuf//types/known/emptypb",
"@org_golang_google_protobuf//types/known/fieldmaskpb",
"@org_golang_google_protobuf//types/known/structpb",
Expand Down
94 changes: 0 additions & 94 deletions examples/internal/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/testing/protocmp"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/emptypb"
fieldmaskpb "google.golang.org/protobuf/types/known/fieldmaskpb"
"google.golang.org/protobuf/types/known/structpb"
Expand Down Expand Up @@ -523,7 +522,6 @@ func TestABE(t *testing.T) {
testABEDownload(t, 8088)
testABEBulkEcho(t, 8088)
testABEBulkEchoZeroLength(t, 8088)
testABEBulkEchoDurationError(t, 8088)
testAdditionalBindings(t, 8088)
testABERepeated(t, 8088)
testABEExists(t, 8088)
Expand Down Expand Up @@ -1451,98 +1449,6 @@ func testABEBulkEchoZeroLength(t *testing.T, port int) {
}
}

func testABEBulkEchoDurationError(t *testing.T, port int) {
reqr, reqw := io.Pipe()
var wg sync.WaitGroup
var want []*durationpb.Duration
wg.Add(1)
go func() {
defer wg.Done()
defer reqw.Close()
for i := 0; i < 10; i++ {
s := fmt.Sprintf("%d.123s", i)
if i == 5 {
s = "invalidDurationFormat"
}
buf, err := marshaler.Marshal(s)
if err != nil {
t.Errorf("marshaler.Marshal(%v) failed with %v; want success", s, err)
return
}
if _, err = reqw.Write(buf); err != nil {
t.Errorf("reqw.Write(%q) failed with %v; want success", string(buf), err)
return
}
want = append(want, &durationpb.Duration{Seconds: int64(i), Nanos: int32(0.123 * 1e9)})
}
}()
apiURL := fmt.Sprintf("http://localhost:%d/v1/example/a_bit_of_everything/echo_duration", port)
req, err := http.NewRequest("POST", apiURL, reqr)
if err != nil {
t.Errorf("http.NewRequest(%q, %q, reqr) failed with %v; want success", "POST", apiURL, err)
return
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Transfer-Encoding", "chunked")
resp, err := http.DefaultClient.Do(req)
if err != nil {
t.Errorf("http.Post(%q, %q, req) failed with %v; want success", apiURL, "application/json", err)
return
}
defer resp.Body.Close()
if got, want := resp.StatusCode, http.StatusOK; got != want {
t.Errorf("resp.StatusCode = %d; want %d", got, want)
}

var got []*durationpb.Duration
var invalidArgumentCount int
wg.Add(1)
go func() {
defer wg.Done()

dec := marshaler.NewDecoder(resp.Body)
for i := 0; ; i++ {
var item struct {
Result json.RawMessage `json:"result"`
Error map[string]interface{} `json:"error"`
}
err := dec.Decode(&item)
if err == io.EOF {
break
}
if err != nil {
t.Errorf("dec.Decode(&item) failed with %v; want success; i = %d", err, i)
}
if len(item.Error) != 0 {
code, ok := item.Error["code"].(float64)
if !ok {
t.Errorf("item.Error[code] not found or not a number: %#v; i = %d", item.Error, i)
} else if int32(code) == 3 {
invalidArgumentCount++
} else {
t.Errorf("item.Error[code] = %v; want 3; i = %d", code, i)
}
continue
}

msg := new(durationpb.Duration)
if err := marshaler.Unmarshal(item.Result, msg); err != nil {
t.Errorf("marshaler.Unmarshal(%q, msg) failed with %v; want success", item.Result, err)
}
got = append(got, msg)
}

if invalidArgumentCount != 1 {
t.Errorf("got %d errors with code 3; want exactly 1", invalidArgumentCount)
}
}()

wg.Wait()
if diff := cmp.Diff(got, want[:5], protocmp.Transform()); diff != "" {
t.Error(diff)
}
}

func testAdditionalBindings(t *testing.T, port int) {
for i, f := range []func() *http.Response{
func() *http.Response {
Expand Down
22 changes: 5 additions & 17 deletions examples/internal/proto/examplepb/flow_combination.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a6f597f

Please sign in to comment.