Skip to content

Commit 71a25ee

Browse files
authored
fix(librarian): don't clone apisource for release init (#1825)
Fixes: #1808
1 parent 95f6736 commit 71a25ee

File tree

3 files changed

+41
-30
lines changed

3 files changed

+41
-30
lines changed

internal/librarian/command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func newCommandRunner(cfg *config.Config) (*commandRunner, error) {
5757

5858
var sourceRepo gitrepo.Repository
5959
var sourceRepoDir string
60-
if cfg.CommandName != tagAndReleaseCmdName {
60+
if cfg.CommandName == generateCmdName {
6161
sourceRepo, err = cloneOrOpenRepo(cfg.WorkRoot, cfg.APISource, cfg.CI, cfg.GitHubToken)
6262
if err != nil {
6363
return nil, err

internal/librarian/generate.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ import (
3232
"github.com/googleapis/librarian/internal/gitrepo"
3333
)
3434

35+
const (
36+
generateCmdName = "generate"
37+
)
38+
3539
var cmdGenerate = &cli.Command{
3640
Short: "generate generates client library code for a single API",
3741
UsageLine: "librarian generate -source=<api-root> -api=<api-path> [flags]",

internal/librarian/generate_test.go

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -397,31 +397,34 @@ func TestNewGenerateRunner(t *testing.T) {
397397
{
398398
name: "valid config",
399399
cfg: &config.Config{
400-
API: "some/api",
401-
APISource: newTestGitRepo(t).GetDir(),
402-
Repo: newTestGitRepo(t).GetDir(),
403-
WorkRoot: t.TempDir(),
404-
Image: "gcr.io/test/test-image",
400+
API: "some/api",
401+
APISource: newTestGitRepo(t).GetDir(),
402+
Repo: newTestGitRepo(t).GetDir(),
403+
WorkRoot: t.TempDir(),
404+
Image: "gcr.io/test/test-image",
405+
CommandName: generateCmdName,
405406
},
406407
},
407408
{
408409
name: "invalid api source",
409410
cfg: &config.Config{
410-
API: "some/api",
411-
APISource: t.TempDir(), // Not a git repo
412-
Repo: newTestGitRepo(t).GetDir(),
413-
WorkRoot: t.TempDir(),
414-
Image: "gcr.io/test/test-image",
411+
API: "some/api",
412+
APISource: t.TempDir(), // Not a git repo
413+
Repo: newTestGitRepo(t).GetDir(),
414+
WorkRoot: t.TempDir(),
415+
Image: "gcr.io/test/test-image",
416+
CommandName: generateCmdName,
415417
},
416418
wantErr: true,
417419
},
418420
{
419421
name: "missing image",
420422
cfg: &config.Config{
421-
API: "some/api",
422-
APISource: t.TempDir(),
423-
Repo: "https://github.com/googleapis/librarian.git",
424-
WorkRoot: t.TempDir(),
423+
API: "some/api",
424+
APISource: t.TempDir(),
425+
Repo: "https://github.com/googleapis/librarian.git",
426+
WorkRoot: t.TempDir(),
427+
CommandName: generateCmdName,
425428
},
426429
wantErr: true,
427430
},
@@ -434,37 +437,41 @@ func TestNewGenerateRunner(t *testing.T) {
434437
WorkRoot: t.TempDir(),
435438
Image: "gcr.io/test/test-image",
436439
GitHubToken: "gh-token",
440+
CommandName: generateCmdName,
437441
},
438442
},
439443
{
440444
name: "empty API source",
441445
cfg: &config.Config{
442-
API: "some/api",
443-
APISource: "", // This will trigger the clone of googleapis
444-
Repo: newTestGitRepo(t).GetDir(),
445-
WorkRoot: t.TempDir(),
446-
Image: "gcr.io/test/test-image",
446+
API: "some/api",
447+
APISource: "", // This will trigger the clone of googleapis
448+
Repo: newTestGitRepo(t).GetDir(),
449+
WorkRoot: t.TempDir(),
450+
Image: "gcr.io/test/test-image",
451+
CommandName: generateCmdName,
447452
},
448453
},
449454
{
450455
name: "clone googleapis fails",
451456
cfg: &config.Config{
452-
API: "some/api",
453-
APISource: "", // This will trigger the clone of googleapis
454-
Repo: newTestGitRepo(t).GetDir(),
455-
WorkRoot: t.TempDir(),
456-
Image: "gcr.io/test/test-image",
457+
API: "some/api",
458+
APISource: "", // This will trigger the clone of googleapis
459+
Repo: newTestGitRepo(t).GetDir(),
460+
WorkRoot: t.TempDir(),
461+
Image: "gcr.io/test/test-image",
462+
CommandName: generateCmdName,
457463
},
458464
wantErr: true,
459465
},
460466
{
461467
name: "valid config with local repo",
462468
cfg: &config.Config{
463-
API: "some/api",
464-
APISource: newTestGitRepo(t).GetDir(),
465-
Repo: newTestGitRepo(t).GetDir(),
466-
WorkRoot: t.TempDir(),
467-
Image: "gcr.io/test/test-image",
469+
API: "some/api",
470+
APISource: newTestGitRepo(t).GetDir(),
471+
Repo: newTestGitRepo(t).GetDir(),
472+
WorkRoot: t.TempDir(),
473+
Image: "gcr.io/test/test-image",
474+
CommandName: generateCmdName,
468475
},
469476
},
470477
} {

0 commit comments

Comments
 (0)