Skip to content

Commit 2cb93aa

Browse files
Show deploy and run commands in terminal (#1020)
## Changes * show commands for deploying a bundle and running it in the terminal * synchronise deploys so multiple deploys do not occur simultaneously ## Tests <!-- How is this tested? -->
1 parent 772d112 commit 2cb93aa

File tree

5 files changed

+44
-18
lines changed

5 files changed

+44
-18
lines changed

packages/databricks-vscode/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,13 +772,15 @@
772772
"@databricks/databricks-sdk": "file:../../vendor/databricks-sdk.tgz",
773773
"@databricks/databricks-vscode-types": "workspace:^",
774774
"@types/lodash": "^4.14.202",
775+
"@types/shell-quote": "^1.7.5",
775776
"@vscode/debugadapter": "^1.64.0",
776777
"@vscode/extension-telemetry": "^0.9.1",
777778
"@vscode/webview-ui-toolkit": "^1.4.0",
778779
"add": "^2.0.6",
779780
"ansi-to-html": "^0.7.2",
780781
"bcryptjs": "^2.4.3",
781782
"lodash": "^4.17.21",
783+
"shell-quote": "^1.8.1",
782784
"triple-beam": "^1.4.1",
783785
"winston": "^3.11.0",
784786
"yaml": "^2.3.4"

packages/databricks-vscode/src/bundle/BundleCommands.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ResourceTreeNode as BundleResourceExplorerResourceTreeNode,
88
} from "../ui/bundle-resource-explorer/types";
99
import {BundleRunStatusManager} from "./run/BundleRunStatusManager";
10+
import {Mutex} from "../locking";
1011

1112
const RUNNABLE_RESOURCES = [
1213
"pipelines",
@@ -38,6 +39,9 @@ export class BundleCommands implements Disposable {
3839
);
3940
}
4041

