Skip to content

Commit 26c608a

Browse files
authored
fix(internal/postprocessor): add ability to override release level (#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.
1 parent 62baf56 commit 26c608a

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

internal/postprocessor/config.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,22 @@ type libraryInfo struct {
4747
ServiceConfig string
4848
// RelPath is the relative path to the client from the repo root.
4949
RelPath string
50+
// ReleaseLevel is an override for the release level of a library. It is
51+
// used in cases where a release level can't be determined by looking at
52+
// the import path and/or reading service `doc.go` files because there are
53+
// no associated services.
54+
ReleaseLevel string
5055
}
5156

5257
func (p *postProcessor) loadConfig() error {
5358
var postProcessorConfig struct {
5459
Modules []string `yaml:"modules"`
5560
ServiceConfigs []*struct {
56-
InputDirectory string `yaml:"input-directory"`
57-
ServiceConfig string `yaml:"service-config"`
58-
ImportPath string `yaml:"import-path"`
59-
RelPath string `yaml:"rel-path"`
61+
InputDirectory string `yaml:"input-directory"`
62+
ServiceConfig string `yaml:"service-config"`
63+
ImportPath string `yaml:"import-path"`
64+
RelPath string `yaml:"rel-path"`
65+
ReleaseLevelOverride string `yaml:"release-level-override"`
6066
} `yaml:"service-configs"`
6167
ManualClients []*ManifestEntry `yaml:"manual-clients"`
6268
}

internal/postprocessor/config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ service-configs:
306306
- input-directory: google/cloud/alloydb/connectors/v1
307307
service-config: connectors_v1.yaml
308308
import-path: cloud.google.com/go/alloydb/connectors/apiv1
309+
release-level-override: preview
309310
- input-directory: google/cloud/alloydb/connectors/v1alpha
310311
service-config: connectors_v1alpha.yaml
311312
import-path: cloud.google.com/go/alloydb/connectors/apiv1alpha

internal/postprocessor/manifest.go

+15-11
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ func (p *postProcessor) Manifest() (map[string]ManifestEntry, error) {
6363
for _, manual := range p.config.ManualClientInfo {
6464
entries[manual.DistributionName] = *manual
6565
}
66-
for inputDir, conf := range p.config.GoogleapisToImportPath {
67-
if conf.ServiceConfig == "" {
66+
for inputDir, li := range p.config.GoogleapisToImportPath {
67+
if li.ServiceConfig == "" {
6868
continue
6969
}
70-
yamlPath := filepath.Join(p.googleapisDir, inputDir, conf.ServiceConfig)
70+
yamlPath := filepath.Join(p.googleapisDir, inputDir, li.ServiceConfig)
7171
yamlFile, err := os.Open(yamlPath)
7272
if err != nil {
7373
return nil, err
@@ -79,11 +79,12 @@ func (p *postProcessor) Manifest() (map[string]ManifestEntry, error) {
7979
if err := yaml.NewDecoder(yamlFile).Decode(&yamlConfig); err != nil {
8080
return nil, fmt.Errorf("decode: %v", err)
8181
}
82-
docURL, err := docURL(p.googleCloudDir, conf.ImportPath, conf.RelPath)
82+
docURL, err := docURL(p.googleCloudDir, li.ImportPath, li.RelPath)
8383
if err != nil {
8484
return nil, fmt.Errorf("unable to build docs URL: %v", err)
8585
}
86-
releaseLevel, err := releaseLevel(p.googleCloudDir, conf.ImportPath, conf.RelPath)
86+
87+
releaseLevel, err := releaseLevel(p.googleCloudDir, li)
8788
if err != nil {
8889
return nil, fmt.Errorf("unable to calculate release level for %v: %v", inputDir, err)
8990
}
@@ -95,15 +96,15 @@ func (p *postProcessor) Manifest() (map[string]ManifestEntry, error) {
9596

9697
entry := ManifestEntry{
9798
APIShortname: apiShortname,
98-
DistributionName: conf.ImportPath,
99+
DistributionName: li.ImportPath,
99100
Description: yamlConfig.Title,
100101
Language: "go",
101102
ClientLibraryType: "generated",
102103
ClientDocumentation: docURL,
103104
ReleaseLevel: releaseLevel,
104105
LibraryType: gapicAutoLibraryType,
105106
}
106-
entries[conf.ImportPath] = entry
107+
entries[li.ImportPath] = entry
107108
}
108109
// Remove base module entry
109110
delete(entries, "")
@@ -132,17 +133,20 @@ func docURL(cloudDir, importPath, relPath string) (string, error) {
132133
return "https://cloud.google.com/go/docs/reference/" + mod + "/latest/" + pkgPath, nil
133134
}
134135

135-
func releaseLevel(cloudDir, importPath, relPath string) (string, error) {
136-
i := strings.LastIndex(importPath, "/")
137-
lastElm := importPath[i+1:]
136+
func releaseLevel(cloudDir string, li *libraryInfo) (string, error) {
137+
if li.ReleaseLevel != "" {
138+
return li.ReleaseLevel, nil
139+
}
140+
i := strings.LastIndex(li.ImportPath, "/")
141+
lastElm := li.ImportPath[i+1:]
138142
if strings.Contains(lastElm, "alpha") {
139143
return "preview", nil
140144
} else if strings.Contains(lastElm, "beta") {
141145
return "preview", nil
142146
}
143147

144148
// Determine by scanning doc.go for our beta disclaimer
145-
docFile := filepath.Join(cloudDir, relPath, "doc.go")
149+
docFile := filepath.Join(cloudDir, li.RelPath, "doc.go")
146150
f, err := os.Open(docFile)
147151
if err != nil {
148152
return "", err

0 commit comments

Comments
 (0)