Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions internal/librarian/nodejs/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os/exec"
"path/filepath"
"regexp"
"slices"
"strings"

"github.com/googleapis/librarian/internal/command"
Expand Down Expand Up @@ -234,8 +235,10 @@ func runPostProcessor(ctx context.Context, cfg *config.Config, library *config.L
if err := restoreCopyrightYear(outDir, library.CopyrightYear); err != nil {
return fmt.Errorf("failed to restore copyright year: %w", err)
}
if err := writeRepoMetadata(cfg, library, googleapisDir, outDir); err != nil {
return fmt.Errorf("failed to write repo metadata: %w", err)
if !slices.Contains(library.Keep, ".repo-metadata.json") {
if err := writeRepoMetadata(cfg, library, googleapisDir, outDir); err != nil {
return fmt.Errorf("failed to write repo metadata: %w", err)
}
}
if err := copyMissingProtos(googleapisDir, outDir); err != nil {
return fmt.Errorf("failed to copy missing protos: %w", err)
Expand Down
38 changes: 38 additions & 0 deletions internal/librarian/nodejs/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,44 @@ func TestFormat(t *testing.T) {
}
}

func TestRunPostProcessor_PreservesRepoMetadata(t *testing.T) {
testhelper.RequireCommand(t, "gapic-node-processing")
testhelper.RequireCommand(t, "compileProtos")

repoRoot := t.TempDir()
library := &config.Library{
Name: "google-cloud-test",
Keep: []string{".repo-metadata.json"},
}
outDir := filepath.Join(repoRoot, "packages", library.Name)
if err := os.MkdirAll(outDir, 0755); err != nil {
t.Fatal(err)
}

createStagingFixture(t, repoRoot, library.Name, []string{"v1"})

originalContent := `{"name": "original", "language": "nodejs"}`
if err := os.WriteFile(filepath.Join(outDir, ".repo-metadata.json"), []byte(originalContent), 0644); err != nil {
t.Fatal(err)
}

cfg := &config.Config{
Language: config.LanguageNodejs,
Repo: "googleapis/google-cloud-node",
}
if err := runPostProcessor(t.Context(), cfg, library, "", repoRoot, outDir); err != nil {
t.Fatal(err)
}

got, err := os.ReadFile(filepath.Join(outDir, ".repo-metadata.json"))
if err != nil {
t.Fatal(err)
}
if string(got) != originalContent {
t.Errorf(".repo-metadata.json content = %q, want %q", string(got), originalContent)
}
}

func TestRunPostProcessor_PreservesFiles(t *testing.T) {
testhelper.RequireCommand(t, "gapic-node-processing")
testhelper.RequireCommand(t, "compileProtos")
Expand Down
Loading