Skip to content

Commit 6258f4d

Browse files
authored
feat: skip a GitHub release for a library (#2612)
Fixes #2606
1 parent 82fda96 commit 6258f4d

File tree

7 files changed

+52
-3
lines changed

7 files changed

+52
-3
lines changed

internal/config/librarian_config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ type LibraryConfig struct {
3838
NextVersion string `yaml:"next_version"`
3939
ReleaseBlocked bool `yaml:"release_blocked"`
4040
TagFormat string `yaml:"tag_format"`
41+
// Whether to create a GitHub release for this library.
42+
SkipGitHubReleaseCreation bool `yaml:"skip_github_release_creation"`
4143
}
4244

4345
// GlobalFile defines the global files in language repositories.

internal/config/state.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ type Commit struct {
154154
CommitHash string `json:"commit_hash,omitempty"`
155155
// PiperCLNumber is the Piper CL number associated with the commit.
156156
PiperCLNumber string `json:"piper_cl_number,omitempty"`
157-
158157
// A list of library IDs associated with the commit.
159158
LibraryIDs string `json:"-"`
160159
}

internal/librarian/mocks_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,17 @@ type mockGitHubClient struct {
5757
pullRequest *github.PullRequest
5858
createdRelease *github.RepositoryRelease
5959
librarianState *config.LibrarianState
60+
librarianConfig *config.LibrarianConfig
6061
}
6162

6263
func (m *mockGitHubClient) GetRawContent(ctx context.Context, path, ref string) ([]byte, error) {
6364
if path == ".librarian/state.yaml" && m.librarianState != nil {
6465
return yaml.Marshal(m.librarianState)
6566
}
67+
68+
if path == ".librarian/config.yaml" && m.librarianConfig != nil {
69+
return yaml.Marshal(m.librarianConfig)
70+
}
6671
return m.rawContent, m.rawErr
6772
}
6873

internal/librarian/state_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ func TestParseGlobalConfig(t *testing.T) {
180180
Permissions: "read-write",
181181
},
182182
},
183+
Libraries: []*config.LibraryConfig{
184+
{
185+
LibraryID: "example-library",
186+
SkipGitHubReleaseCreation: false,
187+
},
188+
},
183189
},
184190
},
185191
{

internal/librarian/tag_and_release.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,22 @@ func (r *tagAndReleaseRunner) processPullRequest(ctx context.Context, p *github.
176176
return fmt.Errorf("failed to create tag %s: %w", tagName, err)
177177
}
178178
for _, release := range releases {
179-
slog.Info("creating release", "library", release.Library, "version", release.Version)
180179
libraryState := librarianState.LibraryByID(release.Library)
181180
if libraryState == nil {
182181
return fmt.Errorf("library %s not found", release.Library)
183182
}
184183

185-
// Create the release.
184+
var libraryConfig *config.LibraryConfig
185+
if librarianConfig != nil {
186+
libraryConfig = librarianConfig.LibraryConfigFor(release.Library)
187+
}
188+
189+
if libraryConfig != nil && libraryConfig.SkipGitHubReleaseCreation {
190+
slog.Info("skip creating release", "library", release.Library)
191+
continue
192+
}
193+
194+
slog.Info("creating release", "library", release.Library, "version", release.Version)
186195
tagFormat := config.DetermineTagFormat(release.Library, libraryState, librarianConfig)
187196
tagName := config.FormatTag(tagFormat, release.Library, release.Version)
188197
releaseName := fmt.Sprintf("%s %s", release.Library, release.Version)

internal/librarian/tag_and_release_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,32 @@ func TestProcessPullRequest(t *testing.T) {
455455
wantReplaceLabelsCalls: 1,
456456
wantCreateTagCalls: 1,
457457
},
458+
{
459+
name: "skip_a_library_release",
460+
pr: prWithRelease,
461+
ghClient: &mockGitHubClient{
462+
librarianState: &config.LibrarianState{
463+
Image: "gcr.io/some-project-id/some-test-image:latest",
464+
Libraries: []*config.LibraryState{
465+
{
466+
ID: "google-cloud-storage",
467+
SourceRoots: []string{"some/path"},
468+
},
469+
},
470+
},
471+
librarianConfig: &config.LibrarianConfig{
472+
Libraries: []*config.LibraryConfig{
473+
{
474+
LibraryID: "google-cloud-storage",
475+
SkipGitHubReleaseCreation: true,
476+
},
477+
},
478+
},
479+
},
480+
wantCreateReleaseCalls: 0,
481+
wantReplaceLabelsCalls: 1,
482+
wantCreateTagCalls: 1,
483+
},
458484
{
459485
name: "create release fails",
460486
pr: prWithRelease,

testdata/test-parse-global-config/successful-parsing-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ global_files_allowlist:
33
permissions: read-only
44
- path: another/path
55
permissions: read-write
6+
libraries:
7+
- id: example-library

0 commit comments

Comments
 (0)