Skip to content

New hidden install-pipelines-cli command that creates pipelines symlink to databricks #3009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Jun 20, 2025
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
60260b7
New hidden install-dlt command that creates symlink in same PATH as d…
alyssa-db Jun 6, 2025
6750e38
addressed code comments prior to testing
alyssa-db Jun 10, 2025
359a77d
added acceptance tests
alyssa-db Jun 10, 2025
d12a848
modified acceptance test PATH to add databricks and helper tools
alyssa-db Jun 10, 2025
e3c41fc
Merge branch 'databricks:main' into install-dlt-feat
alyssa-db Jun 10, 2025
ca3d09b
made dlt path be based on executable
alyssa-db Jun 11, 2025
d168e96
added acceptance test python script, refactored install-dlt
alyssa-db Jun 12, 2025
c282769
draft acceptance test and acceptance test DLT setup
alyssa-db Jun 12, 2025
e771366
acceptance test logic
alyssa-db Jun 12, 2025
9fac6c7
Merge remote-tracking branch 'upstream/main' into install-dlt-feat
alyssa-db Jun 12, 2025
14b7d31
windows path
alyssa-db Jun 12, 2025
be032fa
trying environment variable changes'
alyssa-db Jun 13, 2025
6429b3a
test symlink
alyssa-db Jun 13, 2025
2bf67ef
Merge branch 'main' into install-dlt-feat
alyssa-db Jun 13, 2025
9bf008f
dlt init checker
alyssa-db Jun 13, 2025
8576254
erroring checks
alyssa-db Jun 13, 2025
523c76d
added line for python packages
alyssa-db Jun 13, 2025
ce1c01a
Merge branch 'main' into install-dlt-feat
alyssa-db Jun 17, 2025
cc6454b
Added json path output and refactoring
alyssa-db Jun 17, 2025
8e020dc
checking windows
alyssa-db Jun 17, 2025
12b1e64
not clean paths windows
alyssa-db Jun 18, 2025
2d8da98
error order
alyssa-db Jun 18, 2025
1da3ff0
removed json, added relative path to tests
alyssa-db Jun 18, 2025
be778d6
modified invoke statement
alyssa-db Jun 18, 2025
f9dc119
Merge branch 'main' into install-dlt-feat
alyssa-db Jun 19, 2025
fb62458
renamed dlt to pipelines
alyssa-db Jun 19, 2025
9156ad5
renamed to install-pipelines-cli
alyssa-db Jun 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions acceptance/dlt/install-dlt/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

=== install dlt
>>> errcode [CLI] install-dlt -o json
dlt successfully installed in directory "[BUILD_DIR]"

>>> [BUILD_DIR]/dlt
DLT command verified

=== dlt already installed
>>> errcode [CLI] install-dlt
dlt already installed in directory "[BUILD_DIR]"

=== dlt file exists, should not overwrite
>>> errcode [CLI] install-dlt -d tmpdir -o json
cannot install dlt CLI: "tmpdir/dlt" already exists
Error: installation failed

Exit code: 1

=== Executable not called as databricks
>>> errcode ./notdatabricks install-dlt -o json
dlt successfully installed in directory "[TEST_TMP_DIR]"

>>> [TEST_TMP_DIR]/dlt
DLT command verified
20 changes: 20 additions & 0 deletions acceptance/dlt/install-dlt/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
title "install dlt"
dlt=$(trace errcode $CLI install-dlt -o json | jq -r .symlink_path)
trace $dlt | head -n1 | grep -q "DLT CLI" && echo "DLT command verified" || echo "DLT command failed"

title "dlt already installed"
trace errcode $CLI install-dlt
rm -f "$(dirname $CLI)/dlt"

title "dlt file exists, should not overwrite"
mkdir -p tmpdir
touch tmpdir/dlt
trace errcode $CLI install-dlt -d tmpdir -o json | jq -r .symlink_path
rm -rf tmpdir

title "Executable not called as databricks"
cp $CLI notdatabricks
dlt=$(trace errcode ./notdatabricks install-dlt -o json | jq -r .symlink_path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also not clear here what's being asserted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case that the user has databricks aliased, want to make sure the install-dlt command still works.

trace $dlt | head -n1 | grep -q "DLT CLI" && echo "DLT command verified" || echo "DLT command failed"
rm -f notdatabricks
rm -f dlt
8 changes: 8 additions & 0 deletions acceptance/dlt/install-dlt/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Fix path with reverse slashes in the output for Windows.
[[Repls]]
Old = '\\\\'
New = '/'

[[Repls]]
Old = '\\'
New = '/'
2 changes: 2 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/databricks/cli/cmd/auth"
"github.com/databricks/cli/cmd/bundle"
"github.com/databricks/cli/cmd/configure"
"github.com/databricks/cli/cmd/dlt"
"github.com/databricks/cli/cmd/fs"
"github.com/databricks/cli/cmd/labs"
"github.com/databricks/cli/cmd/root"
Expand Down Expand Up @@ -106,6 +107,7 @@ func New(ctx context.Context) *cobra.Command {
cli.AddCommand(sync.New())
cli.AddCommand(version.New())
cli.AddCommand(selftest.New())
cli.AddCommand(dlt.InstallDLT())

// Add workspace command groups, filtering out empty groups or groups with only hidden commands.
allGroups := workspace.Groups()
Expand Down
18 changes: 18 additions & 0 deletions cmd/dlt/dlt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package dlt

import (
"github.com/spf13/cobra"
)

func New() *cobra.Command {
cmd := &cobra.Command{
Use: "dlt",
Short: "DLT CLI",
Long: "DLT CLI (stub, to be filled in)",
Run: func(cmd *cobra.Command, args []string) {
_ = cmd.Help()
},
}

return cmd
}
85 changes: 85 additions & 0 deletions cmd/dlt/install_dlt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package dlt

import (
"context"
"errors"
"fmt"
"os"
"path/filepath"

"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/flags"
"github.com/spf13/cobra"
)

type installDLTResponse struct {
SymlinkPath string `json:"symlink_path"`
}

func installDLTSymlink(directory string) (string, error) {
path, err := os.Executable()
if err != nil {
return "", err
}
realPath, err := filepath.EvalSymlinks(path)
if err != nil {
return "", err
}

dir := directory
if dir == "" {
dir = filepath.Dir(path)
}
dltPath := filepath.Join(dir, "dlt")

_, err = os.Lstat(dltPath)
if err != nil {
if !errors.Is(err, os.ErrNotExist) {
return "", err
}
err = os.Symlink(realPath, dltPath)
if err != nil {
return "", err
}
cmdio.LogString(context.Background(), fmt.Sprintf("dlt successfully installed in directory %q", dir))
return dltPath, nil
}

target, err := filepath.EvalSymlinks(dltPath)
if err != nil {
return "", err
}
if realPath == target {
cmdio.LogString(context.Background(), fmt.Sprintf("dlt already installed in directory %q", dir))
return dltPath, nil
}
cmdio.LogString(context.Background(), fmt.Sprintf("cannot install dlt CLI: %q already exists", dltPath))
return "", errors.New("installation failed")
}

func InstallDLT() *cobra.Command {
var directory string
cmd := &cobra.Command{
Use: "install-dlt",
Short: "Install DLT",
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
dltPath, err := installDLTSymlink(directory)
if err != nil {
return err
}
response := installDLTResponse{
SymlinkPath: dltPath,
}
switch root.OutputType(cmd) {
case flags.OutputJSON:
return cmdio.Render(cmd.Context(), response)
default:
return nil
}
},
}
cmd.Flags().StringVarP(&directory, "directory", "d", "", "Directory in which to install dlt CLI (defaults to databricks CLI's directory)")
return cmd
}
18 changes: 17 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,30 @@ package main
import (
"context"
"os"
"path/filepath"
"runtime"

"github.com/databricks/cli/cmd"
"github.com/databricks/cli/cmd/dlt"
"github.com/databricks/cli/cmd/root"
"github.com/spf13/cobra"
)

// If invoked as 'dlt' (or 'dlt.exe' on Windows), returns DLT-specific commands,
// otherwise returns the databricks CLI commands. This is used to allow the same
// binary to be used for both DLT and databricks CLI commands.
func getCommand(ctx context.Context) *cobra.Command {
invokedAs := filepath.Base(os.Args[0])
if invokedAs == "dlt" || (runtime.GOOS == "windows" && invokedAs == "dlt.exe") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you can replace it with strings.StartsWith for invokedAs as nit

return dlt.New()
}
return cmd.New(ctx)
}

func main() {
ctx := context.Background()
err := root.Execute(ctx, cmd.New(ctx))
command := getCommand(ctx)
err := root.Execute(ctx, command)
if err != nil {
os.Exit(1)
}
Expand Down
Loading