Skip to content

Commit b5a499d

Browse files
pieternilia-db
andauthored
Add flag to validate and summary commands to include location information (#2189)
## Changes The (hidden) `--include-locations` flag instructs commands to include location information for the configuration tree in the JSON output (if selected). Paths to configuration files are relative to the bundle root directory. ## Tests New acceptance test for the validate command. --------- Co-authored-by: Ilia Babanov <ilia.babanov@databricks.com>
1 parent 491af65 commit b5a499d

File tree

14 files changed

+464
-0
lines changed

14 files changed

+464
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
bundle:
2+
name: include_locations
3+
4+
include:
5+
- resources/*.yml
6+
- override.yml
7+
8+
targets:
9+
dev: {}
10+
prod: {}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"files": [
3+
"databricks.yml",
4+
"override.yml",
5+
"resources/job.yml"
6+
],
7+
"locations": {
8+
"bundle": [
9+
[
10+
0,
11+
2,
12+
3
13+
]
14+
],
15+
"include": [
16+
[
17+
0,
18+
5,
19+
3
20+
]
21+
],
22+
"resources": [
23+
[
24+
2,
25+
2,
26+
3
27+
],
28+
[
29+
1,
30+
4,
31+
7
32+
]
33+
],
34+
"resources.jobs": [
35+
[
36+
2,
37+
3,
38+
5
39+
],
40+
[
41+
1,
42+
5,
43+
9
44+
]
45+
],
46+
"resources.jobs.my_job": [
47+
[
48+
2,
49+
4,
50+
7
51+
],
52+
[
53+
1,
54+
6,
55+
11
56+
]
57+
],
58+
"resources.jobs.my_job.tasks": [
59+
[
60+
2,
61+
6,
62+
9
63+
],
64+
[
65+
1,
66+
8,
67+
13
68+
]
69+
],
70+
"resources.jobs.my_job.tasks[0]": [
71+
[
72+
2,
73+
6,
74+
11
75+
],
76+
[
77+
1,
78+
8,
79+
15
80+
]
81+
],
82+
"targets": [
83+
[
84+
0,
85+
9,
86+
3
87+
],
88+
[
89+
1,
90+
2,
91+
3
92+
]
93+
]
94+
},
95+
"version": 1
96+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"files": [
3+
"databricks.yml",
4+
"override.yml",
5+
"resources/job.yml"
6+
],
7+
"locations": {
8+
"bundle": [
9+
[
10+
0,
11+
2,
12+
3
13+
]
14+
],
15+
"include": [
16+
[
17+
0,
18+
5,
19+
3
20+
]
21+
],
22+
"resources": [
23+
[
24+
2,
25+
2,
26+
3
27+
],
28+
[
29+
1,
30+
14,
31+
7
32+
]
33+
],
34+
"resources.jobs": [
35+
[
36+
2,
37+
3,
38+
5
39+
],
40+
[
41+
1,
42+
15,
43+
9
44+
]
45+
],
46+
"resources.jobs.my_job": [
47+
[
48+
2,
49+
4,
50+
7
51+
],
52+
[
53+
1,
54+
16,
55+
11
56+
]
57+
],
58+
"resources.jobs.my_job.tasks": [
59+
[
60+
2,
61+
6,
62+
9
63+
],
64+
[
65+
1,
66+
18,
67+
13
68+
]
69+
],
70+
"resources.jobs.my_job.tasks[0]": [
71+
[
72+
2,
73+
6,
74+
11
75+
],
76+
[
77+
1,
78+
18,
79+
15
80+
]
81+
],
82+
"targets": [
83+
[
84+
0,
85+
9,
86+
3
87+
],
88+
[
89+
1,
90+
2,
91+
3
92+
]
93+
]
94+
},
95+
"version": 1
96+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
>>> [CLI] bundle validate -t dev -o json --include-locations
3+
4+
>>> [CLI] bundle validate -t prod -o json --include-locations
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
targets:
2+
dev:
3+
resources:
4+
jobs:
5+
my_job:
6+
name: dev name
7+
tasks:
8+
- task_key: default
9+
notebook_task:
10+
notebook_path: ./src/dev.py
11+
12+
prod:
13+
resources:
14+
jobs:
15+
my_job:
16+
name: prod name
17+
tasks:
18+
- task_key: default
19+
notebook_task:
20+
notebook_path: ./src/prod.py
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
resources:
2+
jobs:
3+
my_job:
4+
name: name
5+
tasks:
6+
- task_key: default
7+
notebook_task:
8+
notebook_path: ../src/dev.py
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
trace $CLI bundle validate -t dev -o json --include-locations | jq .__locations > output.dev.json
2+
trace $CLI bundle validate -t prod -o json --include-locations | jq .__locations > output.prod.json
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Databricks notebook source
2+
print("Hello, World!")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Databricks notebook source
2+
print("Hello, World!")
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package mutator
2+
3+
import (
4+
"context"
5+
6+
"github.com/databricks/cli/bundle"
7+
"github.com/databricks/cli/libs/diag"
8+
"github.com/databricks/cli/libs/dyn/dynloc"
9+
)
10+
11+
type populateLocations struct{}
12+
13+
// PopulateLocations collects location information for the entire configuration tree
14+
// and includes this as the [config.Root.Locations] property.
15+
func PopulateLocations() bundle.Mutator {
16+
return &populateLocations{}
17+
}
18+
19+
func (m *populateLocations) Name() string {
20+
return "PopulateLocations"
21+
}
22+
23+
func (m *populateLocations) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
24+
locs, err := dynloc.Build(
25+
b.Config.Value(),
26+
// Make all paths relative to the bundle root.
27+
b.BundleRootPath,
28+
)
29+
if err != nil {
30+
return diag.FromErr(err)
31+
}
32+
33+
b.Config.Locations = &locs
34+
return nil
35+
}

0 commit comments

Comments
 (0)