Skip to content

Commit

Permalink
feat: expose pipeline error as exit code (#237)
Browse files Browse the repository at this point in the history
Co-authored-by: Fabio Stabile <[email protected]>
  • Loading branch information
fabioS24 and Fabio Stabile authored Feb 3, 2025
1 parent e2b364e commit 8c68bb3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- update oauth2 to v0.25.0
- update sync to v0.10.0
- update text to v0.21.0
- update `deploy trigger` command to handle deployment pipeline failure

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

Expand Down
4 changes: 4 additions & 0 deletions internal/cmd/deploy/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ func runDeployTrigger(ctx context.Context, environmentName string, options *clio
return fmt.Errorf("error retrieving the pipeline status: %w", err)
}

if status == "failed" {
return fmt.Errorf("Pipeline failed")
}

fmt.Printf("Pipeline ended with %s\n", status)
return nil
}
Expand Down
34 changes: 34 additions & 0 deletions internal/cmd/deploy/trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ func TestDeploy(t *testing.T) {
server: testTriggerServer(t),
projectID: "correct",
},
"pipeline failed": {
server: testFailedTriggerServer(t),
projectID: "failed",
expectErr: true,
},
"pipeline fails": {
server: testTriggerServer(t),
projectID: "fails-bad-request",
Expand Down Expand Up @@ -115,3 +120,32 @@ func testTriggerServer(t *testing.T) *httptest.Server {

return server
}

func testFailedTriggerServer(t *testing.T) *httptest.Server {
t.Helper()
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
t.Helper()
switch {
case r.Method == http.MethodPost && r.URL.Path == fmt.Sprintf(deployProjectEndpointTemplate, "failed"):
data, err := resources.EncodeResourceToJSON(&resources.DeployProject{
ID: 1,
URL: "http://example.com",
})

require.NoError(t, err)
w.Write(data)
case r.Method == http.MethodGet && r.URL.Path == fmt.Sprintf(pipelineStatusEndpointTemplate, "failed", 1) && r.URL.Query().Get("environment") == "environmentName":
data, err := resources.EncodeResourceToJSON(&resources.PipelineStatus{
ID: 1,
Status: "failed",
})
require.NoError(t, err)
w.Write(data)
default:
w.WriteHeader(http.StatusNotFound)
require.FailNowf(t, "unknown http request", "request method: %s request URL: %s", r.Method, r.URL)
}
}))

return server
}

0 comments on commit 8c68bb3

Please sign in to comment.