Skip to content

Commit b7b26e2

Browse files
authored
fix(internal/librarian): generate should fail with error if all libraries failed (#1876)
Fixes #1787
1 parent 067f4cb commit b7b26e2

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

internal/librarian/generate.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,18 @@ func (r *generateRunner) run(ctx context.Context) error {
141141
}
142142
prBody += fmt.Sprintf("feat: generated %s\n", libraryID)
143143
} else {
144+
failedGenerations := 0
144145
for _, library := range r.state.Libraries {
145146
if err := r.generateSingleLibrary(ctx, library.ID, outputDir); err != nil {
146147
// TODO(https://github.com/googleapis/librarian/issues/983): record failure and report in PR body when applicable
147148
slog.Error("failed to generate library", "id", library.ID, "err", err)
148149
prBody += fmt.Sprintf("%s failed to generate\n", library.ID)
150+
failedGenerations++
149151
}
150152
}
153+
if failedGenerations > 0 && failedGenerations == len(r.state.Libraries) {
154+
return fmt.Errorf("all %d libraries failed to generate", failedGenerations)
155+
}
151156
}
152157

153158
if err := saveLibrarianState(r.repo.GetDir(), r.state); err != nil {

internal/librarian/generate_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,32 @@ func TestGenerateScenarios(t *testing.T) {
829829
wantGenerateCalls: 2,
830830
wantBuildCalls: 1,
831831
},
832+
{
833+
name: "generate all, all fail should report error",
834+
repo: newTestGitRepo(t),
835+
state: &config.LibrarianState{
836+
Image: "gcr.io/test/image:v1.2.3",
837+
Libraries: []*config.LibraryState{
838+
{
839+
ID: "lib1",
840+
APIs: []*config.API{{Path: "some/api1"}},
841+
SourceRoots: []string{
842+
"src/a",
843+
},
844+
},
845+
},
846+
},
847+
container: &mockContainerClient{
848+
failGenerateForID: "lib1",
849+
generateErrForID: errors.New("generate error"),
850+
},
851+
ghClient: &mockGitHubClient{},
852+
build: true,
853+
wantErr: true,
854+
wantErrMsg: "all 1 libraries failed to generate",
855+
wantGenerateCalls: 1,
856+
wantBuildCalls: 0,
857+
},
832858
{
833859
name: "generate skips libraries with no APIs",
834860
repo: newTestGitRepo(t),

0 commit comments

Comments
 (0)