Repository navigation
Add bundle auto-deploy attempts
#7943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dabs-ad-d4-pr5-delete
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| bundle: | ||
| name: auto-deploy | ||
|
|
||
| targets: | ||
| dev: | ||
| default: true | ||
| prod: | ||
| git: | ||
| branch: main |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Cloud = false | ||
| EnvMatrix.DMS = [] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
|
|
||
| === A target without a trigger | ||
|
|
||
| >>> musterr [CLI] bundle auto-deploy attempts | ||
| Error: target dev has no auto-deploy trigger that you can view. To create one, run: databricks bundle auto-deploy create -t dev | ||
|
|
||
| === Creating the trigger queues its first attempt | ||
|
|
||
| >>> [CLI] bundle auto-deploy attempts | ||
| Attempt ID Status Commit Created | ||
| [UUID][0] QUEUED [TIMESTAMP] | ||
|
|
||
| >>> [CLI] bundle auto-deploy attempts [UUID][0] | ||
| Attempt ID: [UUID][0] | ||
| Status: QUEUED | ||
| Created: [TIMESTAMP] | ||
| { | ||
| "method": "GET", | ||
| "path": "/api/2.0/git-webhooks/webhook-triggers/[UUID][1]/attempts" | ||
| } | ||
| { | ||
| "method": "GET", | ||
| "path": "/api/2.0/git-webhooks/webhook-triggers/[UUID][1]/attempts/[UUID][0]" | ||
| } | ||
|
|
||
| === A failed attempt | ||
|
|
||
| >>> [CLI] bundle auto-deploy attempts [UUID][2] | ||
| Attempt ID: [UUID][2] | ||
| Status: FAILED | ||
| Commit: 0123456789abcdef0123456789abcdef01234567 | ||
| Created: [TIMESTAMP] | ||
| Completed: [TIMESTAMP] | ||
| Stage: RUN_BUNDLE_DEPLOY | ||
| Run ID: 7012345678901234 | ||
| Error: cannot create job: invalid cluster spec | ||
|
|
||
| === An attempt that does not exist | ||
|
|
||
| >>> musterr [CLI] bundle auto-deploy attempts [UUID][3] | ||
| Error: Auto-deploy attempt 'webhook-triggers/[UUID][1]/attempts/[UUID][3]' does not exist | ||
|
|
||
| >>> musterr [CLI] bundle auto-deploy attempts webhook-triggers/x/attempts/y | ||
| Error: "webhook-triggers/x/attempts/y" is not an attempt ID. Pass the attempt_id of an attempt, not its name | ||
|
|
||
| >>> musterr [CLI] bundle auto-deploy attempts .. | ||
| Error: ".." is not an attempt ID. Pass the attempt_id of an attempt, not its name |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| git-repo-init | ||
| git remote add origin https://github.com/acme/repo | ||
|
|
||
| title "A target without a trigger" | ||
| trace musterr $CLI bundle auto-deploy attempts | ||
|
|
||
| $CLI bundle auto-deploy create >> LOG.setup 2>&1 | ||
| attempt_id=$($CLI bundle auto-deploy attempts -o json | jq -r '.[0].attempt_id') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] |
||
| rm "$OUT_REQUESTS" | ||
|
|
||
| title "Creating the trigger queues its first attempt" | ||
| trace $CLI bundle auto-deploy attempts | ||
| trace $CLI bundle auto-deploy attempts $attempt_id | ||
| print_requests.py --get //attempts | ||
|
|
||
| title "A failed attempt" | ||
| trace $CLI bundle auto-deploy attempts 11111111-1111-4111-8111-111111111111 | ||
|
|
||
| title "An attempt that does not exist" | ||
| trace musterr $CLI bundle auto-deploy attempts 22222222-2222-4222-8222-222222222222 | ||
| trace musterr $CLI bundle auto-deploy attempts webhook-triggers/x/attempts/y | ||
| trace musterr $CLI bundle auto-deploy attempts .. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # The fake has no runner, so no attempt of it ever fails. This stub covers how a failed attempt | ||
| # renders. It answers for any trigger, as it only checks the output. | ||
| [[Server]] | ||
| Pattern = "GET /api/2.0/git-webhooks/webhook-triggers/{trigger_id}/attempts/11111111-1111-4111-8111-111111111111" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nice to have] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nice to have] The stub matches any |
||
| Response.Body = ''' | ||
| { | ||
| "name": "webhook-triggers/aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa/attempts/11111111-1111-4111-8111-111111111111", | ||
| "trigger_id": "aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa", | ||
| "attempt_id": "11111111-1111-4111-8111-111111111111", | ||
| "attempt_status": "ATTEMPT_STATUS_FAILED", | ||
| "error_message": "cannot create job: invalid cluster spec", | ||
| "resolved_commit_sha": "0123456789abcdef0123456789abcdef01234567", | ||
| "create_time": "2026-11-24T10:00:00Z", | ||
| "complete_time": "2026-11-24T10:02:00Z", | ||
| "dabs_result": { | ||
| "stage": "STAGE_RUN_BUNDLE_DEPLOY", | ||
| "run_id": 7012345678901234, | ||
| "job_id": 7012345678900000 | ||
| } | ||
| } | ||
| ''' | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| package autodeploy | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| "github.com/databricks/cli/cmd/root" | ||
| "github.com/databricks/cli/libs/cmdio" | ||
| "github.com/databricks/cli/libs/gitwebhooks" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // Every status gets a color, so all of them carry the same escape bytes, which the list's column | ||
| // alignment counts as width. | ||
| const attemptStatusTemplate = `{{$s := replace .AttemptStatus "ATTEMPT_STATUS_" ""}}{{if eq $s "SUCCEEDED"}}{{green "%s" $s}}{{else if eq $s "FAILED"}}{{red "%s" $s}}{{else}}{{blue "%s" $s}}{{end}}` | ||
|
|
||
| const attemptTemplate = `Attempt ID: {{.AttemptID}} | ||
| Status: ` + attemptStatusTemplate + ` | ||
| {{with .ResolvedCommitSha}}Commit: {{.}} | ||
| {{end}}Created: {{.CreateTime}} | ||
| {{with .CompleteTime}}Completed: {{.}} | ||
| {{end}}{{with .DabsResult}}{{with .Stage}}Stage: {{replace . "STAGE_" ""}} | ||
| {{end}}{{with .DeploymentVersion}}Version: {{.}} | ||
| {{end}}{{with .RunID}}Run ID: {{.}} | ||
| {{end}}{{end}}{{with .ErrorMessage}}Error: {{.}} | ||
| {{end}}` | ||
|
|
||
| func newAttemptsCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "attempts [ATTEMPT_ID]", | ||
| Short: "List the auto-deploy attempts of this bundle target, or show one", | ||
| Long: `List the auto-deploy attempts of this bundle target, newest first, or show one. | ||
|
|
||
| An attempt is one deploy of the target for one commit: the first deploy when | ||
| the trigger is created, or the deploy for a push to its branch.`, | ||
| Args: root.MaximumNArgs(1), | ||
| Annotations: map[string]string{ | ||
| "headerTemplate": `{{header "Attempt ID"}} {{header "Status"}} {{header "Commit"}} {{header "Created"}}`, | ||
| "template": cmdio.Heredoc(` | ||
| {{range .}}{{.AttemptID}} ` + attemptStatusTemplate + ` {{printf "%.12s" .ResolvedCommitSha}} {{.CreateTime}} | ||
| {{end}}`), | ||
| }, | ||
| } | ||
|
|
||
| cmd.RunE = func(cmd *cobra.Command, args []string) error { | ||
| t, api, err := loadTrigger(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| ctx := cmd.Context() | ||
| // The ID becomes a path segment of the attempt's name, where . and .. would change the path. | ||
| if len(args) == 1 && (args[0] == "" || args[0] == "." || args[0] == ".." || strings.Contains(args[0], "/")) { | ||
| return fmt.Errorf("%q is not an attempt ID. Pass the attempt_id of an attempt, not its name", args[0]) | ||
| } | ||
| found, err := findTrigger(ctx, api, t) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nice to have] |
||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if len(args) == 0 { | ||
| return cmdio.RenderIterator(ctx, api.ListAutoDeployAttempts(ctx, gitwebhooks.ListAutoDeployAttemptsRequest{Parent: found.Name})) | ||
| } | ||
| attempt, err := api.GetAutoDeployAttempt(ctx, gitwebhooks.GetAutoDeployAttemptRequest{Name: found.Name + "/attempts/" + args[0]}) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nice to have] |
||
| if err != nil { | ||
| return err | ||
| } | ||
| return cmdio.RenderWithTemplate(ctx, attempt, "", attemptTemplate) | ||
| } | ||
|
|
||
| return cmd | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit]
testing.mdasks for theacceptance/bin/helpers instead of inlinejq, and recommendsgron.py | grep fieldfor single values. Canattempt_idbe read withgron.pyhere instead ofjq -r '.[0].attempt_id'?