Skip to content

Commit 1b60cba

Browse files
authored
refactor(internal/librarian): remove srcPath (#3527)
Remove all srcPath parameters, since these were always just library.Output.
1 parent b883366 commit 1b60cba

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

internal/librarian/release.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func runRelease(ctx context.Context, cmd *cli.Command) error {
112112
if err != nil {
113113
return err
114114
}
115-
if err = releaseLibrary(ctx, cfg, libConfg, libConfg.Output, lastTag, gitExe, googleapisDir); err != nil {
115+
if err = releaseLibrary(ctx, cfg, libConfg, lastTag, gitExe, googleapisDir); err != nil {
116116
return err
117117
}
118118
}
@@ -133,44 +133,44 @@ func releaseAll(ctx context.Context, cfg *config.Config, lastTag, gitExe, google
133133
if err != nil {
134134
return err
135135
}
136-
if shouldRelease(library, filesChanged, library.Output) {
137-
if err := releaseLibrary(ctx, cfg, library, library.Output, lastTag, gitExe, googleapisDir); err != nil {
136+
if shouldRelease(library, filesChanged) {
137+
if err := releaseLibrary(ctx, cfg, library, lastTag, gitExe, googleapisDir); err != nil {
138138
return err
139139
}
140140
}
141141
}
142142
return nil
143143
}
144144

145-
func shouldRelease(library *config.Library, filesChanged []string, srcPath string) bool {
145+
func shouldRelease(library *config.Library, filesChanged []string) bool {
146146
if library.SkipPublish {
147147
return false
148148
}
149-
pathWithTrailingSlash := srcPath
149+
pathWithTrailingSlash := library.Output
150150
if !strings.HasSuffix(pathWithTrailingSlash, "/") {
151151
pathWithTrailingSlash = pathWithTrailingSlash + "/"
152152
}
153153
for _, path := range filesChanged {
154-
if strings.Contains(path, pathWithTrailingSlash) {
154+
if strings.HasPrefix(path, pathWithTrailingSlash) {
155155
return true
156156
}
157157
}
158158
return false
159159
}
160160

161-
func releaseLibrary(ctx context.Context, cfg *config.Config, libConfig *config.Library, srcPath, lastTag, gitExe, googleapisDir string) error {
161+
func releaseLibrary(ctx context.Context, cfg *config.Config, libConfig *config.Library, lastTag, gitExe, googleapisDir string) error {
162162
switch cfg.Language {
163163
case languageFake:
164164
return fakeReleaseLibrary(libConfig)
165165
case languageRust:
166-
release, err := rust.ManifestVersionNeedsBump(gitExe, lastTag, srcPath+"/Cargo.toml")
166+
release, err := rust.ManifestVersionNeedsBump(gitExe, lastTag, libConfig.Output+"/Cargo.toml")
167167
if err != nil {
168168
return err
169169
}
170170
if !release {
171171
return nil
172172
}
173-
if err := rust.ReleaseLibrary(libConfig, srcPath); err != nil {
173+
if err := rust.ReleaseLibrary(libConfig); err != nil {
174174
return err
175175
}
176176
copyConfig, err := cloneConfig(cfg)

internal/librarian/release_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,10 @@ func TestRelease(t *testing.T) {
277277

278278
for _, test := range tests {
279279
t.Run(test.name, func(t *testing.T) {
280-
libConfg := &config.Library{}
281-
err := releaseLibrary(t.Context(), cfg, libConfg, test.srcPath, test.lastTag, "git", "")
280+
libConfg := &config.Library{
281+
Output: test.srcPath,
282+
}
283+
err := releaseLibrary(t.Context(), cfg, libConfg, test.lastTag, "git", "")
282284
if err != nil {
283285
t.Fatalf("releaseLibrary() error = %v", err)
284286
}

internal/librarian/rust/release.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
const defaultVersion = "0.1.0"
2828

2929
// ReleaseLibrary bumps version for Cargo.toml files and updates librarian config version.
30-
func ReleaseLibrary(library *config.Library, srcPath string) error {
30+
func ReleaseLibrary(library *config.Library) error {
3131
newVersion := defaultVersion
3232
if library.Version != "" {
3333
v, err := semver.DeriveNext(semver.Minor, library.Version,
@@ -41,7 +41,7 @@ func ReleaseLibrary(library *config.Library, srcPath string) error {
4141
newVersion = v
4242
}
4343

44-
cargoFile := filepath.Join(srcPath, "Cargo.toml")
44+
cargoFile := filepath.Join(library.Output, "Cargo.toml")
4545
_, err := os.Stat(cargoFile)
4646
switch {
4747
case err != nil && !os.IsNotExist(err):

internal/librarian/rust/release_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ const (
4040

4141
func TestReleaseOne(t *testing.T) {
4242
cfg := setupRelease(t)
43-
err := ReleaseLibrary(cfg.Libraries[0], storageDir)
44-
if err != nil {
43+
if err := ReleaseLibrary(cfg.Libraries[0]); err != nil {
4544
t.Fatal(err)
4645
}
4746

@@ -114,9 +113,9 @@ func checkLibraryVersion(t *testing.T, library *config.Library, wantVersion stri
114113
}
115114

116115
func TestNoCargoFile(t *testing.T) {
117-
got := ReleaseLibrary(&config.Library{Version: "1.0.0"}, "nonexistent/path")
118-
if got == nil {
119-
t.Errorf("expected error when Cargo.toml doesn't exist with library.Version set, but got %v", got)
116+
err := ReleaseLibrary(&config.Library{Version: "1.0.0", Output: "nonexistent/path"})
117+
if err == nil {
118+
t.Error("expected error when Cargo.toml doesn't exist")
120119
}
121120
}
122121

@@ -161,7 +160,7 @@ func TestReleaseLibraryNoVersion(t *testing.T) {
161160
Name: libName,
162161
Output: libDir,
163162
}
164-
if err := ReleaseLibrary(lib, libDir); err != nil {
163+
if err := ReleaseLibrary(lib); err != nil {
165164
t.Fatal(err)
166165
}
167166
checkLibraryVersion(t, lib, test.wantVersion)

0 commit comments

Comments
 (0)