Skip to content

Commit

Permalink
fix(internal/postprocessor): add ability to override release level (g…
Browse files Browse the repository at this point in the history
…oogleapis#8643)

For stable client without services there is not a good way to infer
the release level. Eventually it may be nice if this info is pushed
into the service config rather than a blaze rule so we can extract
it better. For now, lets a a manual override.

In the past for things like oslogin we just did not provide a service
config entry. Although this would work here it is not ideal as there
is still valuable metadata and configuration options in these files.
  • Loading branch information
codyoss authored Oct 4, 2023
1 parent 62baf56 commit 26c608a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
14 changes: 10 additions & 4 deletions internal/postprocessor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,22 @@ type libraryInfo struct {
ServiceConfig string
// RelPath is the relative path to the client from the repo root.
RelPath string
// ReleaseLevel is an override for the release level of a library. It is
// used in cases where a release level can't be determined by looking at
// the import path and/or reading service `doc.go` files because there are
// no associated services.
ReleaseLevel string
}

func (p *postProcessor) loadConfig() error {
var postProcessorConfig struct {
Modules []string `yaml:"modules"`
ServiceConfigs []*struct {
InputDirectory string `yaml:"input-directory"`
ServiceConfig string `yaml:"service-config"`
ImportPath string `yaml:"import-path"`
RelPath string `yaml:"rel-path"`
InputDirectory string `yaml:"input-directory"`
ServiceConfig string `yaml:"service-config"`
ImportPath string `yaml:"import-path"`
RelPath string `yaml:"rel-path"`
ReleaseLevelOverride string `yaml:"release-level-override"`
} `yaml:"service-configs"`
ManualClients []*ManifestEntry `yaml:"manual-clients"`
}
Expand Down
1 change: 1 addition & 0 deletions internal/postprocessor/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ service-configs:
- input-directory: google/cloud/alloydb/connectors/v1
service-config: connectors_v1.yaml
import-path: cloud.google.com/go/alloydb/connectors/apiv1
release-level-override: preview
- input-directory: google/cloud/alloydb/connectors/v1alpha
service-config: connectors_v1alpha.yaml
import-path: cloud.google.com/go/alloydb/connectors/apiv1alpha
Expand Down
26 changes: 15 additions & 11 deletions internal/postprocessor/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ func (p *postProcessor) Manifest() (map[string]ManifestEntry, error) {
for _, manual := range p.config.ManualClientInfo {
entries[manual.DistributionName] = *manual
}
for inputDir, conf := range p.config.GoogleapisToImportPath {
if conf.ServiceConfig == "" {
for inputDir, li := range p.config.GoogleapisToImportPath {
if li.ServiceConfig == "" {
continue
}
yamlPath := filepath.Join(p.googleapisDir, inputDir, conf.ServiceConfig)
yamlPath := filepath.Join(p.googleapisDir, inputDir, li.ServiceConfig)
yamlFile, err := os.Open(yamlPath)
if err != nil {
return nil, err
Expand All @@ -79,11 +79,12 @@ func (p *postProcessor) Manifest() (map[string]ManifestEntry, error) {
if err := yaml.NewDecoder(yamlFile).Decode(&yamlConfig); err != nil {
return nil, fmt.Errorf("decode: %v", err)
}
docURL, err := docURL(p.googleCloudDir, conf.ImportPath, conf.RelPath)
docURL, err := docURL(p.googleCloudDir, li.ImportPath, li.RelPath)
if err != nil {
return nil, fmt.Errorf("unable to build docs URL: %v", err)
}
releaseLevel, err := releaseLevel(p.googleCloudDir, conf.ImportPath, conf.RelPath)

releaseLevel, err := releaseLevel(p.googleCloudDir, li)
if err != nil {
return nil, fmt.Errorf("unable to calculate release level for %v: %v", inputDir, err)
}
Expand All @@ -95,15 +96,15 @@ func (p *postProcessor) Manifest() (map[string]ManifestEntry, error) {

entry := ManifestEntry{
APIShortname: apiShortname,
DistributionName: conf.ImportPath,
DistributionName: li.ImportPath,
Description: yamlConfig.Title,
Language: "go",
ClientLibraryType: "generated",
ClientDocumentation: docURL,
ReleaseLevel: releaseLevel,
LibraryType: gapicAutoLibraryType,
}
entries[conf.ImportPath] = entry
entries[li.ImportPath] = entry
}
// Remove base module entry
delete(entries, "")
Expand Down Expand Up @@ -132,17 +133,20 @@ func docURL(cloudDir, importPath, relPath string) (string, error) {
return "https://cloud.google.com/go/docs/reference/" + mod + "/latest/" + pkgPath, nil
}

func releaseLevel(cloudDir, importPath, relPath string) (string, error) {
i := strings.LastIndex(importPath, "/")
lastElm := importPath[i+1:]
func releaseLevel(cloudDir string, li *libraryInfo) (string, error) {
if li.ReleaseLevel != "" {
return li.ReleaseLevel, nil
}
i := strings.LastIndex(li.ImportPath, "/")
lastElm := li.ImportPath[i+1:]
if strings.Contains(lastElm, "alpha") {
return "preview", nil
} else if strings.Contains(lastElm, "beta") {
return "preview", nil
}

// Determine by scanning doc.go for our beta disclaimer
docFile := filepath.Join(cloudDir, relPath, "doc.go")
docFile := filepath.Join(cloudDir, li.RelPath, "doc.go")
f, err := os.Open(docFile)
if err != nil {
return "", err
Expand Down

0 comments on commit 26c608a

Please sign in to comment.