-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/go_modules/golang.org/x/mod-0.21.0
- Loading branch information
Showing
135 changed files
with
9,059 additions
and
10,192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ jobs: | |
- name: Setup Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: 1.22.x | ||
go-version: 1.22.7 | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
|
@@ -68,7 +68,7 @@ jobs: | |
- name: Setup Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: 1.22.x | ||
go-version: 1.22.7 | ||
|
||
# No need to download cached dependencies when running gofmt. | ||
cache: false | ||
|
@@ -100,18 +100,25 @@ jobs: | |
- name: Setup Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: 1.22.x | ||
go-version: 1.22.7 | ||
|
||
# Github repo: https://github.com/ajv-validator/ajv-cli | ||
- name: Install ajv-cli | ||
run: npm install -g [email protected] | ||
|
||
# Assert that the generated bundle schema is a valid JSON schema by using | ||
# ajv-cli to validate it against a sample configuration file. | ||
# ajv-cli to validate it against bundle configuration files. | ||
# By default the ajv-cli runs in strict mode which will fail if the schema | ||
# itself is not valid. Strict mode is more strict than the JSON schema | ||
# specification. See for details: https://ajv.js.org/options.html#strict-mode-options | ||
- name: Validate bundle schema | ||
run: | | ||
go run main.go bundle schema > schema.json | ||
ajv -s schema.json -d ./bundle/tests/basic/databricks.yml | ||
for file in ./bundle/internal/schema/testdata/pass/*.yml; do | ||
ajv test -s schema.json -d $file --valid | ||
done | ||
for file in ./bundle/internal/schema/testdata/fail/*.yml; do | ||
ajv test -s schema.json -d $file --invalid | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package mutator | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/databricks/cli/bundle" | ||
"github.com/databricks/cli/libs/diag" | ||
"github.com/databricks/cli/libs/dyn" | ||
) | ||
|
||
type computeIdToClusterId struct{} | ||
|
||
func ComputeIdToClusterId() bundle.Mutator { | ||
return &computeIdToClusterId{} | ||
} | ||
|
||
func (m *computeIdToClusterId) Name() string { | ||
return "ComputeIdToClusterId" | ||
} | ||
|
||
func (m *computeIdToClusterId) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics { | ||
var diags diag.Diagnostics | ||
|
||
// The "compute_id" key is set; rewrite it to "cluster_id". | ||
err := b.Config.Mutate(func(v dyn.Value) (dyn.Value, error) { | ||
v, d := rewriteComputeIdToClusterId(v, dyn.NewPath(dyn.Key("bundle"))) | ||
diags = diags.Extend(d) | ||
|
||
// Check if the "compute_id" key is set in any target overrides. | ||
return dyn.MapByPattern(v, dyn.NewPattern(dyn.Key("targets"), dyn.AnyKey()), func(p dyn.Path, v dyn.Value) (dyn.Value, error) { | ||
v, d := rewriteComputeIdToClusterId(v, dyn.Path{}) | ||
diags = diags.Extend(d) | ||
return v, nil | ||
}) | ||
}) | ||
|
||
diags = diags.Extend(diag.FromErr(err)) | ||
return diags | ||
} | ||
|
||
func rewriteComputeIdToClusterId(v dyn.Value, p dyn.Path) (dyn.Value, diag.Diagnostics) { | ||
var diags diag.Diagnostics | ||
computeIdPath := p.Append(dyn.Key("compute_id")) | ||
computeId, err := dyn.GetByPath(v, computeIdPath) | ||
|
||
// If the "compute_id" key is not set, we don't need to do anything. | ||
if err != nil { | ||
return v, nil | ||
} | ||
|
||
if computeId.Kind() == dyn.KindInvalid { | ||
return v, nil | ||
} | ||
|
||
diags = diags.Append(diag.Diagnostic{ | ||
Severity: diag.Warning, | ||
Summary: "compute_id is deprecated, please use cluster_id instead", | ||
Locations: computeId.Locations(), | ||
Paths: []dyn.Path{computeIdPath}, | ||
}) | ||
|
||
clusterIdPath := p.Append(dyn.Key("cluster_id")) | ||
nv, err := dyn.SetByPath(v, clusterIdPath, computeId) | ||
if err != nil { | ||
return dyn.InvalidValue, diag.FromErr(err) | ||
} | ||
// Drop the "compute_id" key. | ||
vout, err := dyn.Walk(nv, func(p dyn.Path, v dyn.Value) (dyn.Value, error) { | ||
switch len(p) { | ||
case 0: | ||
return v, nil | ||
case 1: | ||
if p[0] == dyn.Key("compute_id") { | ||
return v, dyn.ErrDrop | ||
} | ||
return v, nil | ||
case 2: | ||
if p[1] == dyn.Key("compute_id") { | ||
return v, dyn.ErrDrop | ||
} | ||
} | ||
return v, dyn.ErrSkip | ||
}) | ||
|
||
diags = diags.Extend(diag.FromErr(err)) | ||
return vout, diags | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package mutator_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/databricks/cli/bundle" | ||
"github.com/databricks/cli/bundle/config" | ||
"github.com/databricks/cli/bundle/config/mutator" | ||
"github.com/databricks/cli/libs/diag" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestComputeIdToClusterId(t *testing.T) { | ||
b := &bundle.Bundle{ | ||
Config: config.Root{ | ||
Bundle: config.Bundle{ | ||
ComputeId: "compute-id", | ||
}, | ||
}, | ||
} | ||
|
||
diags := bundle.Apply(context.Background(), b, mutator.ComputeIdToClusterId()) | ||
assert.NoError(t, diags.Error()) | ||
assert.Equal(t, "compute-id", b.Config.Bundle.ClusterId) | ||
assert.Empty(t, b.Config.Bundle.ComputeId) | ||
|
||
assert.Len(t, diags, 1) | ||
assert.Equal(t, "compute_id is deprecated, please use cluster_id instead", diags[0].Summary) | ||
assert.Equal(t, diag.Warning, diags[0].Severity) | ||
} | ||
|
||
func TestComputeIdToClusterIdInTargetOverride(t *testing.T) { | ||
b := &bundle.Bundle{ | ||
Config: config.Root{ | ||
Targets: map[string]*config.Target{ | ||
"dev": { | ||
ComputeId: "compute-id-dev", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
diags := bundle.Apply(context.Background(), b, mutator.ComputeIdToClusterId()) | ||
assert.NoError(t, diags.Error()) | ||
assert.Empty(t, b.Config.Targets["dev"].ComputeId) | ||
|
||
diags = diags.Extend(bundle.Apply(context.Background(), b, mutator.SelectTarget("dev"))) | ||
assert.NoError(t, diags.Error()) | ||
|
||
assert.Equal(t, "compute-id-dev", b.Config.Bundle.ClusterId) | ||
assert.Empty(t, b.Config.Bundle.ComputeId) | ||
|
||
assert.Len(t, diags, 1) | ||
assert.Equal(t, "compute_id is deprecated, please use cluster_id instead", diags[0].Summary) | ||
assert.Equal(t, diag.Warning, diags[0].Severity) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.