Skip to content

Commit

Permalink
feat: set version equal to module version
Browse files Browse the repository at this point in the history
As of googleapis/google-cloud-go#5517 we
now have a version file in the internal package for every module.
This change reads variable and uses it for the client version. This
means all autogenerated clients will now get a meaningful realease
version in thier call metadata.
  • Loading branch information
codyoss committed Feb 11, 2022
1 parent d0fea5b commit 4ad46f5
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 7 deletions.
11 changes: 10 additions & 1 deletion internal/gengapic/doc_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package gengapic

import (
"fmt"
"sort"
"strings"

Expand Down Expand Up @@ -105,6 +106,7 @@ func (g *generator) genDocFile(year int, scopes []string, serv *descriptor.Servi
p("//")
p("// For information about setting deadlines, reusing contexts, and more")
p("// please visit https://pkg.go.dev/cloud.google.com/go.")
//TODO(codyoss): use the pkgPath opt
p("package %s // import %q", g.opts.pkgName, g.opts.pkgPath)
p("")

Expand All @@ -119,6 +121,7 @@ func (g *generator) genDocFile(year int, scopes []string, serv *descriptor.Servi
p("%s%q", "\t", "strings")
p("%s%q", "\t", "unicode")
p("")
p("%s%q", "\t", resolveModuleInternalPkg(g.opts.pkgPath))
if hasREST {
p("%s%q", "\t", "golang.org/x/xerrors")
}
Expand All @@ -133,7 +136,7 @@ func (g *generator) genDocFile(year int, scopes []string, serv *descriptor.Servi
p("type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error)")
p("")

p("const versionClient = %q", "UNKNOWN")
p("var versionClient = internal.Version")
p("")

p("func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context {")
Expand Down Expand Up @@ -271,3 +274,9 @@ func wrapString(str string, max int) []string {

return lines
}

func resolveModuleInternalPkg(pkgPath string) string {
pkgSuffix := strings.TrimPrefix(pkgPath, "cloud.google.com/go/")
pkg := strings.Split(pkgSuffix, "/")[0]
return fmt.Sprintf("cloud.google.com/go/%s/internal", pkg)
}
3 changes: 2 additions & 1 deletion internal/gengapic/testdata/doc_file.want
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import (
"strings"
"unicode"

"cloud.google.com/go/path/internal"
"golang.org/x/xerrors"
"google.golang.org/api/option"
"google.golang.org/grpc/metadata"
Expand All @@ -88,7 +89,7 @@ import (
type clientHookParams struct{}
type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error)

const versionClient = "UNKNOWN"
var versionClient = internal.Version

func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context {
out, _ := metadata.FromOutgoingContext(ctx)
Expand Down
3 changes: 2 additions & 1 deletion internal/gengapic/testdata/doc_file_alpha.want
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import (
"strings"
"unicode"

"cloud.google.com/go/path/internal"
"golang.org/x/xerrors"
"google.golang.org/api/option"
"google.golang.org/grpc/metadata"
Expand All @@ -90,7 +91,7 @@ import (
type clientHookParams struct{}
type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error)

const versionClient = "UNKNOWN"
var versionClient = internal.Version

func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context {
out, _ := metadata.FromOutgoingContext(ctx)
Expand Down
3 changes: 2 additions & 1 deletion internal/gengapic/testdata/doc_file_alpha_emptyservice.want
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import (
"strings"
"unicode"

"cloud.google.com/go/path/internal"
"google.golang.org/api/option"
"google.golang.org/grpc/metadata"
)
Expand All @@ -66,7 +67,7 @@ import (
type clientHookParams struct{}
type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error)

const versionClient = "UNKNOWN"
var versionClient = internal.Version

func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context {
out, _ := metadata.FromOutgoingContext(ctx)
Expand Down
3 changes: 2 additions & 1 deletion internal/gengapic/testdata/doc_file_beta.want
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import (
"strings"
"unicode"

"cloud.google.com/go/path/internal"
"golang.org/x/xerrors"
"google.golang.org/api/option"
"google.golang.org/grpc/metadata"
Expand All @@ -90,7 +91,7 @@ import (
type clientHookParams struct{}
type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error)

const versionClient = "UNKNOWN"
var versionClient = internal.Version

func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context {
out, _ := metadata.FromOutgoingContext(ctx)
Expand Down
3 changes: 2 additions & 1 deletion internal/gengapic/testdata/doc_file_beta_emptyservice.want
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import (
"strings"
"unicode"

"cloud.google.com/go/path/internal"
"google.golang.org/api/option"
"google.golang.org/grpc/metadata"
)
Expand All @@ -66,7 +67,7 @@ import (
type clientHookParams struct{}
type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error)

const versionClient = "UNKNOWN"
var versionClient = internal.Version

func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context {
out, _ := metadata.FromOutgoingContext(ctx)
Expand Down
3 changes: 2 additions & 1 deletion internal/gengapic/testdata/doc_file_emptyservice.want
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import (
"strings"
"unicode"

"cloud.google.com/go/path/internal"
"google.golang.org/api/option"
"google.golang.org/grpc/metadata"
)
Expand All @@ -64,7 +65,7 @@ import (
type clientHookParams struct{}
type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error)

const versionClient = "UNKNOWN"
var versionClient = internal.Version

func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context {
out, _ := metadata.FromOutgoingContext(ctx)
Expand Down

0 comments on commit 4ad46f5

Please sign in to comment.