Skip to content

Commit 957dceb

Browse files
committed
temp: tool to port release-level from generation-config to sdk.yaml
1 parent cec5d8b commit 957dceb

File tree

1 file changed

+111
-0
lines changed
  • tool/cmd/java_release_level_migrate

1 file changed

+111
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Copyright 2026 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package main
16+
17+
import (
18+
"flag"
19+
"fmt"
20+
"log"
21+
"path/filepath"
22+
"strings"
23+
24+
"github.com/googleapis/librarian/internal/serviceconfig"
25+
"github.com/googleapis/librarian/internal/yaml"
26+
)
27+
28+
// GAPICConfig represents the GAPIC configuration in generation_config.yaml.
29+
type GAPICConfig struct {
30+
ProtoPath string `yaml:"proto_path"`
31+
}
32+
33+
// LibraryConfig represents a library entry in generation_config.yaml.
34+
type LibraryConfig struct {
35+
ReleaseLevel string `yaml:"release_level"`
36+
GAPICs []GAPICConfig `yaml:"GAPICs"`
37+
}
38+
39+
// GenerationConfig represents the root of generation_config.yaml.
40+
type GenerationConfig struct {
41+
Libraries []LibraryConfig `yaml:"libraries"`
42+
}
43+
44+
const sdkYamlPath = "internal/serviceconfig/sdk.yaml"
45+
46+
func main() {
47+
javaRepoPath := flag.String("java-repo", "", "Path to google-cloud-java repository")
48+
flag.Parse()
49+
50+
if *javaRepoPath == "" {
51+
log.Fatal("--java-repo is required")
52+
}
53+
54+
genConfigPath := filepath.Join(*javaRepoPath, "generation_config.yaml")
55+
gen, err := yaml.Read[GenerationConfig](genConfigPath)
56+
if err != nil {
57+
log.Fatalf("failed to read %s: %v", genConfigPath, err)
58+
}
59+
60+
apis, err := yaml.Read[[]*serviceconfig.API](sdkYamlPath)
61+
if err != nil {
62+
log.Fatalf("failed to read %s: %v", sdkYamlPath, err)
63+
}
64+
65+
apiMap := make(map[string]*serviceconfig.API)
66+
for _, api := range *apis {
67+
apiMap[api.Path] = api
68+
}
69+
70+
updatedCount := 0
71+
for _, l := range gen.Libraries {
72+
level := strings.ToLower(l.ReleaseLevel)
73+
if level == "" {
74+
level = "preview"
75+
}
76+
for _, g := range l.GAPICs {
77+
if g.ProtoPath == "" {
78+
continue
79+
}
80+
api, ok := apiMap[g.ProtoPath]
81+
if !ok {
82+
continue
83+
}
84+
if level == "stable" {
85+
if api.ReleaseLevels != nil {
86+
if _, ok := api.ReleaseLevels["java"]; ok {
87+
delete(api.ReleaseLevels, "java")
88+
if len(api.ReleaseLevels) == 0 {
89+
api.ReleaseLevels = nil
90+
}
91+
updatedCount++
92+
}
93+
}
94+
continue
95+
}
96+
if api.ReleaseLevels == nil {
97+
api.ReleaseLevels = make(map[string]string)
98+
}
99+
if api.ReleaseLevels["java"] != level {
100+
api.ReleaseLevels["java"] = level
101+
updatedCount++
102+
}
103+
}
104+
}
105+
106+
if err := yaml.Write(sdkYamlPath, apis); err != nil {
107+
log.Fatalf("failed to write %s: %v", sdkYamlPath, err)
108+
}
109+
110+
fmt.Printf("Successfully updated %d API entries in %s\n", updatedCount, sdkYamlPath)
111+
}

0 commit comments

Comments
 (0)