Skip to content

Commit faad5d9

Browse files
authored
fix(nodejs): freeze v1small generation and prevent deletion (#5540)
Configure `librarian` and the `migrate` to prevent the deletion, regeneration, or metadata update of the `v1small` package for `google-cloud-compute`. This effectively freezes the package in its current state as it approaches deprecation. For #4751
1 parent 6c17c4d commit faad5d9

2 files changed

Lines changed: 69 additions & 2 deletions

File tree

internal/librarian/nodejs/generate.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ func Generate(ctx context.Context, cfg *config.Config, library *config.Library,
5353
}
5454
repoRoot := filepath.Dir(filepath.Dir(outdir))
5555
for _, api := range library.APIs {
56+
// TODO(https://github.com/googleapis/librarian/issues/4751): Do not
57+
// generate v1small. This package is not meant to be used and will be
58+
// deprecated in the future, but for now (during the migration period) it
59+
// will be set to not be maintained.
60+
if api.Path == "google/cloud/compute/v1small" {
61+
continue
62+
}
5663
if err := generateAPI(ctx, api, library, googleapisDir, repoRoot); err != nil {
5764
return fmt.Errorf("failed to generate api %q: %w", api.Path, err)
5865
}
@@ -543,6 +550,13 @@ func updateSnippetMetadataVersion(outDir, version string) error {
543550
return fmt.Errorf("failed to glob snippet metadata files: %w", err)
544551
}
545552
for _, path := range matches {
553+
// TODO(https://github.com/googleapis/librarian/issues/4751): Do not
554+
// update v1small. This package is not meant to be used and will be
555+
// deprecated in the future, but for now (during the migration period) it
556+
// will be set to not be maintained.
557+
if filepath.Base(filepath.Dir(path)) == "v1small" {
558+
continue
559+
}
546560
if err := updateVersionInFile(path, version); err != nil {
547561
return fmt.Errorf("failed to update %s: %w", path, err)
548562
}

tool/cmd/migrate/nodejs.go

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,16 @@ func buildNodejsLibrary(googleapisDir, packagesDir, libraryName string) (*config
180180
if err != nil {
181181
return nil, fmt.Errorf("parsing API paths for %s: %w", libraryName, err)
182182
}
183-
library.APIs = apis
184-
library.Nodejs.NodejsAPIs = buildNodejsLibraryAPIs(googleapisDir, apis)
183+
184+
var filteredAPIs []*config.API
185+
for _, api := range apis {
186+
if libraryName == "google-cloud-compute" && api.Path == "google/cloud/compute/v1small" {
187+
continue
188+
}
189+
filteredAPIs = append(filteredAPIs, api)
190+
}
191+
library.APIs = filteredAPIs
192+
library.Nodejs.NodejsAPIs = buildNodejsLibraryAPIs(googleapisDir, filteredAPIs)
185193
}
186194

187195
// Extract copyright year from existing generated source files.
@@ -240,9 +248,54 @@ func buildNodejsLibrary(googleapisDir, packagesDir, libraryName string) (*config
240248
library.Keep = append(library.Keep, dirKeep...)
241249
}
242250

251+
if libraryName == "google-cloud-compute" {
252+
v1smallKeep, err := nodejsV1SmallKeep(pkgDir)
253+
if err != nil {
254+
return nil, fmt.Errorf("collecting keep files for v1small: %w", err)
255+
}
256+
library.Keep = append(library.Keep, v1smallKeep...)
257+
}
258+
243259
return library, nil
244260
}
245261

262+
// TODO(https://github.com/googleapis/librarian/issues/4751): Do not
263+
// generate or delete v1small. This package is not meant to be used and
264+
// will be deprecated in the future, but for now (during the migration
265+
// period) it will be set to not be maintained.
266+
//
267+
// We explicitly add these files to the keep list to prevent the clean
268+
// phase from deleting them, as the generation phase skips v1small.
269+
func nodejsV1SmallKeep(pkgDir string) ([]string, error) {
270+
var paths []string
271+
err := filepath.WalkDir(pkgDir, func(path string, d os.DirEntry, err error) error {
272+
if err != nil {
273+
return err
274+
}
275+
if d.IsDir() {
276+
if d.Name() == "node_modules" || d.Name() == "owl-bot-staging" {
277+
return filepath.SkipDir
278+
}
279+
return nil
280+
}
281+
rel, err := filepath.Rel(pkgDir, path)
282+
if err != nil {
283+
return err
284+
}
285+
if strings.Contains(rel, "v1small") {
286+
paths = append(paths, rel)
287+
}
288+
return nil
289+
})
290+
if err != nil {
291+
if errors.Is(err, fs.ErrNotExist) {
292+
return nil, nil
293+
}
294+
return nil, err
295+
}
296+
return paths, nil
297+
}
298+
246299
func buildNodejsLibraryAPIs(googleapisDir string, apis []*config.API) []*config.NodejsAPI {
247300
var nodejsAPIs []*config.NodejsAPI
248301
for _, api := range apis {

0 commit comments

Comments
 (0)