diff --git a/internal/postprocessor/config.go b/internal/postprocessor/config.go index a2d4121ff2d..a44652ef445 100644 --- a/internal/postprocessor/config.go +++ b/internal/postprocessor/config.go @@ -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"` } diff --git a/internal/postprocessor/config.yaml b/internal/postprocessor/config.yaml index 4350baf98e2..3b9ca08b2db 100644 --- a/internal/postprocessor/config.yaml +++ b/internal/postprocessor/config.yaml @@ -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 diff --git a/internal/postprocessor/manifest.go b/internal/postprocessor/manifest.go index a6cb509155f..3c5c739f2ac 100644 --- a/internal/postprocessor/manifest.go +++ b/internal/postprocessor/manifest.go @@ -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 @@ -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) } @@ -95,7 +96,7 @@ 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", @@ -103,7 +104,7 @@ func (p *postProcessor) Manifest() (map[string]ManifestEntry, error) { ReleaseLevel: releaseLevel, LibraryType: gapicAutoLibraryType, } - entries[conf.ImportPath] = entry + entries[li.ImportPath] = entry } // Remove base module entry delete(entries, "") @@ -132,9 +133,12 @@ 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") { @@ -142,7 +146,7 @@ func releaseLevel(cloudDir, importPath, relPath string) (string, error) { } // 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