Skip to content

Commit e59fc73

Browse files
authored
refactor(internal/librarian): rename release command to bump (#3644)
Rename release command to bump to avoid confusion. Fix #3551
1 parent 819270f commit e59fc73

6 files changed

Lines changed: 57 additions & 56 deletions

File tree

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,20 @@ var (
5656
}
5757
)
5858

59-
func releaseCommand() *cli.Command {
59+
func bumpCommand() *cli.Command {
6060
return &cli.Command{
61-
Name: "release",
61+
Name: "bump",
6262
Usage: "update versions and prepare release artifacts",
63-
UsageText: "librarian release [library] [--all] [--version=<version>]",
64-
Description: `Release updates version numbers and prepares the files needed for a new release.
63+
UsageText: "librarian bump [library] [--all] [--version=<version>]",
64+
Description: `bump updates version numbers and prepares the files needed for a new release.
6565
6666
If a library name is given, only that library is updated. The --all flag updates every
6767
library in the workspace. When a library is specified explicitly, the --version flag can
6868
be used to override the new version.
6969
7070
Examples:
71-
librarian release <library> # update version for one library
72-
librarian release --all # update versions for all libraries`,
71+
librarian bump <library> # update version for one library
72+
librarian bump --all # update versions for all libraries`,
7373
Flags: []cli.Flag{
7474
&cli.BoolFlag{
7575
Name: "all",
@@ -80,11 +80,11 @@ Examples:
8080
Usage: "specific version to update to; not valid with --all",
8181
},
8282
},
83-
Action: runRelease,
83+
Action: runBump,
8484
}
8585
}
8686

87-
func runRelease(ctx context.Context, cmd *cli.Command) error {
87+
func runBump(ctx context.Context, cmd *cli.Command) error {
8888
all := cmd.Bool("all")
8989
libraryName := cmd.Args().First()
9090
versionOverride := cmd.String("version")
@@ -135,7 +135,7 @@ func runRelease(ctx context.Context, cmd *cli.Command) error {
135135
}
136136

137137
if all {
138-
if err = releaseAll(ctx, cfg, lastTag, gitExe, googleapisDir, rustSources); err != nil {
138+
if err = bumpAll(ctx, cfg, lastTag, gitExe, googleapisDir, rustSources); err != nil {
139139
return err
140140
}
141141
} else {
@@ -147,18 +147,18 @@ func runRelease(ctx context.Context, cmd *cli.Command) error {
147147
if err != nil {
148148
return err
149149
}
150-
if err = releaseLibrary(ctx, cfg, libConfg, lastTag, gitExe, versionOverride, googleapisDir, rustSources); err != nil {
150+
if err = bumpLibrary(ctx, cfg, libConfg, lastTag, gitExe, versionOverride, googleapisDir, rustSources); err != nil {
151151
return err
152152
}
153153
}
154154

155-
if err := postRelease(ctx, cfg); err != nil {
155+
if err := postBump(ctx, cfg); err != nil {
156156
return err
157157
}
158158
return RunTidyOnConfig(ctx, cfg)
159159
}
160160

161-
func releaseAll(ctx context.Context, cfg *config.Config, lastTag, gitExe string, googleapisDir string, rustSources *rust.Sources) error {
161+
func bumpAll(ctx context.Context, cfg *config.Config, lastTag, gitExe string, googleapisDir string, rustSources *rust.Sources) error {
162162
filesChanged, err := git.FilesChangedSince(ctx, lastTag, gitExe, cfg.Release.IgnoredChanges)
163163
if err != nil {
164164
return err
@@ -169,7 +169,7 @@ func releaseAll(ctx context.Context, cfg *config.Config, lastTag, gitExe string,
169169
return err
170170
}
171171
if shouldRelease(library, filesChanged) {
172-
if err := releaseLibrary(ctx, cfg, library, lastTag, gitExe, "", googleapisDir, rustSources); err != nil {
172+
if err := bumpLibrary(ctx, cfg, library, lastTag, gitExe, "", googleapisDir, rustSources); err != nil {
173173
return err
174174
}
175175
}
@@ -193,7 +193,7 @@ func shouldRelease(library *config.Library, filesChanged []string) bool {
193193
return false
194194
}
195195

196-
func releaseLibrary(ctx context.Context, cfg *config.Config, libConfig *config.Library, lastTag, gitExe, versionOverride, googleapisDir string, rustSources *rust.Sources) error {
196+
func bumpLibrary(ctx context.Context, cfg *config.Config, libConfig *config.Library, lastTag, gitExe, versionOverride, googleapisDir string, rustSources *rust.Sources) error {
197197
// If the language doesn't have bespoke versioning options, a default
198198
// [semver.DeriveNextOptions] instance is returned.
199199
opts := languageVersioningOptions[cfg.Language]
@@ -204,7 +204,7 @@ func releaseLibrary(ctx context.Context, cfg *config.Config, libConfig *config.L
204204

205205
switch cfg.Language {
206206
case languageFake:
207-
return fakeReleaseLibrary(libConfig, nextVersion)
207+
return fakeBumpLibrary(libConfig, nextVersion)
208208
case languageRust:
209209
release, err := rust.ManifestVersionNeedsBump(gitExe, lastTag, libConfig.Output+"/Cargo.toml")
210210
if err != nil {
@@ -213,7 +213,7 @@ func releaseLibrary(ctx context.Context, cfg *config.Config, libConfig *config.L
213213
if !release {
214214
return nil
215215
}
216-
if err := rust.ReleaseLibrary(libConfig, nextVersion); err != nil {
216+
if _, err := rust.Bump(libConfig, nextVersion); err != nil {
217217
return err
218218
}
219219
if _, err := generateLibrary(ctx, cfg, libConfig.Name, googleapisDir, rustSources); err != nil {
@@ -224,12 +224,12 @@ func releaseLibrary(ctx context.Context, cfg *config.Config, libConfig *config.L
224224
}
225225
return nil
226226
default:
227-
return fmt.Errorf("language not supported for release: %q", cfg.Language)
227+
return fmt.Errorf("language not supported for bump: %q", cfg.Language)
228228
}
229229
}
230230

231-
// postRelease performs post-release cleanup and maintenance tasks after libraries have been processed.
232-
func postRelease(ctx context.Context, cfg *config.Config) error {
231+
// postBump performs post version bump cleanup and maintenance tasks after libraries have been processed.
232+
func postBump(ctx context.Context, cfg *config.Config) error {
233233
switch cfg.Language {
234234
case languageRust:
235235
cargoExe := "cargo"
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import (
3838
// rather than an ambiguous empty string.
3939
const testUnusedStringParam = ""
4040

41-
func TestReleaseCommand(t *testing.T) {
41+
func TestBumpCommand(t *testing.T) {
4242
testhelper.RequireCommand(t, "git")
4343

4444
for _, test := range []struct {
@@ -51,7 +51,7 @@ func TestReleaseCommand(t *testing.T) {
5151
}{
5252
{
5353
name: "library name",
54-
args: []string{"librarian", "release", sample.Lib1Name},
54+
args: []string{"librarian", "bump", sample.Lib1Name},
5555
cfg: sample.Config(),
5656
withChanges: []string{filepath.Join(sample.Lib1Output, "src", "lib.rs")},
5757
wantCfg: func() *config.Config {
@@ -63,7 +63,7 @@ func TestReleaseCommand(t *testing.T) {
6363
},
6464
{
6565
name: "library name and explicit version",
66-
args: []string{"librarian", "release", sample.Lib1Name, "--version=1.2.3"},
66+
args: []string{"librarian", "bump", sample.Lib1Name, "--version=1.2.3"},
6767
cfg: sample.Config(),
6868
withChanges: []string{filepath.Join(sample.Lib1Output, "src", "lib.rs")},
6969
wantCfg: func() *config.Config {
@@ -75,7 +75,7 @@ func TestReleaseCommand(t *testing.T) {
7575
},
7676
{
7777
name: "all flag all have changes",
78-
args: []string{"librarian", "release", "--all"},
78+
args: []string{"librarian", "bump", "--all"},
7979
cfg: sample.Config(),
8080
withChanges: []string{
8181
filepath.Join(sample.Lib1Output, "src", "lib.rs"),
@@ -91,7 +91,7 @@ func TestReleaseCommand(t *testing.T) {
9191
},
9292
{
9393
name: "all flag 1 has changes",
94-
args: []string{"librarian", "release", "--all"},
94+
args: []string{"librarian", "bump", "--all"},
9595
cfg: sample.Config(),
9696
withChanges: []string{filepath.Join(sample.Lib1Output, "src", "lib.rs")},
9797
wantCfg: func() *config.Config {
@@ -103,7 +103,7 @@ func TestReleaseCommand(t *testing.T) {
103103
},
104104
{
105105
name: "preview library released",
106-
args: []string{"librarian", "release", sample.Lib1Name},
106+
args: []string{"librarian", "bump", sample.Lib1Name},
107107
withChanges: []string{filepath.Join(sample.Lib1Output, "src", "lib.rs")},
108108
cfg: sample.Config(),
109109
previewCfg: sample.PreviewConfig(),
@@ -116,7 +116,7 @@ func TestReleaseCommand(t *testing.T) {
116116
},
117117
{
118118
name: "all preview libraries released",
119-
args: []string{"librarian", "release", "--all"},
119+
args: []string{"librarian", "bump", "--all"},
120120
withChanges: []string{
121121
filepath.Join(sample.Lib1Output, "src", "lib.rs"),
122122
filepath.Join(sample.Lib2Output, "src", "lib.rs"),
@@ -177,7 +177,7 @@ func TestReleaseCommand(t *testing.T) {
177177
}
178178
}
179179

180-
func TestReleaseCommand_Error(t *testing.T) {
180+
func TestBumpCommand_Error(t *testing.T) {
181181
testhelper.RequireCommand(t, "git")
182182

183183
for _, test := range []struct {
@@ -189,34 +189,34 @@ func TestReleaseCommand_Error(t *testing.T) {
189189
}{
190190
{
191191
name: "no args",
192-
args: []string{"librarian", "release"},
192+
args: []string{"librarian", "bump"},
193193
wantErr: errMissingLibraryOrAllFlag,
194194
},
195195
{
196196
name: "library name and all flag",
197-
args: []string{"librarian", "release", "foo", "--all"},
197+
args: []string{"librarian", "bump", "foo", "--all"},
198198
wantErr: errBothLibraryAndAllFlag,
199199
},
200200
{
201201
name: "version flag and all flag",
202-
args: []string{"librarian", "release", "--version=1.2.3", "--all"},
202+
args: []string{"librarian", "bump", "--version=1.2.3", "--all"},
203203
wantErr: errBothVersionAndAllFlag,
204204
},
205205
{
206206
name: "missing librarian yaml file",
207-
args: []string{"librarian", "release", "--all"},
207+
args: []string{"librarian", "bump", "--all"},
208208
wantErr: errNoYaml,
209209
},
210210
{
211211
name: "local repo is dirty",
212-
args: []string{"librarian", "release", "--all"},
212+
args: []string{"librarian", "bump", "--all"},
213213
cfg: sample.Config(),
214214
dirty: true,
215215
wantErr: git.ErrGitStatusUnclean,
216216
},
217217
{
218218
name: "release config empty",
219-
args: []string{"librarian", "release", "--all"},
219+
args: []string{"librarian", "bump", "--all"},
220220
cfg: func() *config.Config {
221221
c := sample.Config()
222222

@@ -297,7 +297,7 @@ func TestLibraryByName(t *testing.T) {
297297
}
298298
}
299299

300-
func TestReleaseLibrary(t *testing.T) {
300+
func TestBumpLibrary(t *testing.T) {
301301
testhelper.RequireCommand(t, "git")
302302

303303
tests := []struct {
@@ -359,9 +359,9 @@ func TestReleaseLibrary(t *testing.T) {
359359

360360
targetLibCfg := targetCfg.Libraries[0]
361361
// Unused string param: lastTag.
362-
err := releaseLibrary(t.Context(), targetCfg, targetLibCfg, testUnusedStringParam, "git", test.versionOverride, "", nil)
362+
err := bumpLibrary(t.Context(), targetCfg, targetLibCfg, testUnusedStringParam, "git", test.versionOverride, "", nil)
363363
if err != nil {
364-
t.Fatalf("releaseLibrary() error = %v", err)
364+
t.Fatalf("bumpLibrary() error = %v", err)
365365
}
366366
if targetLibCfg.Version != test.wantVersion {
367367
t.Errorf("library %q version mismatch: want %q, got %q", targetLibCfg.Name, test.wantVersion, targetLibCfg.Version)
@@ -371,7 +371,7 @@ func TestReleaseLibrary(t *testing.T) {
371371
}
372372
}
373373

374-
func TestReleaseAll(t *testing.T) {
374+
func TestBumpAll(t *testing.T) {
375375
testhelper.RequireCommand(t, "git")
376376

377377
for _, test := range []struct {
@@ -439,7 +439,7 @@ func TestReleaseAll(t *testing.T) {
439439
}
440440
testhelper.Setup(t, opts)
441441

442-
err := releaseAll(t.Context(), targetCfg, sinceTag, "git", "", nil)
442+
err := bumpAll(t.Context(), targetCfg, sinceTag, "git", "", nil)
443443
if err != nil {
444444
t.Fatal(err)
445445
}
@@ -453,7 +453,7 @@ func TestReleaseAll(t *testing.T) {
453453
}
454454
}
455455

456-
func TestPostRelease(t *testing.T) {
456+
func TestPostBump(t *testing.T) {
457457
fakeCargo := filepath.Join(t.TempDir(), "fake-cargo")
458458
for _, test := range []struct {
459459
name string
@@ -508,9 +508,9 @@ func TestPostRelease(t *testing.T) {
508508
test.setup()
509509
}
510510

511-
err := postRelease(t.Context(), test.cfg)
511+
err := postBump(t.Context(), test.cfg)
512512
if (err != nil) != test.wantErr {
513-
t.Errorf("postRelease() error = %v, wantErr %v", err, test.wantErr)
513+
t.Errorf("postBump() error = %v, wantErr %v", err, test.wantErr)
514514
}
515515
})
516516
}

internal/librarian/fake.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525

2626
const fakePublishedFile = "PUBLISHED"
2727

28-
func fakeReleaseLibrary(lib *config.Library, nextVersion string) error {
28+
func fakeBumpLibrary(lib *config.Library, nextVersion string) error {
2929
lib.Version = nextVersion
3030
return nil
3131
}

internal/librarian/librarian.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func Run(ctx context.Context, args ...string) error {
4141
Commands: []*cli.Command{
4242
addCommand(),
4343
generateCommand(),
44-
releaseCommand(),
44+
bumpCommand(),
4545
tidyCommand(),
4646
updateCommand(),
4747
versionCommand(),
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,33 @@ var (
2828
errMissingVersion = errors.New("version must not be empty")
2929
)
3030

31-
// ReleaseLibrary bumps version for Cargo.toml files and updates librarian config version.
32-
func ReleaseLibrary(library *config.Library, version string) error {
31+
// Bump bumps version for Cargo.toml files and updates librarian config version
32+
// for a library.
33+
func Bump(library *config.Library, version string) (*config.Library, error) {
3334
if version == "" {
34-
return errMissingVersion
35+
return nil, errMissingVersion
3536
}
3637

3738
cargoFile := filepath.Join(library.Output, "Cargo.toml")
3839
_, err := os.Stat(cargoFile)
3940
switch {
4041
case err != nil && !os.IsNotExist(err):
41-
return err
42+
return nil, err
4243
case os.IsNotExist(err):
4344
cargo := fmt.Sprintf(`[package]
4445
name = "%s"
4546
version = "%s"
4647
edition = "2021"
4748
`, library.Name, version)
4849
if err := os.WriteFile(cargoFile, []byte(cargo), 0644); err != nil {
49-
return err
50+
return nil, err
5051
}
5152
default:
5253
if err := updateCargoVersion(cargoFile, version); err != nil {
53-
return err
54+
return nil, err
5455
}
5556
}
5657

5758
library.Version = version
58-
return nil
59+
return library, nil
5960
}

0 commit comments

Comments
 (0)