Refine `mode: production` diagnostic output (#2236)

## Changes

This refines the `mode: production` diagnostic output now that the
`Detail` property is rendered as output. This is a follow-up to
https://github.com/databricks/cli/pull/1712.
This commit is contained in:
Lennart Kats (databricks) 2025-02-24 09:33:13 +01:00 committed by GitHub
parent f99716b0a5
commit 6e18d94264
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 6 deletions

View File

@ -144,8 +144,11 @@ func validateProductionMode(ctx context.Context, b *bundle.Bundle, isPrincipalUs
// We need to verify that there is only a single deployment of the current target. // We need to verify that there is only a single deployment of the current target.
// The best way to enforce this is to explicitly set root_path. // The best way to enforce this is to explicitly set root_path.
advice := fmt.Sprintf( advice := "set 'workspace.root_path' to make sure only one copy is deployed"
"set 'workspace.root_path' to make sure only one copy is deployed. A common practice is to use a username or principal name in this path, i.e. root_path: /Workspace/Users/%s/.bundle/${bundle.name}/${bundle.target}", adviceDetail := fmt.Sprintf(
"A common practice is to use a username or principal name in this path, i.e. use\n"+
"\n"+
" root_path: /Workspace/Users/%s/.bundle/${bundle.name}/${bundle.target}",
b.Config.Workspace.CurrentUser.UserName, b.Config.Workspace.CurrentUser.UserName,
) )
if !isExplicitRootSet(b) { if !isExplicitRootSet(b) {
@ -154,9 +157,21 @@ func validateProductionMode(ctx context.Context, b *bundle.Bundle, isPrincipalUs
// and neither is setting a principal. // and neither is setting a principal.
// We only show a warning for these cases since we didn't historically // We only show a warning for these cases since we didn't historically
// report an error for them. // report an error for them.
return diag.Recommendationf("target with 'mode: production' should %s", advice) return diag.Diagnostics{
{
Severity: diag.Recommendation,
Summary: "target with 'mode: production' should " + advice,
Detail: adviceDetail,
},
}
}
return diag.Diagnostics{
{
Severity: diag.Error,
Summary: "target with 'mode: production' must " + advice,
Detail: adviceDetail,
},
} }
return diag.Errorf("target with 'mode: production' must %s", advice)
} }
return nil return nil
} }

View File

@ -329,7 +329,7 @@ func TestProcessTargetModeProduction(t *testing.T) {
b := mockBundle(config.Production) b := mockBundle(config.Production)
diags := validateProductionMode(context.Background(), b, false) diags := validateProductionMode(context.Background(), b, false)
require.ErrorContains(t, diags.Error(), "target with 'mode: production' must set 'workspace.root_path' to make sure only one copy is deployed. A common practice is to use a username or principal name in this path, i.e. root_path: /Workspace/Users/lennart@company.com/.bundle/${bundle.name}/${bundle.target}") assert.ErrorContains(t, diags.Error(), "A common practice is to use a username or principal name in this path, i.e. use\n\n root_path: /Workspace/Users/lennart@company.com/.bundle/${bundle.name}/${bundle.target}")
b.Config.Workspace.StatePath = "/Shared/.bundle/x/y/state" b.Config.Workspace.StatePath = "/Shared/.bundle/x/y/state"
b.Config.Workspace.ArtifactPath = "/Shared/.bundle/x/y/artifacts" b.Config.Workspace.ArtifactPath = "/Shared/.bundle/x/y/artifacts"
@ -337,7 +337,7 @@ func TestProcessTargetModeProduction(t *testing.T) {
b.Config.Workspace.ResourcePath = "/Shared/.bundle/x/y/resources" b.Config.Workspace.ResourcePath = "/Shared/.bundle/x/y/resources"
diags = validateProductionMode(context.Background(), b, false) diags = validateProductionMode(context.Background(), b, false)
require.ErrorContains(t, diags.Error(), "target with 'mode: production' must set 'workspace.root_path' to make sure only one copy is deployed. A common practice is to use a username or principal name in this path, i.e. root_path: /Workspace/Users/lennart@company.com/.bundle/${bundle.name}/${bundle.target}") assert.ErrorContains(t, diags.Error(), "A common practice is to use a username or principal name in this path, i.e. use\n\n root_path: /Workspace/Users/lennart@company.com/.bundle/${bundle.name}/${bundle.target}")
permissions := []resources.Permission{ permissions := []resources.Permission{
{ {