Skip to content

Add hidden bundle auto-deploy group with create - #7940

Open
atreyadbrx wants to merge 1 commit into
mainfrom
dabs-ad-d4-pr3-create
Open

atreyadbrx wants to merge 1 commit into
mainfrom
dabs-ad-d4-pr3-create

Conversation

@atreyadbrx

@atreyadbrx atreyadbrx commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Changes

  • Adds a bundle auto-deploy command group, hidden for now, with create. create sets up the trigger that deploys a bundle target on every push to a branch. It is identified by bundle.git.origin_url, the bundle's path in the repo (bundle.git.bundle_root_path plus the config file name), and the target.
  • --git-provider is needed only for hosts other than github.com and dev.azure.com. It takes the same case-insensitive values as apps and repos (gitHub, gitLab, ...). --branch defaults to bundle.git.branch, or to the current branch when git.branch resolves to "". --deploy-as takes a service principal application ID or your own email, which is all the service accepts. It defaults to you.
  • create fails early in three cases, each with a fix in the error message:
    • --branch differs from the target's configured git.branch, since that deploy would fail the branch check.
    • The origin isn't an HTTPS URL. The service keys and clones webhooks over HTTPS.
    • A variable is set locally, through --var, BUNDLE_VAR_<name> or the target's variable-overrides file (only an entry that sets a defined, non-lookup variable counts). The runner deploys from a clone that has none of them. This makes VariableEnvPrefix and VariableOverridesPath in bundle/config/mutator exported.
  • The commands load the bundle's Git details and variables (with a new ResolveVariableReferencesInGit for bundle.git), not the full Initialize. Its target-mode checks, run_as checks and lookups run as the caller, but the deploys run as --deploy-as.
  • New libs/gitwebhooks: a client for the git-webhooks API (PUT /api/2.0/git-webhooks). The fake handlers are in libs/testserver/gitwebhooks.go.

Why

Auto-deploy needs a CLI way to set up a trigger for a bundle target. The git-webhooks API isn't in the public spec or the Go SDK yet, so libs/gitwebhooks calls it through client.Do with local types that mirror the service, like libs/dms/enrollments.go does. The group stays hidden until the API is public.

Tests

  • acceptance/bundle/auto-deploy/create covers:
    • defaults, and an update of an existing trigger (same trigger ID)
    • --deploy-as with a service principal, with your own email (-o json) and with another user's email (rejected)
    • a mode: production target without root_path, with --deploy-as a service principal
    • a lookup variable, which create does not resolve, also set in the overrides file
    • a --branch that conflicts with git.branch, a git.branch set from a variable, one that resolves to "", and a detached HEAD
    • a bundle in a subdirectory of the repository
    • an unknown host with and without --git-provider, and an unsupported --git-provider
    • an SSH origin, --var, BUNDLE_VAR_<name>, an overrides file that sets a defined variable and one that doesn't, and a repo with no origin
  • Unit tests for provider inference and --git-provider parsing.
  • Only the fake server checks the request contract so far: no test workspace serves the git-webhooks API yet, and the auto-deploy flag is off. That covers the enum strings, deployment_mode carrying the target, the response fields, and the 403 for another user's email. The fake follows the service's implemented behavior. A real-workspace check follows once the API and flag are on.

This pull request and its description were written by Isaac.

@atreyadbrx
atreyadbrx requested review from a team as code owners November 24, 2026 17:48
@atreyadbrx
atreyadbrx requested a review from pietern November 24, 2026 17:48
@github-actions github-actions Bot added the DABs DABs related issues label Nov 24, 2026

@review-oss-bot review-oss-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Automated review at cd55ba9. Each finding was verified against the code.

Not ready yet: 1 blocking issue(s), tagged [blocking].

This adds a hidden bundle auto-deploy create command that registers a git-webhooks trigger for a bundle target, along with a small libs/gitwebhooks client and a fake handler. The command is mostly sound. One gap should be fixed before merge: the guard that stops local variable overrides only checks --var, so BUNDLE_VAR_* and the variable-overrides file can still register a trigger whose deploys all fail. The provider inference duplicates an existing helper, and the acceptance output puts one request under the wrong heading.

Comment thread cmd/bundle/autodeploy/create.go Outdated

