Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions acceptance/bundle/auto-deploy/get/databricks.yml
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
2 changes: 2 additions & 0 deletions acceptance/bundle/auto-deploy/get/out.test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cloud = false
EnvMatrix.DMS = []
85 changes: 85 additions & 0 deletions acceptance/bundle/auto-deploy/get/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@

=== A target without a trigger

>>> musterr [CLI] bundle auto-deploy get
Error: target dev has no auto-deploy trigger that you can view. To create one, run: databricks bundle auto-deploy create -t dev

=== The target's trigger

>>> [CLI] bundle auto-deploy get
Trigger ID: [UUID][0]
Repository: https://github.com/acme/repo
Bundle: databricks.yml
Target: dev
Branch: main
Deploy as: you or a user

>>> [CLI] bundle auto-deploy get -t prod
Trigger ID: [UUID][1]
Repository: https://github.com/acme/repo
Bundle: databricks.yml
Target: prod
Branch: main
Deploy as: [UUID][2]

>>> [CLI] bundle auto-deploy get -t prod -o json
{
"name": "webhook-triggers/[UUID][1]",
"repo_url": "https://github.com/acme/repo",
"git_provider": "GITHUB",
"trigger_config": {
"push_event": {
"branch": "main"
},
"dabs_deploy": {
"bundle_yml_repo_path": "databricks.yml",
"deployment_mode": "prod",
"deploy_as": {
"service_principal_client_id": "[UUID][2]"
}
},
"trigger_id": "[UUID][1]"
}
}
{
"method": "GET",
"path": "/api/2.0/git-webhooks/webhook-triggers",
"q": {
"filter": "repo_url = \"https://github.com/acme/repo\" AND trigger_config.dabs_deploy.bundle_yml_repo_path = \"databricks.yml\" AND trigger_config.dabs_deploy.deployment_mode = \"dev\""
}
}
{
"method": "GET",
"path": "/api/2.0/git-webhooks/webhook-triggers",
"q": {
"filter": "repo_url = \"https://github.com/acme/repo\" AND trigger_config.dabs_deploy.bundle_yml_repo_path = \"databricks.yml\" AND trigger_config.dabs_deploy.deployment_mode = \"prod\""
}
}
{
"method": "GET",
"path": "/api/2.0/git-webhooks/webhook-triggers",
"q": {
"filter": "repo_url = \"https://github.com/acme/repo\" AND trigger_config.dabs_deploy.bundle_yml_repo_path = \"databricks.yml\" AND trigger_config.dabs_deploy.deployment_mode = \"prod\"",
"page_token": "1"
}
}
{
"method": "GET",
"path": "/api/2.0/git-webhooks/webhook-triggers",
"q": {
"filter": "repo_url = \"https://github.com/acme/repo\" AND trigger_config.dabs_deploy.bundle_yml_repo_path = \"databricks.yml\" AND trigger_config.dabs_deploy.deployment_mode = \"prod\""
}
}
{
"method": "GET",
"path": "/api/2.0/git-webhooks/webhook-triggers",
"q": {
"filter": "repo_url = \"https://github.com/acme/repo\" AND trigger_config.dabs_deploy.bundle_yml_repo_path = \"databricks.yml\" AND trigger_config.dabs_deploy.deployment_mode = \"prod\"",
"page_token": "1"
}
}

=== Another caller does not see the trigger

>>> musterr as-test-sp [CLI] bundle auto-deploy get
Error: target dev has no auto-deploy trigger that you can view. To create one, run: databricks bundle auto-deploy create -t dev
18 changes: 18 additions & 0 deletions acceptance/bundle/auto-deploy/get/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
git-repo-init
git remote add origin https://github.com/acme/repo

title "A target without a trigger"
trace musterr $CLI bundle auto-deploy get

$CLI bundle auto-deploy create >> LOG.setup 2>&1
$CLI bundle auto-deploy create -t prod --deploy-as 692bc6d0-ffa3-11ed-be56-0242ac120002 >> LOG.setup 2>&1
rm "$OUT_REQUESTS"

title "The target's trigger"
trace $CLI bundle auto-deploy get
trace $CLI bundle auto-deploy get -t prod
trace $CLI bundle auto-deploy get -t prod -o json
print_requests.py --get //git-webhooks

title "Another caller does not see the trigger"
trace musterr as-test-sp $CLI bundle auto-deploy get
9 changes: 9 additions & 0 deletions acceptance/bundle/auto-deploy/list/databricks.yml
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
9 changes: 9 additions & 0 deletions acceptance/bundle/auto-deploy/list/other/databricks.yml
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
2 changes: 2 additions & 0 deletions acceptance/bundle/auto-deploy/list/out.test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cloud = false
EnvMatrix.DMS = []
115 changes: 115 additions & 0 deletions acceptance/bundle/auto-deploy/list/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@

=== A bundle without triggers

>>> [CLI] bundle auto-deploy list
Target Branch Deploy as Trigger ID

=== Another bundle in the same repository, whose trigger is not this bundle's

>>> withdir other [CLI] bundle auto-deploy create
Pushes to branch main now deploy target dev as you.
Trigger ID: [UUID][0]
{
"method": "PUT",
"path": "/api/2.0/git-webhooks",
"body": {
"repo_url": "https://github.com/acme/repo",
"git_provider": "GITHUB",
"trigger_config": {
"push_event": {
"branch": "main"
},
"dabs_deploy": {
"bundle_yml_repo_path": "other/databricks.yml",
"deployment_mode": "dev"
}
}
}
}

=== The triggers of this bundle's targets

>>> [CLI] bundle auto-deploy list
Target Branch Deploy as Trigger ID
dev main you or a user [UUID][1]
prod main you or a user [UUID][2]

>>> [CLI] bundle auto-deploy list -o json
[
{
"name": "webhook-triggers/[UUID][1]",
"repo_url": "https://github.com/acme/repo",
"git_provider": "GITHUB",
"trigger_config": {
"push_event": {
"branch": "main"
},
"dabs_deploy": {
"bundle_yml_repo_path": "databricks.yml",
"deployment_mode": "dev"
},
"trigger_id": "[UUID][1]"
}
},
{
"name": "webhook-triggers/[UUID][2]",
"repo_url": "https://github.com/acme/repo",
"git_provider": "GITHUB",
"trigger_config": {
"push_event": {
"branch": "main"
},
"dabs_deploy": {
"bundle_yml_repo_path": "databricks.yml",
"deployment_mode": "prod"
},
"trigger_id": "[UUID][2]"
}
}
]
{
"method": "GET",
"path": "/api/2.0/git-webhooks/webhook-triggers",
"q": {
"filter": "repo_url = \"https://github.com/acme/repo\" AND trigger_config.dabs_deploy.bundle_yml_repo_path = \"databricks.yml\""
}
}
{
"method": "GET",
"path": "/api/2.0/git-webhooks/webhook-triggers",
"q": {
"filter": "repo_url = \"https://github.com/acme/repo\" AND trigger_config.dabs_deploy.bundle_yml_repo_path = \"databricks.yml\"",
"page_token": "1"
}
}
{
"method": "GET",
"path": "/api/2.0/git-webhooks/webhook-triggers",
"q": {
"filter": "repo_url = \"https://github.com/acme/repo\" AND trigger_config.dabs_deploy.bundle_yml_repo_path = \"databricks.yml\"",
"page_token": "2"
}
}
{
"method": "GET",
"path": "/api/2.0/git-webhooks/webhook-triggers",
"q": {
"filter": "repo_url = \"https://github.com/acme/repo\" AND trigger_config.dabs_deploy.bundle_yml_repo_path = \"databricks.yml\""
}
}
{
"method": "GET",
"path": "/api/2.0/git-webhooks/webhook-triggers",
"q": {
"filter": "repo_url = \"https://github.com/acme/repo\" AND trigger_config.dabs_deploy.bundle_yml_repo_path = \"databricks.yml\"",
"page_token": "1"
}
}
{
"method": "GET",
"path": "/api/2.0/git-webhooks/webhook-triggers",
"q": {
"filter": "repo_url = \"https://github.com/acme/repo\" AND trigger_config.dabs_deploy.bundle_yml_repo_path = \"databricks.yml\"",
"page_token": "2"
}
}
18 changes: 18 additions & 0 deletions acceptance/bundle/auto-deploy/list/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
git-repo-init
git remote add origin https://github.com/acme/repo

title "A bundle without triggers"
trace $CLI bundle auto-deploy list

$CLI bundle auto-deploy create >> LOG.setup 2>&1
$CLI bundle auto-deploy create -t prod >> LOG.setup 2>&1
rm "$OUT_REQUESTS"

title "Another bundle in the same repository, whose trigger is not this bundle's"
trace withdir other $CLI bundle auto-deploy create
print_requests.py //git-webhooks

title "The triggers of this bundle's targets"
trace $CLI bundle auto-deploy list
trace $CLI bundle auto-deploy list -o json
print_requests.py --get //git-webhooks
2 changes: 2 additions & 0 deletions cmd/bundle/autodeploy/autodeploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ Example:
}

cmd.AddCommand(newCreateCommand())
cmd.AddCommand(newGetCommand())
cmd.AddCommand(newListCommand())
return cmd
}
45 changes: 45 additions & 0 deletions cmd/bundle/autodeploy/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package autodeploy

import (
"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/cmdio"
"github.com/spf13/cobra"
)

// The service shows deploy_as only for a service principal other than the caller, so an unset
// value is the caller or a user, which an admin's update can make someone other than the creator.
const deployAsTemplate = `{{with .TriggerConfig.DabsDeploy.DeployAs}}{{.ServicePrincipalClientID}}{{else}}you or a user{{end}}`

const getTemplate = `Trigger ID: {{.TriggerConfig.TriggerID}}
Repository: {{.RepoURL}}
Bundle: {{.TriggerConfig.DabsDeploy.BundleYmlRepoPath}}
Target: {{.TriggerConfig.DabsDeploy.DeploymentMode}}
Branch: {{.TriggerConfig.PushEvent.Branch}}
Deploy as: ` + deployAsTemplate + `
`

func newGetCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "get",
Short: "Show the auto-deploy trigger of this bundle target",
Args: root.NoArgs,
Annotations: map[string]string{
"template": getTemplate,
},
}

cmd.RunE = func(cmd *cobra.Command, args []string) error {
t, api, err := loadTrigger(cmd)
if err != nil {
return err
}
ctx := cmd.Context()
found, err := findTrigger(ctx, api, t)
if err != nil {
return err
}
return cmdio.Render(ctx, found)
}

return cmd
}
37 changes: 37 additions & 0 deletions cmd/bundle/autodeploy/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package autodeploy

import (
"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/gitwebhooks"
"github.com/spf13/cobra"
)

func newListCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List the auto-deploy triggers of this bundle's targets",
Long: `List the auto-deploy triggers of this bundle's targets.

The triggers are those for the origin URL and workspace of the selected target
(-t). A target with another workspace or origin has its triggers there.`,
Args: root.NoArgs,
Annotations: map[string]string{
"headerTemplate": `{{header "Target"}} {{header "Branch"}} {{header "Deploy as"}} {{header "Trigger ID"}}`,
"template": cmdio.Heredoc(`
{{range .}}{{.TriggerConfig.DabsDeploy.DeploymentMode | green}} {{.TriggerConfig.PushEvent.Branch}} ` + deployAsTemplate + ` {{.TriggerConfig.TriggerID}}
{{end}}`),
},
}

cmd.RunE = func(cmd *cobra.Command, args []string) error {
t, api, err := loadTrigger(cmd)
if err != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] list says it covers "this bundle's targets", but loadTrigger runs ProcessBundle, which selects one target first. In a bundle with two targets and no default: true, bundle auto-deploy list fails with "please specify target" even though the filter never uses the target. When prod sets its own workspace.host, running list from dev only queries dev's workspace and leaves out prod's trigger without saying so. The same happens when a target overrides bundle.git.origin_url, because repo_url comes from the selected target (trigger.go resolveTrigger). Should list work without a selected target, or go through each target's workspace and origin? Failing that, can the help text say it lists the triggers in the selected target's workspace and repository?

return err
}
ctx := cmd.Context()
return cmdio.RenderIterator(ctx, api.ListWebhookTriggers(ctx, gitwebhooks.ListWebhookTriggersRequest{Filter: t.bundleFilter()}))
}

return cmd
}
Loading
Loading