Skip to content

Commit 3409447

Browse files
authored
chore(pipeline): create an action in the pipeline for local jobs (#1561)
_By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
1 parent ed78875 commit 3409447

File tree

11 files changed

+112
-46
lines changed

11 files changed

+112
-46
lines changed

internal/pkg/cli/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ type wsJobDirReader interface {
255255
}
256256

257257
type wsPipelineReader interface {
258-
wsServiceLister
259258
wsPipelineManifestReader
259+
WorkloadNames() ([]string, error)
260260
}
261261

262262
type wsAppManager interface {

internal/pkg/cli/mocks/mock_interfaces.go

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/pkg/cli/pipeline_update.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ func (o *updatePipelineOpts) Validate() error {
9898

9999
func (o *updatePipelineOpts) convertStages(manifestStages []manifest.PipelineStage) ([]deploy.PipelineStage, error) {
100100
var stages []deploy.PipelineStage
101-
svcNames, err := o.ws.ServiceNames()
101+
workloads, err := o.ws.WorkloadNames()
102102
if err != nil {
103-
return nil, fmt.Errorf("service names from workspace: %w", err)
103+
return nil, fmt.Errorf("get workload names from workspace: %w", err)
104104
}
105105

106106
for _, stage := range manifestStages {
@@ -110,7 +110,7 @@ func (o *updatePipelineOpts) convertStages(manifestStages []manifest.PipelineSta
110110
}
111111

112112
pipelineStage := deploy.PipelineStage{
113-
LocalServices: svcNames,
113+
LocalWorkloads: workloads,
114114
AssociatedEnvironment: &deploy.AssociatedEnvironment{
115115
Name: stage.Name,
116116
Region: env.Region,

internal/pkg/cli/pipeline_update_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestUpdatePipelineOpts_convertStages(t *testing.T) {
5252
Prod: false,
5353
}
5454
gomock.InOrder(
55-
m.ws.EXPECT().ServiceNames().Return([]string{"frontend", "backend"}, nil).Times(1),
55+
m.ws.EXPECT().WorkloadNames().Return([]string{"frontend", "backend"}, nil).Times(1),
5656
m.envStore.EXPECT().GetEnvironment("badgoose", "test").Return(mockEnv, nil).Times(1),
5757
)
5858
},
@@ -64,7 +64,7 @@ func TestUpdatePipelineOpts_convertStages(t *testing.T) {
6464
Region: "us-west-2",
6565
AccountID: "123456789012",
6666
},
67-
LocalServices: []string{"frontend", "backend"},
67+
LocalWorkloads: []string{"frontend", "backend"},
6868
RequiresApproval: false,
6969
TestCommands: []string{"make test", "echo \"made test\""},
7070
},
@@ -87,7 +87,7 @@ func TestUpdatePipelineOpts_convertStages(t *testing.T) {
8787
Prod: false,
8888
}
8989
gomock.InOrder(
90-
m.ws.EXPECT().ServiceNames().Return([]string{"frontend", "backend"}, nil).Times(1),
90+
m.ws.EXPECT().WorkloadNames().Return([]string{"frontend", "backend"}, nil).Times(1),
9191
m.envStore.EXPECT().GetEnvironment("badgoose", "test").Return(mockEnv, nil).Times(1),
9292
)
9393
},
@@ -99,7 +99,7 @@ func TestUpdatePipelineOpts_convertStages(t *testing.T) {
9999
Region: "us-west-2",
100100
AccountID: "123456789012",
101101
},
102-
LocalServices: []string{"frontend", "backend"},
102+
LocalWorkloads: []string{"frontend", "backend"},
103103
RequiresApproval: false,
104104
TestCommands: []string(nil),
105105
},
@@ -123,7 +123,7 @@ func TestUpdatePipelineOpts_convertStages(t *testing.T) {
123123
Prod: true,
124124
}
125125
gomock.InOrder(
126-
m.ws.EXPECT().ServiceNames().Return([]string{"frontend", "backend"}, nil).Times(1),
126+
m.ws.EXPECT().WorkloadNames().Return([]string{"frontend", "backend"}, nil).Times(1),
127127
m.envStore.EXPECT().GetEnvironment("badgoose", "test").Return(mockEnv, nil).Times(1),
128128
)
129129
},
@@ -135,7 +135,7 @@ func TestUpdatePipelineOpts_convertStages(t *testing.T) {
135135
Region: "us-west-2",
136136
AccountID: "123456789012",
137137
},
138-
LocalServices: []string{"frontend", "backend"},
138+
LocalWorkloads: []string{"frontend", "backend"},
139139
RequiresApproval: true,
140140
TestCommands: []string(nil),
141141
},
@@ -305,7 +305,7 @@ stages:
305305
m.prog.EXPECT().Stop(log.Ssuccessf(fmtPipelineUpdateResourcesComplete, appName)).Times(1),
306306

307307
m.ws.EXPECT().ReadPipelineManifest().Return([]byte(content), nil),
308-
m.ws.EXPECT().ServiceNames().Return([]string{"frontend", "backend"}, nil).Times(1),
308+
m.ws.EXPECT().WorkloadNames().Return([]string{"frontend", "backend"}, nil).Times(1),
309309

310310
// convertStages
311311
m.envStore.EXPECT().GetEnvironment(appName, "chicken").Return(mockEnv, nil).Times(1),
@@ -334,7 +334,7 @@ stages:
334334
m.prog.EXPECT().Stop(log.Ssuccessf(fmtPipelineUpdateResourcesComplete, appName)).Times(1),
335335

336336
m.ws.EXPECT().ReadPipelineManifest().Return([]byte(content), nil),
337-
m.ws.EXPECT().ServiceNames().Return([]string{"frontend", "backend"}, nil).Times(1),
337+
m.ws.EXPECT().WorkloadNames().Return([]string{"frontend", "backend"}, nil).Times(1),
338338

339339
// convertStages
340340
m.envStore.EXPECT().GetEnvironment(appName, "chicken").Return(mockEnv, nil).Times(1),
@@ -364,7 +364,7 @@ stages:
364364
m.prog.EXPECT().Stop(log.Ssuccessf(fmtPipelineUpdateResourcesComplete, appName)).Times(1),
365365

366366
m.ws.EXPECT().ReadPipelineManifest().Return([]byte(content), nil),
367-
m.ws.EXPECT().ServiceNames().Return([]string{"frontend", "backend"}, nil).Times(1),
367+
m.ws.EXPECT().WorkloadNames().Return([]string{"frontend", "backend"}, nil).Times(1),
368368

369369
// convertStages
370370
m.envStore.EXPECT().GetEnvironment(appName, "chicken").Return(mockEnv, nil).Times(1),
@@ -391,7 +391,7 @@ stages:
391391
m.prog.EXPECT().Stop(log.Ssuccessf(fmtPipelineUpdateResourcesComplete, appName)).Times(1),
392392

393393
m.ws.EXPECT().ReadPipelineManifest().Return([]byte(content), nil),
394-
m.ws.EXPECT().ServiceNames().Return([]string{"frontend", "backend"}, nil).Times(1),
394+
m.ws.EXPECT().WorkloadNames().Return([]string{"frontend", "backend"}, nil).Times(1),
395395

396396
// convertStages
397397
m.envStore.EXPECT().GetEnvironment(appName, "chicken").Return(mockEnv, nil).Times(1),
@@ -462,10 +462,10 @@ stages:
462462
m.prog.EXPECT().Stop(log.Ssuccessf(fmtPipelineUpdateResourcesComplete, appName)).Times(1),
463463

464464
m.ws.EXPECT().ReadPipelineManifest().Return([]byte(content), nil),
465-
m.ws.EXPECT().ServiceNames().Return(nil, errors.New("some error")).Times(1),
465+
m.ws.EXPECT().WorkloadNames().Return(nil, errors.New("some error")).Times(1),
466466
)
467467
},
468-
expectedError: fmt.Errorf("convert environments to deployment stage: service names from workspace: some error"),
468+
expectedError: fmt.Errorf("convert environments to deployment stage: get workload names from workspace: some error"),
469469
},
470470
"returns an error if fails to get cross-regional resources": {
471471
inApp: &app,
@@ -478,7 +478,7 @@ stages:
478478
m.prog.EXPECT().Stop(log.Ssuccessf(fmtPipelineUpdateResourcesComplete, appName)).Times(1),
479479

480480
m.ws.EXPECT().ReadPipelineManifest().Return([]byte(content), nil),
481-
m.ws.EXPECT().ServiceNames().Return([]string{"frontend", "backend"}, nil).Times(1),
481+
m.ws.EXPECT().WorkloadNames().Return([]string{"frontend", "backend"}, nil).Times(1),
482482

483483
// convertStages
484484
m.envStore.EXPECT().GetEnvironment(appName, "chicken").Return(mockEnv, nil).Times(1),
@@ -501,7 +501,7 @@ stages:
501501
m.prog.EXPECT().Stop(log.Ssuccessf(fmtPipelineUpdateResourcesComplete, appName)).Times(1),
502502

503503
m.ws.EXPECT().ReadPipelineManifest().Return([]byte(content), nil),
504-
m.ws.EXPECT().ServiceNames().Return([]string{"frontend", "backend"}, nil).Times(1),
504+
m.ws.EXPECT().WorkloadNames().Return([]string{"frontend", "backend"}, nil).Times(1),
505505

506506
// convertStages
507507
m.envStore.EXPECT().GetEnvironment(appName, "chicken").Return(mockEnv, nil).Times(1),
@@ -527,7 +527,7 @@ stages:
527527
m.prog.EXPECT().Stop(log.Ssuccessf(fmtPipelineUpdateResourcesComplete, appName)).Times(1),
528528

529529
m.ws.EXPECT().ReadPipelineManifest().Return([]byte(content), nil),
530-
m.ws.EXPECT().ServiceNames().Return([]string{"frontend", "backend"}, nil).Times(1),
530+
m.ws.EXPECT().WorkloadNames().Return([]string{"frontend", "backend"}, nil).Times(1),
531531

532532
// convertStages
533533
m.envStore.EXPECT().GetEnvironment(appName, "chicken").Return(mockEnv, nil).Times(1),
@@ -556,7 +556,7 @@ stages:
556556
m.prog.EXPECT().Stop(log.Ssuccessf(fmtPipelineUpdateResourcesComplete, appName)).Times(1),
557557

558558
m.ws.EXPECT().ReadPipelineManifest().Return([]byte(content), nil),
559-
m.ws.EXPECT().ServiceNames().Return([]string{"frontend", "backend"}, nil).Times(1),
559+
m.ws.EXPECT().WorkloadNames().Return([]string{"frontend", "backend"}, nil).Times(1),
560560

561561
// convertStages
562562
m.envStore.EXPECT().GetEnvironment(appName, "chicken").Return(mockEnv, nil).Times(1),

internal/pkg/deploy/cloudformation/pipeline_integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func TestPipelineCreation(t *testing.T) {
187187
Region: *appSess.Config.Region,
188188
AccountID: app.AccountID,
189189
},
190-
LocalServices: []string{"frontend", "backend"},
190+
LocalWorkloads: []string{"frontend", "backend"},
191191
},
192192
},
193193
ArtifactBuckets: artifactBuckets,

