Skip to content

Commit 8c68bb3

Browse files
fabioS24Fabio Stabile
andauthored
feat: expose pipeline error as exit code (#237)
Co-authored-by: Fabio Stabile <[email protected]>
1 parent e2b364e commit 8c68bb3

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- update oauth2 to v0.25.0
1515
- update sync to v0.10.0
1616
- update text to v0.21.0
17+
- update `deploy trigger` command to handle deployment pipeline failure
1718

1819
## [v0.16.0] - 2024-11-21
1920

internal/cmd/deploy/trigger.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ func runDeployTrigger(ctx context.Context, environmentName string, options *clio
9393
return fmt.Errorf("error retrieving the pipeline status: %w", err)
9494
}
9595

96+
if status == "failed" {
97+
return fmt.Errorf("Pipeline failed")
98+
}
99+
96100
fmt.Printf("Pipeline ended with %s\n", status)
97101
return nil
98102
}

internal/cmd/deploy/trigger_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ func TestDeploy(t *testing.T) {
4141
server: testTriggerServer(t),
4242
projectID: "correct",
4343
},
44+
"pipeline failed": {
45+
server: testFailedTriggerServer(t),
46+
projectID: "failed",
47+
expectErr: true,
48+
},
4449
"pipeline fails": {
4550
server: testTriggerServer(t),
4651
projectID: "fails-bad-request",
@@ -115,3 +120,32 @@ func testTriggerServer(t *testing.T) *httptest.Server {
115120

116121
return server
117122
}
123+
124+
func testFailedTriggerServer(t *testing.T) *httptest.Server {
125+
t.Helper()
126+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
127+
t.Helper()
128+
switch {
129+
case r.Method == http.MethodPost && r.URL.Path == fmt.Sprintf(deployProjectEndpointTemplate, "failed"):
130+
data, err := resources.EncodeResourceToJSON(&resources.DeployProject{
131+
ID: 1,
132+
URL: "http://example.com",
133+
})
134+
135+
require.NoError(t, err)
136+
w.Write(data)
137+
case r.Method == http.MethodGet && r.URL.Path == fmt.Sprintf(pipelineStatusEndpointTemplate, "failed", 1) && r.URL.Query().Get("environment") == "environmentName":
138+
data, err := resources.EncodeResourceToJSON(&resources.PipelineStatus{
139+
ID: 1,
140+
Status: "failed",
141+
})
142+
require.NoError(t, err)
143+
w.Write(data)
144+
default:
145+
w.WriteHeader(http.StatusNotFound)
146+
require.FailNowf(t, "unknown http request", "request method: %s request URL: %s", r.Method, r.URL)
147+
}
148+
}))
149+
150+
return server
151+
}

0 commit comments

Comments
 (0)