Skip to content

Commit 409c831

Browse files
committed
..
1 parent 85a4d53 commit 409c831

File tree

5 files changed

+140
-2
lines changed

5 files changed

+140
-2
lines changed

cmd/labs/project/installer.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,21 @@ type hook struct {
3535
WarehouseTypes whTypes `yaml:"warehouse_types,omitempty"`
3636
}
3737

38+
func (h *hook) RequireRunningCluster() bool {
39+
if h.Entrypoint == nil {
40+
return false
41+
}
42+
return h.Entrypoint.RequireRunningCluster
43+
}
44+
3845
func (h *hook) HasPython() bool {
3946
return strings.HasSuffix(h.Script, ".py")
4047
}
4148

4249
func (h *hook) runHook(cmd *cobra.Command) error {
50+
if h.Script == "" {
51+
return nil
52+
}
4353
ctx := cmd.Context()
4454
envs, err := h.Prepare(cmd)
4555
if err != nil {

cmd/labs/project/installer_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func zipballFromFolder(src string) ([]byte, error) {
7373
func copyTestdata(t *testing.T, name string) string {
7474
// TODO: refactor fs.cp command into a reusable util
7575
tempDir := t.TempDir()
76+
name = strings.ReplaceAll(name, "/", string(os.PathSeparator))
7677
err := filepath.WalkDir(name, func(path string, d fs.DirEntry, err error) error {
7778
require.NoError(t, err)
7879
dst := strings.TrimPrefix(path, name)

cmd/labs/project/login.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func (lc *loginConfig) askCluster(ctx context.Context, w *databricks.WorkspaceCl
7474
if err != nil {
7575
return fmt.Errorf("select: %w", err)
7676
}
77+
w.Config.ClusterID = clusterID
7778
lc.ClusterID = clusterID
7879
return
7980
}

cmd/labs/project/project.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func readFromBytes(ctx context.Context, labsYmlRaw []byte) (*Project, error) {
5353
}
5454

5555
type Project struct {
56-
SpecVersion int `yaml:"version"`
56+
SpecVersion int `yaml:"$version"`
5757

5858
Name string `yaml:"name"`
5959
Description string `yaml:"description"`
@@ -92,7 +92,7 @@ func (p *Project) metaEntrypoint(ctx context.Context) *Entrypoint {
9292
}
9393

9494
func (p *Project) requireRunningCluster() bool {
95-
if p.Installer != nil && p.Installer.RequireRunningCluster {
95+
if p.Installer != nil && p.Installer.RequireRunningCluster() {
9696
return true
9797
}
9898
for _, v := range p.Commands {

cmd/labs/project/schema.json

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
{
2+
"id": "https://raw.githubusercontent.com/databricks/cli/feat/labs/cmd/labs/project/schema.json#",
3+
"$schema": "http://json-schema.org/draft-04/schema",
4+
"definitions": {
5+
"entrypoint": {
6+
"type": "object",
7+
"properties": {
8+
"require_running_cluster": {
9+
"type": "boolean",
10+
"default": false
11+
},
12+
"is_unauthenticated": {
13+
"type": "boolean",
14+
"default": false
15+
},
16+
"is_account_level": {
17+
"type": "boolean",
18+
"default": false
19+
},
20+
"is_bundle_aware": {
21+
"type": "boolean",
22+
"default": false
23+
}
24+
}
25+
},
26+
"hook": {
27+
"type": "object",
28+
"$ref": "#/definitions/entrypoint",
29+
"unevaluatedProperties": true,
30+
"properties": {
31+
"script": {
32+
"type": "string",
33+
"pattern": "^[A-Za-z0-9_-/\\.]+$"
34+
},
35+
"min_runtime_version": {
36+
"type": "string",
37+
"pattern": "^[0-9]+.[0-9]+$"
38+
},
39+
"require_databricks_connect": {
40+
"type": "boolean",
41+
"default": false
42+
},
43+
"warehouse_types": {
44+
"enum": [ "PRO", "CLASSIC", "TYPE_UNSPECIFIED" ]
45+
}
46+
}
47+
},
48+
"alphanum": {
49+
"type": "string",
50+
"pattern": "^[a-z0-9-]$"
51+
},
52+
"command": {
53+
"type": "object",
54+
"$ref": "#/definitions/entrypoint",
55+
"unevaluatedProperties": true,
56+
"required": ["name", "description"],
57+
"properties": {
58+
"name": {
59+
"$ref": "#/definitions/alphanum"
60+
},
61+
"description": {
62+
"type": "string"
63+
},
64+
"table_template": {
65+
"type": "string"
66+
},
67+
"flags": {
68+
"$ref": "#/definitions/flag"
69+
}
70+
}
71+
},
72+
"flag": {
73+
"type": "object",
74+
"required": ["name", "description"],
75+
"properties": {
76+
"name": {
77+
"$ref": "#/definitions/alphanum"
78+
},
79+
"description": {
80+
"type": "string"
81+
},
82+
"default": {}
83+
}
84+
}
85+
},
86+
"type": "object",
87+
"additionalProperties": false,
88+
"required": ["name", "description", "entrypoint"],
89+
"properties": {
90+
"$version": {
91+
"type": "integer",
92+
"default": 1
93+
},
94+
"name": {
95+
"$ref": "#/definitions/alphanum",
96+
"description": "Name of the project"
97+
},
98+
"description": {
99+
"type": "string",
100+
"description": "Short description of the project"
101+
},
102+
"entrypoint": {
103+
"type": "string",
104+
"description": "Script that routes subcommands"
105+
},
106+
"min_python": {
107+
"type": "string",
108+
"pattern": "^3.[0-9]+$",
109+
"description": "Minimal Python version required"
110+
},
111+
"install": {
112+
"$ref": "#/definitions/hook",
113+
"description": "Installation configuration"
114+
},
115+
"uninstall": {
116+
"$ref": "#/definitions/hook"
117+
},
118+
"commands": {
119+
"type": "array",
120+
"description": "Exposed commands",
121+
"items": {
122+
"$ref": "#/definitions/command"
123+
}
124+
}
125+
}
126+
}

0 commit comments

Comments
 (0)