Skip to content

Commit 192e469

Browse files
authored
feat(internal/librarian/php): support install PNPM tools (#6839)
Support installing PNPM tools for php. It is needed because owlbot postprocessing has a formatting step that uses prettier via npm exec. Fix #6830
1 parent b2df615 commit 192e469

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

internal/librarian/php/install.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/googleapis/librarian/internal/command"
2727
"github.com/googleapis/librarian/internal/config"
2828
"github.com/googleapis/librarian/internal/fetch"
29+
"github.com/googleapis/librarian/internal/librarian/nodejs"
2930
"github.com/googleapis/librarian/internal/tool/pip"
3031
)
3132

@@ -79,6 +80,12 @@ func Install(ctx context.Context, tools *config.Tools) error {
7980
return err
8081
}
8182
}
83+
// Install PNPM tools
84+
if len(tools.PNPM) > 0 {
85+
if err := nodejs.Install(ctx, tools); err != nil {
86+
return fmt.Errorf("failed to install pnpm tools: %w", err)
87+
}
88+
}
8289
return nil
8390
}
8491

internal/librarian/php/install_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,47 @@ func TestInstall(t *testing.T) {
106106
t.Setenv("PATH", bin+string(os.PathListSeparator)+os.Getenv("PATH"))
107107
},
108108
},
109+
{
110+
name: "with composer, pip, and pnpm tools",
111+
tools: &config.Tools{
112+
Composer: []*config.ComposerTool{
113+
{
114+
Name: "fake-composer-tool",
115+
Version: "1.0.0",
116+
Repo: "github.com/fake/fake-tool",
117+
SHA256: "29635b02c6e505fe31cba2f88ae999f00d2710fe1d65cb7cad521a82e7c5a518",
118+
},
119+
},
120+
Pip: []*config.PipTool{
121+
{
122+
Name: "fake-pip-tool",
123+
Version: "2.0.0",
124+
},
125+
},
126+
PNPM: []*config.PNPMTool{
127+
{
128+
Name: "fake-pnpm-tool",
129+
Version: "3.0.0",
130+
},
131+
},
132+
},
133+
setup: func(t *testing.T) {
134+
cache := t.TempDir()
135+
t.Setenv("LIBRARIAN_CACHE", cache)
136+
t.Setenv("LIBRARIAN_BIN", filepath.Join(cache, "bin"))
137+
repoDir := filepath.Join(cache, "github.com/fake/fake-tool@1.0.0")
138+
if err := os.MkdirAll(filepath.Join(repoDir, "dummy"), 0o755); err != nil {
139+
t.Fatal(err)
140+
}
141+
142+
bin := t.TempDir()
143+
writeExecutable(t, filepath.Join(bin, "composer"), "#!/bin/sh\nexit 0\n")
144+
writeExecutable(t, filepath.Join(bin, "pip"), "#!/bin/sh\nexit 0\n")
145+
writeExecutable(t, filepath.Join(bin, "node"), "#!/bin/sh\nexit 0\n")
146+
writeExecutable(t, filepath.Join(bin, "pnpm"), "#!/bin/sh\nexit 0\n")
147+
t.Setenv("PATH", bin+string(os.PathListSeparator)+os.Getenv("PATH"))
148+
},
149+
},
109150
} {
110151
t.Run(test.name, func(t *testing.T) {
111152
if test.setup != nil {

0 commit comments

Comments
 (0)