internal/pkg/deploy/cloudformation/stack/pipeline_integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestPipeline_Template(t *testing.T) {
3535
Region: "us-west-2",
3636
AccountID: "1111",
3737
},
38-
LocalServices: []string{"api"},
38+
LocalWorkloads: []string{"api"},
3939
RequiresApproval: false,
4040
TestCommands: []string{`echo "test"`},
4141
},

internal/pkg/deploy/cloudformation/stack/pipeline_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,12 @@ func mockCreatePipelineInput() *deploy.CreatePipelineInput {
136136
Stages: []deploy.PipelineStage{
137137
{
138138
AssociatedEnvironment: mockAssociatedEnv("test-chicken", "us-west-2"),
139-
LocalServices: []string{"frontend", "backend"},
139+
LocalWorkloads: []string{"frontend", "backend"},
140140
TestCommands: []string{"echo 'bok bok bok'", "make test"},
141141
},
142142
{
143143
AssociatedEnvironment: mockAssociatedEnv("prod-can-fly", "us-east-1"),
144-
LocalServices: []string{"frontend", "backend"},
144+
LocalWorkloads: []string{"frontend", "backend"},
145145
},
146146
},
147147
ArtifactBuckets: []deploy.ArtifactBucket{

internal/pkg/deploy/pipeline.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func (s *Source) Owner() (string, error) {
162162
// test commands, if the user has opted to add any.
163163
type PipelineStage struct {
164164
*AssociatedEnvironment
165-
LocalServices []string
165+
LocalWorkloads []string
166166
RequiresApproval bool
167167
TestCommands []string
168168
}

internal/pkg/workspace/workspace.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ func (ws *Workspace) JobNames() ([]string, error) {
143143
})
144144
}
145145

146+
// WorkloadNames returns the name of all the workloads in the workspace.
147+
func (ws *Workspace) WorkloadNames() ([]string, error) {
148+
return ws.workloadNames(func(wlType string) bool {
149+
return true
150+
})
151+
}
152+
146153
// workloadNames returns the name of all workloads (either services or jobs) in the workspace.
147154
func (ws *Workspace) workloadNames(match func(string) bool) ([]string, error) {
148155
copilotPath, err := ws.CopilotDirPath()

internal/pkg/workspace/workspace_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,65 @@ func TestWorkspace_JobNames(t *testing.T) {
419419
}
420420
}
421421

422+
func TestWorkspace_WorkspaceNames(t *testing.T) {
423+
testCases := map[string]struct {
424+
copilotDir string
425+
fs func() afero.Fs
426+
427+
wantedNames []string
428+
wantedErr error
429+
}{
430+
"retrieve only directories with manifest files": {
431+
copilotDir: "/copilot",
432+
fs: func() afero.Fs {
433+
fs := afero.NewMemMapFs()
434+
fs.Mkdir("/copilot", 0755)
435+
fs.Create("/copilot/buildspec.yml")
436+
fs.Create("/copilot/pipeline.yml")
437+
438+
fs.Mkdir("/copilot/frontend", 0755)
439+
frontendManifest, _ := fs.Create("/copilot/frontend/manifest.yml")
440+
defer frontendManifest.Close()
441+
frontendManifest.Write([]byte("type: Load Balanced Web Service"))
442+
443+
fs.Mkdir("/copilot/users", 0755)
444+
userManifest, _ := fs.Create("/copilot/users/manifest.yml")
445+
defer userManifest.Close()
446+
userManifest.Write([]byte("type: Backend Service"))
447+
448+
fs.MkdirAll("/copilot/report/addons", 0755)
449+
reportManifest, _ := fs.Create("/copilot/report/manifest.yml")
450+
defer reportManifest.Close()
451+
reportManifest.Write([]byte("type: Scheduled Job"))
452+
453+
// Missing manifest.yml.
454+
fs.Mkdir("/copilot/inventory", 0755)
455+
return fs
456+
},
457+
458+
wantedNames: []string{"frontend", "users", "report"},
459+
},
460+
}
461+
462+
for name, tc := range testCases {
463+
t.Run(name, func(t *testing.T) {
464+
ws := &Workspace{
465+
copilotDir: tc.copilotDir,
466+
fsUtils: &afero.Afero{
467+
Fs: tc.fs(),
468+
},
469+
}
470+
471+
names, err := ws.WorkloadNames()
472+
if tc.wantedErr != nil {
473+
require.EqualError(t, err, tc.wantedErr.Error())
474+
} else {
475+
require.ElementsMatch(t, tc.wantedNames, names)
476+
}
477+
})
478+
}
479+
}
480+
422481
func TestIsInGitRepository(t *testing.T) {
423482
testCases := map[string]struct {
424483
given func() FileStat

0 commit comments

Comments
 (0)