cmd.RunE = func(cmd *cobra.Command, args []string) error {
// The runner deploys with the values in the configuration only.
if cmd.Flags().Changed("var") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[blocking] This check only catches --var. mutator.SetVariables also reads BUNDLE_VAR_<name> from the environment and .databricks/bundle/<target>/variable-overrides.json. The runner has neither: the environment is the user's, and .databricks/ is normally gitignored. With the test fixture, BUNDLE_VAR_release_branch=hotfix databricks bundle auto-deploy create -t staging resolves git.branch to hotfix. That passes the branch-conflict check at line 79 too, because configuredBranch already carries the local override, and the trigger is registered for hotfix. The runner resolves git.branch to release, so ValidateGitDetails fails every deploy. Could this also reject BUNDLE_VAR_* variables that are set in the environment, and an existing overrides file for the target?

// Auto-deploy infers only these providers. Any other host takes --git-provider, since
// a host name does not tell, for example, GitHub Enterprise from GitLab self-managed.
var providersByHost = map[string]gitwebhooks.GitProvider{
"github.com": gitwebhooks.GitProviderGitHub,

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] repos.DetectProvider in cmd/workspace/repos/provider.go already maps hosts to providers. It also covers gitlab.com, bitbucket.org and git-codecommit.<region>.amazonaws.com. With providersByHost, create on an origin like https://gitlab.com/acme/repo fails with cannot infer the Git provider and needs --git-provider. The comment's GitHub Enterprise vs GitLab self-managed concern doesn't apply to those public hosts. Can we reuse that helper, or move it into libs/, and map its result onto the gitwebhooks.GitProvider names?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 +1. The accepted values also differ from the CLI's other --git-provider flags. apps and repos take the camelCase names case-insensitively (gitLab, see cmd/workspace/apps/git_flags.go:35). Here, --git-provider gitLab fails with value "gitLab" is not one of GITHUB, GITHUB_ENTERPRISE, GITLAB, .... So an origin on https://gitlab.com/... fails twice: inference fails, then the spelling the rest of the CLI uses is refused. A shared host table, plus accepting the existing names case-insensitively and mapping them to the API enum when building the request, would fix both.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed in 30d20e7. --git-provider now takes the same case-insensitive values as apps and repos (gitHub, gitLab, ...) and maps them to the API enum. Inference stays limited to github.com and dev.azure.com, which is the scope agreed for this command. Widening it is a separate decision.

trace musterr $CLI bundle auto-deploy create -t prod --branch release

title "A git.branch from a variable"
trace $CLI bundle auto-deploy create -t staging

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] No print_requests.py //git-webhooks follows this step. Its request (target staging, branch release, github.com) therefore shows up in output.txt under "A host whose provider is not inferred", ahead of the GITLAB_ENTERPRISE_EDITION request, so the --git-provider run looks like it sent two requests. Can you add print_requests.py //git-webhooks after this trace?

Comment thread libs/gitwebhooks/api.go Outdated
return &API{client: client}, nil
}

// UpsertWebhookTrigger creates the trigger, or updates the one with the same repository and target.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[nit] The comment says the upsert updates "the one with the same repository and target". The DabsDeployTarget comment and the fake also key on bundle_yml_repo_path, though, so this wording suggests two bundles in one repo share a trigger per target. Could it say "the same repository, bundle path and target"?

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Regression test report ✅

Commit: b8e3fd824 | Workflow run

Selected 1 changed tests (limit=20, 0 not selected)

1 tests: regression=1 unreleased=0 coverage=0 failing=0
test branch main (9a14ad6) latest (v1.28.0)
TestAccept/bundle/auto-deploy/create ✅ ❌ ❌
TestAccept/bundle/auto-deploy/create: branch ✅ | main (9a14ad6) ❌ | latest (v1.28.0) ❌

main (9a14ad6):

