Repository navigation
Add hidden bundle auto-deploy group with create - #7940
atreyadbrx wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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.
|
|
||
| cmd.RunE = func(cmd *cobra.Command, args []string) error { | ||
| // The runner deploys with the values in the configuration only. | ||
| if cmd.Flags().Changed("var") { |
There was a problem hiding this comment.
[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, |
There was a problem hiding this comment.
[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?
There was a problem hiding this comment.
🤖 +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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
[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?
| return &API{client: client}, nil | ||
| } | ||
|
|
||
| // UpsertWebhookTrigger creates the trigger, or updates the one with the same repository and target. |
There was a problem hiding this comment.
[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"?
Regression test report ✅Commit: Selected 1 changed tests (limit=20, 0 not selected) 1 tests: regression=1 unreleased=0 coverage=0 failing=0
TestAccept/bundle/auto-deploy/create: branch ✅ | main (9a14ad6) ❌ | latest (v1.28.0) ❌main (9a14ad6): latest (v1.28.0): same output as main (9a14ad6) |
✅ Integration test reportCommit: b8e3fd8
Top 3 slowest tests (at least 2 minutes):
|
cf6b8e1 to
cfcecee
Compare
denik
left a comment
There was a problem hiding this comment.
🤖 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 exampleAZURE_DEV_OPS_SERVICES),deployment_modecarrying the target, the response fields, and the 403 for another user's email.
Findings not posted inline:
- 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_pathis half of the trigger's key, and only a rootdatabricks.ymlis tested), and the "cannot determine the branch" error (create.go:82, for example on a detached HEAD). - Plausible,
cmd/bundle/autodeploy/trigger.go:50:repo_urlis sent exactly as the checkout has it. If the service doesn't normalize,https://github.com/acme/repo.git(GitHub's copy-URL form) andhttps://github.com/acme/repogive two triggers for one target, and each push deploys twice. Worth confirming with the service, or normalizing here.
| 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 { |
There was a problem hiding this comment.
🤖 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.
There was a problem hiding this comment.
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.
| } | ||
| } | ||
| overrides := mutator.VariableOverridesPath(b.Config.Bundle.Target) | ||
| if _, err := os.Stat(filepath.Join(b.BundleRootPath, overrides)); err == nil { |
There was a problem hiding this comment.
🤖 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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
🤖 +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.
cfcecee to
30d20e7
Compare
|
Thanks @denik. I pushed 30d20e7 with your points addressed. Inline threads have replies.
|
`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>
30d20e7 to
b8e3fd8
Compare
Changes
bundle auto-deploycommand group, hidden for now, withcreate.createsets up the trigger that deploys a bundle target on every push to a branch. It is identified bybundle.git.origin_url, the bundle's path in the repo (bundle.git.bundle_root_pathplus the config file name), and the target.--git-provideris needed only for hosts other than github.com and dev.azure.com. It takes the same case-insensitive values asappsandrepos(gitHub,gitLab, ...).--branchdefaults tobundle.git.branch, or to the current branch whengit.branchresolves to"".--deploy-astakes a service principal application ID or your own email, which is all the service accepts. It defaults to you.createfails early in three cases, each with a fix in the error message:--branchdiffers from the target's configuredgit.branch, since that deploy would fail the branch check.--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 makesVariableEnvPrefixandVariableOverridesPathinbundle/config/mutatorexported.ResolveVariableReferencesInGitforbundle.git), not the fullInitialize. Its target-mode checks,run_aschecks and lookups run as the caller, but the deploys run as--deploy-as.libs/gitwebhooks: a client for the git-webhooks API (PUT /api/2.0/git-webhooks). The fake handlers are inlibs/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/gitwebhookscalls it throughclient.Dowith local types that mirror the service, likelibs/dms/enrollments.godoes. The group stays hidden until the API is public.Tests
acceptance/bundle/auto-deploy/createcovers:--deploy-aswith a service principal, with your own email (-o json) and with another user's email (rejected)mode: productiontarget withoutroot_path, with--deploy-asa service principalcreatedoes not resolve, also set in the overrides file--branchthat conflicts withgit.branch, agit.branchset from a variable, one that resolves to"", and a detached HEAD--git-provider, and an unsupported--git-provider--var,BUNDLE_VAR_<name>, an overrides file that sets a defined variable and one that doesn't, and a repo with no origin--git-providerparsing.deployment_modecarrying 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.