Skip to content

Commit f12f284

Browse files
authored
feat: release_blocked field in per-library configuration (#2243)
Fixes #897. This change implements the "release init" command part (`release_blocked`). When library config has release_blocked field set to true, the "release init" command skips the library processing. If the library ID is explicitly specified, then `release_blocked` is ignored.
1 parent cb430fa commit f12f284

File tree

4 files changed

+142
-1
lines changed

4 files changed

+142
-1
lines changed

doc/config-schema.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ Each object in the `libraries` list represents a single library and has the foll
2929
|-------------------------|--------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|-----------------------------------------------------------|
3030
| `id` | string | A unique identifier for the library, in a language-specific format. It should not be empty and only contains alphanumeric characters, slashes, periods, underscores, and hyphens. | Yes | Must be a valid library ID. |
3131
| `next_version` | string | The next released version of the library. Ignored unless it would increase the release version. | No | Must be a valid semantic version, "v" prefix is optional. |
32-
| `generate_blocked` | bool | Set this to `true` to skip the generation of this library. It's `false` by default. | No | |
32+
| `generate_blocked` | bool | (When this library is not explicitlly specified in the `-library` argument) Set this to `true` to skip the generation of this library. It's `false` by default. | No | |
33+
| `release_blocked` | bool | (When this library is not explicitlly specified in the `-library` argument) Set this to `true` to skip the release of this library. It's `false` by default. | No | |
3334

3435
## Example
3536

@@ -56,4 +57,5 @@ libraries:
5657
- id: "example-library"
5758
next_version: "2.3.4"
5859
generate_blocked: false
60+
release_blocked: false
5961
```

internal/config/librarian_config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type LibraryConfig struct {
3535
LibraryID string `yaml:"id"`
3636
NextVersion string `yaml:"next_version"`
3737
GenerateBlocked bool `yaml:"generate_blocked"`
38+
ReleaseBlocked bool `yaml:"release_blocked"`
3839
}
3940

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

internal/librarian/release_init.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ func (r *initRunner) runInitCommand(ctx context.Context, outputDir string) error
142142
// Mark if there are any library that needs to be released
143143
foundReleasableLibrary := false
144144
for _, library := range librariesToRelease {
145+
if r.librarianConfig != nil {
146+
libraryConfig := r.librarianConfig.LibraryConfigFor(library.ID)
147+
if libraryConfig != nil && libraryConfig.ReleaseBlocked && r.library != library.ID {
148+
// Do not skip the `release_blocked` library if library ID is explicitly specified.
149+
slog.Info("library has release_blocked, skipping", "id", library.ID)
150+
continue
151+
}
152+
}
145153
if err := r.processLibrary(library); err != nil {
146154
return err
147155
}

internal/librarian/release_init_test.go

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,136 @@ func TestInitRun(t *testing.T) {
295295
},
296296
},
297297
},
298+
{
299+
name: "run release init command, skips blocked libraries!",
300+
containerClient: &mockContainerClient{},
301+
dockerInitCalls: 1,
302+
setupRunner: func(containerClient *mockContainerClient) *initRunner {
303+
return &initRunner{
304+
workRoot: t.TempDir(),
305+
containerClient: containerClient,
306+
state: &config.LibrarianState{
307+
Libraries: []*config.LibraryState{
308+
{
309+
ID: "blocked-example-id",
310+
Version: "1.0.0",
311+
},
312+
{
313+
ID: "example-id",
314+
Version: "2.0.0",
315+
},
316+
},
317+
},
318+
repo: &MockRepository{
319+
Dir: t.TempDir(),
320+
GetCommitsForPathsSinceTagValueByTag: map[string][]*gitrepo.Commit{
321+
"blocked-example-id-1.0.0": {
322+
{
323+
Hash: plumbing.NewHash("123456"),
324+
Message: "feat: another new feature",
325+
},
326+
},
327+
"example-id-2.0.0": {
328+
{
329+
Hash: plumbing.NewHash("abcdefg"),
330+
Message: "feat: a new feature",
331+
},
332+
},
333+
},
334+
ChangedFilesInCommitValueByHash: map[string][]string{
335+
plumbing.NewHash("123456").String(): {
336+
"dir1/file1.txt",
337+
},
338+
plumbing.NewHash("abcdefg").String(): {
339+
"dir1/file2.txt",
340+
},
341+
},
342+
},
343+
librarianConfig: &config.LibrarianConfig{
344+
Libraries: []*config.LibraryConfig{
345+
{LibraryID: "blocked-example-id", ReleaseBlocked: true},
346+
{LibraryID: "example-id"},
347+
},
348+
},
349+
partialRepo: t.TempDir(),
350+
}
351+
},
352+
want: &config.LibrarianState{
353+
Libraries: []*config.LibraryState{
354+
{
355+
ID: "blocked-example-id",
356+
Version: "1.0.0", // version is NOT bumped.
357+
APIs: []*config.API{},
358+
SourceRoots: []string{},
359+
PreserveRegex: []string{},
360+
RemoveRegex: []string{},
361+
},
362+
{
363+
ID: "example-id",
364+
Version: "2.1.0", // version is bumped.
365+
APIs: []*config.API{},
366+
SourceRoots: []string{},
367+
PreserveRegex: []string{},
368+
RemoveRegex: []string{},
369+
},
370+
},
371+
},
372+
},
373+
{
374+
name: "run release init command, does not skip blocked library if explicitly specified",
375+
containerClient: &mockContainerClient{},
376+
dockerInitCalls: 1,
377+
setupRunner: func(containerClient *mockContainerClient) *initRunner {
378+
return &initRunner{
379+
workRoot: t.TempDir(),
380+
containerClient: containerClient,
381+
// The library is explicitly specified.
382+
library: "blocked-example-id",
383+
state: &config.LibrarianState{
384+
Libraries: []*config.LibraryState{
385+
{
386+
ID: "blocked-example-id",
387+
Version: "1.0.0",
388+
},
389+
},
390+
},
391+
repo: &MockRepository{
392+
Dir: t.TempDir(),
393+
GetCommitsForPathsSinceTagValueByTag: map[string][]*gitrepo.Commit{
394+
"blocked-example-id-1.0.0": {
395+
{
396+
Hash: plumbing.NewHash("123456"),
397+
Message: "feat: another new feature",
398+
},
399+
},
400+
},
401+
ChangedFilesInCommitValueByHash: map[string][]string{
402+
plumbing.NewHash("123456").String(): {
403+
"dir1/file1.txt",
404+
},
405+
},
406+
},
407+
librarianConfig: &config.LibrarianConfig{
408+
Libraries: []*config.LibraryConfig{
409+
{LibraryID: "blocked-example-id", ReleaseBlocked: true},
410+
},
411+
},
412+
partialRepo: t.TempDir(),
413+
}
414+
},
415+
want: &config.LibrarianState{
416+
Libraries: []*config.LibraryState{
417+
{
418+
ID: "blocked-example-id",
419+
Version: "1.1.0",
420+
APIs: []*config.API{},
421+
SourceRoots: []string{},
422+
PreserveRegex: []string{},
423+
RemoveRegex: []string{},
424+
},
425+
},
426+
},
427+
},
298428
{
299429
name: "run release init command for one invalid library (invalid library id in cfg)",
300430
containerClient: &mockContainerClient{},

0 commit comments

Comments
 (0)