acceptance_test.go:1402: Diff:
        --- bundle/auto-deploy/create/output.txt
        +++ /tmp/TestAcceptbundleauto-deploycreate4097976811/002/output.txt
        @@ -2,289 +2,48 @@
         === The current branch, as the caller
         
         >>> [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": "databricks.yml",
        -        "deployment_mode": "dev"
        -      }
        -    }
        -  }
        -}
        +Declarative Automation Bundles let you express data/AI/analytics projects as code.
         
        -=== Updating the trigger keeps its ID
        +Common workflows:
        +  databricks bundle init default-python      # Initialize new project
        +  databricks bundle deploy --target dev      # Deploy to development
        +  databricks bundle run my_job               # Run jobs/pipelines
        +  databricks bundle deploy --target prod     # Deploy to production
         
        ->>> [CLI] bundle auto-deploy create --branch release --deploy-as [UUID][1]
        -Pushes to branch release now deploy target dev as [UUID][1].
        -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": "release"
        -      },
        -      "dabs_deploy": {
        -        "bundle_yml_repo_path": "databricks.yml",
        -        "deployment_mode": "dev",
        -        "deploy_as": {
        -          "service_principal_client_id": "[UUID][1]"
        -        }
        -      }
        -    }
        -  }
        -}
        +Import existing resources:
        +  databricks bundle generate job --existing-job-id 123 --key my_job # Generate job configuration
        +  databricks bundle deployment bind my_job 123                      # Link to an existing job
         
        -=== As yourself, in JSON
        +Online documentation: https://docs.databricks.com/en/dev-tools/bundles/index.html
         
        ->>> [CLI] bundle auto-deploy create -t prod --deploy-as [USERNAME] -o json
        -{
        -  "webhook_id": "[UUID][2]",
        -  "trigger_id": "[UUID][3]"
        -}
        -{
        -  "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": "databricks.yml",
        -        "deployment_mode": "prod",
        -        "deploy_as": {
        -          "user_email": "[USERNAME]"
        -        }
        -      }
        -    }
        -  }
        -}
        +Usage:
        +  databricks bundle [command]
         
        -=== As a service principal, on a production target that a user could not deploy
        +Available Commands:
        +  deploy             Deploy bundle
        +  deployment         Deployment related commands
        +  destroy            Destroy deployed bundle resources
        +  generate           Generate bundle configuration
        +  init               Initialize using a bundle template
        +  open               Open a resource in the browser
        +  plan               Show deployment plan
        +  run                Run a job, pipeline update or app
        +  schema             Generate JSON Schema for bundle configuration
        +  summary            Summarize resources deployed by this bundle
        +  sync               Synchronize bundle tree to the workspace
        +  validate           Validate configuration
         
        ->>> [CLI] bundle auto-deploy create -t prod --deploy-as [UUID][1]
        -Pushes to branch main now deploy target prod as [UUID][1].
        -Trigger ID: [UUID][3]
        -{
        -  "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": "databricks.yml",
        -        "deployment_mode": "prod",
        -        "deploy_as": {
        -          "service_principal_client_id": "[UUID][1]"
        -        }
        -      }
        -    }
        -  }
        -}
        +Flags:
        +  -h, --help[=true|false]   help for bundle
        +      --var strings         set values for variables defined in bundle config. Example: --var="foo=bar"
         
        -=== As another user
        +Global Flags:
        +      --debug[=true|false]   enable debug logging
        +  -o, --output type          output type: text or json (default text)
        +  -p, --profile string       ~/.databrickscfg profile
        +  -t, --target string        bundle target to use (if applicable)
         
        ->>> musterr [CLI] bundle auto-deploy create -t prod --deploy-as someone@example.com
        -Error: deploy_as.user_email must be your own email. To deploy as another identity, use a service principal you have the Service Principal User role on.
        +Use "databricks bundle [command] --help" for more information about a command.
        +File [OUTPUT_DIR]/out.requests.txt not found
         
        -Host:      [DATABRICKS_URL]
        -Auth type: Personal Access Token (pat)
        -
        -Next steps:
        -  - Verify you have the required permissions for this operation
        -  - Check your identity: databricks auth describe
        -  - Consider setting up a profile: databricks auth login --profile <name>
        -{
        -  "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": "databricks.yml",
        -        "deployment_mode": "prod",
        -        "deploy_as": {
        -          "user_email": "someone@example.com"
        -        }
        -      }
        -    }
        -  }
        -}
        -
        -=== A branch other than the target's git.branch
        -
        ->>> musterr [CLI] bundle auto-deploy create -t prod --branch release
        -Error: git.branch is main for target prod, so a deploy from release would fail. Omit --branch, or change git.branch
        -
        -=== A git.branch from a variable
        -
        ->>> [CLI] bundle auto-deploy create -t staging
        -Pushes to branch release now deploy target staging as you.
        -Trigger ID: [UUID][4]
        -{
        -  "method": "PUT",
        -  "path": "/api/2.0/git-webhooks",
        -  "body": {
        -    "repo_url": "https://github.com/acme/repo",
        -    "git_provider": "GITHUB",
        -    "trigger_config": {
        -      "push_event": {
        -        "branch": "release"
        -      },
        -      "dabs_deploy": {
        -        "bundle_yml_repo_path": "databricks.yml",
        -        "deployment_mode": "staging"
        -      }
        -    }
... (131 more lines truncated, raise DATABRICKS_CLI_TEST_MAX_LOG to see more)

latest (v1.28.0): same output as main (9a14ad6)

@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: b8e3fd8

Run: 46397294854

Env 💚​RECOVERED ✅​pass 🙈​skip Time
💚​ aws linux-2core-8gb 1 173 18 2:28
💚​ aws-windows-latest-4core-16gb 1 173 18 3:10
💚​ azure linux-2core-8gb 1 172 18 2:17
💚​ azure-windows-latest-4core-16gb 1 172 18 3:13
💚​ gcp linux-2core-8gb 1 173 18 2:31
💚​ gcp-windows-latest-4core-16gb 1 173 18 2:58
Test Name aws linux-2core-8gb aws-windows-latest-4core-16gb azure linux-2core-8gb azure-windows-latest-4core-16gb gcp linux-2core-8gb gcp-windows-latest-4core-16gb
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
Top 3 slowest tests (at least 2 minutes):
duration env testname
3:12 azure-windows-latest-4core-16gb TestAccept
3:08 aws-windows-latest-4core-16gb TestAccept
2:56 gcp-windows-latest-4core-16gb TestAccept

@atreyadbrx
atreyadbrx force-pushed the dabs-ad-d4-pr3-create branch 2 times, most recently from cf6b8e1 to cfcecee Compare November 27, 2026 16:57

@denik denik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 Automated review of cfcecee42 by Opus, Fable and Astra; each finding verified against the code.

Looks close. There are two Should-fix issues inline in the branch and variable-override checks, and the provider inference/flag point is added to the existing thread.

Review points:

  • The request contract is tested only against the fake (Cloud = false, and the fake decodes with the client's own structs). Please say in the description which parts were checked against a real workspace: the enum strings (for example AZURE_DEV_OPS_SERVICES), deployment_mode carrying the target, the response fields, and the 403 for another user's email.

Findings not posted inline:

  1. Should fix acceptance/bundle/auto-deploy/create/script: three new paths have no case. These are the overrides-file branch (create.go:135), a bundle in a subdirectory (trigger.go:51; bundle_yml_repo_path is half of the trigger's key, and only a root databricks.yml is tested), and the "cannot determine the branch" error (create.go:82, for example on a detached HEAD).
  2. Plausible, cmd/bundle/autodeploy/trigger.go:50: repo_url is sent exactly as the checkout has it. If the service doesn't normalize, https://github.com/acme/repo.git (GitHub's copy-URL form) and https://github.com/acme/repo give two triggers for one target, and each push deploys twice. Worth confirming with the service, or normalizing here.

Comment thread cmd/bundle/autodeploy/create.go Outdated
return errors.New("cannot determine the branch to deploy from. Pass it with --branch")
}
// A deploy fails when the pushed branch is not the configured one.
if branchConfigured && branch != configuredBranch {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 Should fix: when git.branch is an expression that resolves to "", both fixes this command suggests fail. Resolving to "" is the documented way to unset it (see acceptance/bundle/variables/git-branch). InitFunc sees the unresolved ${var...}, so branchConfigured is true, but after Initialize configuredBranch is "":

  • without --branch: cannot determine the branch to deploy from. Pass it with --branch
  • with --branch main: git.branch is for target prod, so a deploy from main would fail. Omit --branch, or change git.branch

A deploy from main would actually pass: ValidateGitDetails skips an empty Branch. I reproduced this with a scratch acceptance test (git.branch: ${var.deployment_branch}, default ""). One possible fix: count the branch as configured only when the resolved value is non-empty (branchConfigured && configuredBranch != ""), and fall back to Git.ActualBranch for the default in that case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 30d20e7. A git.branch that resolves to "" now counts as unset, so create defaults to the current branch and accepts any --branch. The create test covers both, with the unpinned target.

Comment thread cmd/bundle/autodeploy/create.go Outdated
}
}
overrides := mutator.VariableOverridesPath(b.Config.Bundle.Target)
if _, err := os.Stat(filepath.Join(b.BundleRootPath, overrides)); err == nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 Should fix: this rejects the target whenever its overrides file exists, even if the file sets nothing. setVariable uses a file entry only for a defined variable with a non-nil value. A file containing {}, or only keys for variables the bundle no longer defines, changes nothing in the deploy. create still fails with ... variable-overrides.json overrides them here, and the suggested fix (set defaults) doesn't help. The check also re-derives setVariable's list of sources, so a source added there later would go undetected here. One possible fix: report the file only if it sets one of b.Config.Variables to a non-nil value, or have SetVariables record where each value came from. No acceptance case reaches this branch yet.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 30d20e7. The check now reads the file and counts only an entry that sets a defined variable to a non-null value, as SetVariables does. The create test covers a file with only an undefined variable (accepted) and one that sets release_branch (rejected). Recording the source in SetVariables would be sturdier, but that changes the mutator for every command, so I kept it in create.

// Auto-deploy infers only these providers. Any other host takes --git-provider, since
// a host name does not tell, for example, GitHub Enterprise from GitLab self-managed.
var providersByHost = map[string]gitwebhooks.GitProvider{
"github.com": gitwebhooks.GitProviderGitHub,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 +1. The accepted values also differ from the CLI's other --git-provider flags. apps and repos take the camelCase names case-insensitively (gitLab, see cmd/workspace/apps/git_flags.go:35). Here, --git-provider gitLab fails with value "gitLab" is not one of GITHUB, GITHUB_ENTERPRISE, GITLAB, .... So an origin on https://gitlab.com/... fails twice: inference fails, then the spelling the rest of the CLI uses is refused. A shared host table, plus accepting the existing names case-insensitively and mapping them to the API enum when building the request, would fix both.

@denik
denik requested review from a team November 29, 2026 09:16
@atreyadbrx
atreyadbrx force-pushed the dabs-ad-d4-pr3-create branch from cfcecee to 30d20e7 Compare November 29, 2026 22:25
@atreyadbrx

Copy link
Copy Markdown
Contributor Author

Thanks @denik. I pushed 30d20e7 with your points addressed. Inline threads have replies.

  • New create cases: an overrides file that sets a defined variable and one that doesn't, a bundle in a subdirectory (the request shows sub/databricks.yml), a detached HEAD, and a git.branch that resolves to "".
  • repo_url: the service normalizes it on upsert, delete and in the list filter, so https://github.com/acme/repo.git and https://github.com/acme/repo resolve to the same trigger. No CLI change is needed.
  • Real-workspace checks: none yet, and the description now says so. No test workspace serves the API, and the auto-deploy flag is still off. I'll check the enum strings, deployment_mode, the responses and the 403 once it's on.

`bundle auto-deploy create` sets up the trigger that deploys a bundle target
on every push to a branch, over the git-webhooks API. The trigger is
identified by the bundle's origin URL, its path in the repository and the
target. The Git provider is inferred for github.com and dev.azure.com, and
--git-provider covers any other host. --branch defaults to bundle.git.branch,
and --deploy-as takes a user email or a service principal application ID.

The commands load the bundle's Git details and variables, not the rest of
Initialize. Its checks and lookups run as the caller, while the deploys run
as --deploy-as.

The git-webhooks API is not in the Go SDK yet, so libs/gitwebhooks calls it
with local types. The group stays hidden until the API is public.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: atreyadbrx <atreya.misra@databricks.com>
@atreyadbrx
atreyadbrx force-pushed the dabs-ad-d4-pr3-create branch from 30d20e7 to b8e3fd8 Compare November 30, 2026 10:07

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DABs DABs related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants