Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions internal/config/librarian_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type LibraryConfig struct {
NextVersion string `yaml:"next_version"`
ReleaseBlocked bool `yaml:"release_blocked"`
TagFormat string `yaml:"tag_format"`
// Whether to create a GitHub release for this library.
SkipGitHubReleaseCreation bool `yaml:"skip_github_release_creation"`
}

// GlobalFile defines the global files in language repositories.
Expand Down
1 change: 0 additions & 1 deletion internal/config/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ type Commit struct {
CommitHash string `json:"commit_hash,omitempty"`
// PiperCLNumber is the Piper CL number associated with the commit.
PiperCLNumber string `json:"piper_cl_number,omitempty"`

// A list of library IDs associated with the commit.
LibraryIDs string `json:"-"`
}
Expand Down
5 changes: 5 additions & 0 deletions internal/librarian/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,17 @@ type mockGitHubClient struct {
pullRequest *github.PullRequest
createdRelease *github.RepositoryRelease
librarianState *config.LibrarianState
librarianConfig *config.LibrarianConfig
}

func (m *mockGitHubClient) GetRawContent(ctx context.Context, path, ref string) ([]byte, error) {
if path == ".librarian/state.yaml" && m.librarianState != nil {
return yaml.Marshal(m.librarianState)
}

if path == ".librarian/config.yaml" && m.librarianConfig != nil {
return yaml.Marshal(m.librarianConfig)
}
return m.rawContent, m.rawErr
}

Expand Down
6 changes: 6 additions & 0 deletions internal/librarian/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ func TestParseGlobalConfig(t *testing.T) {
Permissions: "read-write",
},
},
Libraries: []*config.LibraryConfig{
{
LibraryID: "example-library",
SkipGitHubReleaseCreation: false,
},
},
},
},
{
Expand Down
13 changes: 11 additions & 2 deletions internal/librarian/tag_and_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,22 @@ func (r *tagAndReleaseRunner) processPullRequest(ctx context.Context, p *github.
return fmt.Errorf("failed to create tag %s: %w", tagName, err)
}
for _, release := range releases {
slog.Info("creating release", "library", release.Library, "version", release.Version)
libraryState := librarianState.LibraryByID(release.Library)
if libraryState == nil {
return fmt.Errorf("library %s not found", release.Library)
}

// Create the release.
var libraryConfig *config.LibraryConfig
if librarianConfig != nil {
libraryConfig = librarianConfig.LibraryConfigFor(release.Library)
}

if libraryConfig != nil && libraryConfig.SkipGitHubReleaseCreation {
slog.Info("skip creating release", "library", release.Library)
continue
}

slog.Info("creating release", "library", release.Library, "version", release.Version)
tagFormat := config.DetermineTagFormat(release.Library, libraryState, librarianConfig)
tagName := config.FormatTag(tagFormat, release.Library, release.Version)
releaseName := fmt.Sprintf("%s %s", release.Library, release.Version)
Expand Down
26 changes: 26 additions & 0 deletions internal/librarian/tag_and_release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,32 @@ func TestProcessPullRequest(t *testing.T) {
wantReplaceLabelsCalls: 1,
wantCreateTagCalls: 1,
},
{
name: "skip_a_library_release",
pr: prWithRelease,
ghClient: &mockGitHubClient{
librarianState: &config.LibrarianState{
Image: "gcr.io/some-project-id/some-test-image:latest",
Libraries: []*config.LibraryState{
{
ID: "google-cloud-storage",
SourceRoots: []string{"some/path"},
},
},
},
librarianConfig: &config.LibrarianConfig{
Libraries: []*config.LibraryConfig{
{
LibraryID: "google-cloud-storage",
SkipGitHubReleaseCreation: true,
},
},
},
},
wantCreateReleaseCalls: 0,
wantReplaceLabelsCalls: 1,
wantCreateTagCalls: 1,
},
{
name: "create release fails",
pr: prWithRelease,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ global_files_allowlist:
permissions: read-only
- path: another/path
permissions: read-write
libraries:
- id: example-library