42+
private refreshStateMutex = new Mutex();
43+
44+
@Mutex.synchronise("refreshStateMutex")
4145
async refreshRemoteState() {
4246
await window.withProgress(
4347
{location: {viewId: "dabsResourceExplorerView"}},
@@ -61,6 +65,9 @@ export class BundleCommands implements Disposable {
6165
await this.refreshRemoteState();
6266
}
6367

68+
private deployMutex = new Mutex();
69+
70+
@Mutex.synchronise("deployMutex")
6471
async deploy() {
6572
this.prepareOutputChannel();
6673
await window.withProgress(

packages/databricks-vscode/src/bundle/run/CustomOutputTerminal.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {ChildProcess, SpawnOptions, spawn} from "child_process";
2+
import {quote} from "shell-quote";
23
import {Pseudoterminal, Event, EventEmitter} from "vscode";
34

45
export class CustomOutputTerminal implements Pseudoterminal {
@@ -33,7 +34,9 @@ export class CustomOutputTerminal implements Pseudoterminal {
3334
options: SpawnOptions;
3435
}): void {
3536
this.isClosed = false;
36-
this.writeEmitter.fire("\x1b[2J\x1b[H");
37+
this.writeEmitter.fire("\x1b[2J\x1b[H\r\n");
38+
this.writeEmitter.fire(quote([cmd, ...args]) + "\r\n\r\n");
39+
3740
this._process = spawn(cmd, args, options);
3841
if (!this.process) {
3942
throw new Error("Can't start process: process is undefined");

packages/databricks-vscode/src/cli/CliWrapper.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {Cloud} from "../utils/constants";
1515
import {EnvVarGenerators, UrlUtils} from "../utils";
1616
import {AuthProvider} from "../configuration/auth/AuthProvider";
1717
import {removeUndefinedKeys} from "../utils/envVarGenerators";
18+
import {quote} from "shell-quote";
1819

1920
const withLogContext = logging.withLogContext;
2021
const execFile = promisify(execFileCb);
@@ -292,28 +293,25 @@ export class CliWrapper {
292293
onStdOut?: (data: string) => void,
293294
onStdError?: (data: string) => void
294295
) {
296+
const cmd = [this.cliPath, "bundle", "deploy", "--target", target];
295297
if (onStdError) {
296-
onStdError(`Deploying the bundle for target ${target}...\n\n`);
297-
onStdError(`${this.cliPath} bundle deploy --target ${target}\n`);
298+
onStdError(`Deploying the bundle for target ${target}...\n`);
298299
if (this.clusterId) {
299300
onStdError(`DATABRICKS_CLUSTER_ID=${this.clusterId}\n\n`);
300301
}
302+
onStdOut?.(quote(cmd) + "\n\n");
301303
}
302-
const p = spawn(
303-
this.cliPath,
304-
["bundle", "deploy", "--target", target],
305-
{
306-
cwd: workspaceFolder.fsPath,
307-
env: {
308-
...EnvVarGenerators.getEnvVarsForCli(configfilePath),
309-
...EnvVarGenerators.getProxyEnvVars(),
310-
...authProvider.toEnv(),
311-
// eslint-disable-next-line @typescript-eslint/naming-convention
312-
DATABRICKS_CLUSTER_ID: this.clusterId,
313-
},
314-
shell: true,
315-
}
316-
);
304+
const p = spawn(cmd[0], cmd.slice(1), {
305+
cwd: workspaceFolder.fsPath,
306+
env: {
307+
...EnvVarGenerators.getEnvVarsForCli(configfilePath),
308+
...EnvVarGenerators.getProxyEnvVars(),
309+
...authProvider.toEnv(),
310+
// eslint-disable-next-line @typescript-eslint/naming-convention
311+
DATABRICKS_CLUSTER_ID: this.clusterId,
312+
},
313+
shell: true,
314+
});
317315

318316
return await waitForProcess(p, onStdOut, onStdError);
319317
}

yarn.lock

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,13 @@ __metadata:
15581558
languageName: node
15591559
linkType: hard
15601560

1561+
"@types/shell-quote@npm:^1.7.5":
1562+
version: 1.7.5
1563+
resolution: "@types/shell-quote@npm:1.7.5"
1564+
checksum: 32b4d697c7d23dbadf40713692c47f1595f083a3b3deea76cb18e30a05d197aa9205d2b87f6d92edb60cda120b51e35d32bda96ed9b0a7e32921eed2deb4559e
1565+
languageName: node
1566+
linkType: hard
1567+
15611568
"@types/sinonjs__fake-timers@npm:^8.1.5":
15621569
version: 8.1.5
15631570
resolution: "@types/sinonjs__fake-timers@npm:8.1.5"
@@ -3617,6 +3624,7 @@ __metadata:
36173624
"@types/mocha": ^10.0.6
36183625
"@types/mock-require": ^2.0.3
36193626
"@types/node": ^20.10.4
3627+
"@types/shell-quote": ^1.7.5
36203628
"@types/sinonjs__fake-timers": ^8.1.5
36213629
"@types/tmp": ^0.2.6
36223630
"@types/triple-beam": ^1.3.5
@@ -3649,6 +3657,7 @@ __metadata:
36493657
mock-require: ^3.0.3
36503658
nyc: ^15.1.0
36513659
prettier: ^3.1.1
3660+
shell-quote: ^1.8.1
36523661
tmp-promise: ^3.0.3
36533662
triple-beam: ^1.4.1
36543663
ts-mocha: ^10.0.0
@@ -9338,6 +9347,13 @@ __metadata:
93389347
languageName: node
93399348
linkType: hard
93409349

9350+
"shell-quote@npm:^1.8.1":
9351+
version: 1.8.1
9352+
resolution: "shell-quote@npm:1.8.1"
9353+
checksum: 5f01201f4ef504d4c6a9d0d283fa17075f6770bfbe4c5850b074974c68062f37929ca61700d95ad2ac8822e14e8c4b990ca0e6e9272e64befd74ce5e19f0736b
9354+
languageName: node
9355+
linkType: hard
9356+
93419357
"side-channel@npm:^1.0.4":
93429358
version: 1.0.4
93439359
resolution: "side-channel@npm:1.0.4"

0 commit comments

Comments
 (0)