Skip to content

Commit 5497c7b

Browse files
1 parent c52b23a commit 5497c7b

File tree

12 files changed

+402
-22
lines changed

12 files changed

+402
-22
lines changed

.github/workflows/create-build-artifacts.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Publish nightly release
1+
name: Create Build Artefacts
22

33
on:
44
workflow_call:
@@ -72,6 +72,12 @@ jobs:
7272
# TODO: Remove this once the bricks repo is public
7373
GH_TOKEN: ${{ secrets.DECO_GITHUB_TOKEN }}
7474

75+
- name: Update arch in package.json
76+
working-directory: packages/databricks-vscode
77+
run: |
78+
yarn ts-node scripts/set_arch_in_package.ts -f package.json -b ${{ matrix.arch.bricks_arch }} -V ${{ matrix.arch.vsix_arch }} -c $(git rev-parse --short HEAD)
79+
yarn run fix
80+
7581
- run: yarn run package -t ${{ matrix.arch.vsix_arch }}
7682
working-directory: packages/databricks-vscode
7783

packages/databricks-vscode/package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"galleryBanner": {
2929
"theme": "light"
3030
},
31-
"homepage": "https://https://github.com/databricks/databricks-vscode/blob/main/README.md",
31+
"homepage": "https://github.com/databricks/databricks-vscode/blob/main/README.md",
3232
"bugs": {
3333
"url": "https://github.com/databricks/databricks-vscode/issues"
3434
},
@@ -549,7 +549,8 @@
549549
"test:integ": "yarn run test:integ:prepare && yarn run test:integ:install-vsix && yarn run test:integ:run",
550550
"test:cov": "nyc yarn run test:unit",
551551
"test": "yarn run test:lint && yarn run test:unit",
552-
"clean": "rm -rf node_modules out .vscode-test"
552+
"clean": "rm -rf node_modules out .vscode-test",
553+
"ts-node": "ts-node"
553554
},
554555
"dependencies": {
555556
"@databricks/databricks-sdk": "workspace:^",
@@ -558,7 +559,8 @@
558559
"@vscode/debugadapter": "^1.58.0",
559560
"@vscode/webview-ui-toolkit": "^1.1.0",
560561
"ansi-to-html": "^0.7.2",
561-
"triple-beam": "^1.3.0"
562+
"triple-beam": "^1.3.0",
563+
"winston": "^3.8.2"
562564
},
563565
"devDependencies": {
564566
"@istanbuljs/nyc-config-typescript": "^1.0.2",
@@ -569,6 +571,7 @@
569571
"@types/node": "^18.11.9",
570572
"@types/tmp": "^0.2.3",
571573
"@types/vscode": "^1.69.1",
574+
"@types/yargs": "^17.0.14",
572575
"@typescript-eslint/eslint-plugin": "^5.42.0",
573576
"@typescript-eslint/parser": "^5.42.0",
574577
"@vscode/test-electron": "^2.2.0",
@@ -586,7 +589,7 @@
586589
"typescript": "^4.8.4",
587590
"vsce": "^2.13.0",
588591
"vscode-extension-tester": "5.1.x",
589-
"winston": "^3.8.2"
592+
"yargs": "^17.6.2"
590593
},
591594
"nyc": {
592595
"extends": "@istanbuljs/nyc-config-typescript",
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import fs from "node:fs/promises";
2+
import yargs from "yargs";
3+
4+
async function main() {
5+
const argv = await yargs
6+
.option("bricksArch", {
7+
alias: "b",
8+
description: "Architecture of bricks-cli.",
9+
type: "string",
10+
requiresArg: true,
11+
})
12+
.option("vsixArch", {
13+
alias: "V",
14+
description: "Architecture of vsix",
15+
type: "string",
16+
requiresArg: true,
17+
})
18+
.option("commitSha", {
19+
alias: "c",
20+
description:
21+
"Commit sha of the commit from which this build is created.",
22+
type: "string",
23+
requiresArg: true,
24+
})
25+
.option("packageFile", {
26+
alias: "f",
27+
description: "path/to/package.json",
28+
type: "string",
29+
requiresArg: true,
30+
}).argv;
31+
32+
const rawData = await fs.readFile(argv.packageFile!, {
33+
encoding: "utf-8",
34+
});
35+
const jsonData = JSON.parse(rawData);
36+
37+
jsonData["arch"] = {
38+
bricksArch: argv.bricksArch,
39+
vsixArch: argv.vsixArch,
40+
};
41+
jsonData["commitSha"] = argv.commitSha;
42+
43+
await fs.writeFile(argv.packageFile!, JSON.stringify(jsonData), {
44+
encoding: "utf-8",
45+
});
46+
}
47+
48+
main();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"module": "CommonJS",
4+
"target": "ES2020",
5+
"outDir": "out",
6+
"esModuleInterop": true,
7+
"isolatedModules": true,
8+
"lib": ["ES2020", "ES2021.String"],
9+
"sourceMap": true,
10+
"strict": true /* enable all strict type-checking options */,
11+
"forceConsistentCasingInFileNames": true,
12+
"experimentalDecorators": true
13+
}
14+
}

packages/databricks-vscode/src/configuration/ConfigurationDataProvider.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ export class ConfigurationDataProvider
9090
contextValue:
9191
cluster.state === "RUNNING"
9292
? "clusterRunning"
93-
: cluster.state === "PENDING"
93+
: ["PENDING", "RESIZING", "RESTARTING"].includes(
94+
cluster.state
95+
)
9496
? "clusterPending"
9597
: "clusterStopped",
9698
});

packages/databricks-vscode/src/extension.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ import {ProjectConfigFileWatcher} from "./configuration/ProjectConfigFileWatcher
1515
import {QuickstartCommands} from "./quickstart/QuickstartCommands";
1616
import {showQuickStartOnFirstUse} from "./quickstart/QuickStart";
1717
import {PublicApi} from "@databricks/databricks-vscode-types";
18-
import {LoggerManager} from "./logger";
19-
import {UtilsCommands} from "./utils/UtilsCommands";
18+
import {LoggerManager, Loggers} from "./logger";
2019
import {NamedLogger} from "@databricks/databricks-sdk/dist/logging";
2120
import {workspaceConfigs} from "./WorkspaceConfigs";
21+
import {PackageJsonUtils, UtilsCommands} from "./utils";
22+
23+
export async function activate(
24+
context: ExtensionContext
25+
): Promise<PublicApi | undefined> {
26+
if (!(await PackageJsonUtils.checkArchCompat(context))) {
27+
return undefined;
28+
}
2229

23-
export function activate(context: ExtensionContext): PublicApi | undefined {
2430
if (
2531
workspace.workspaceFolders === undefined ||
2632
workspace.workspaceFolders?.length === 0
@@ -41,6 +47,10 @@ export function activate(context: ExtensionContext): PublicApi | undefined {
4147
loggerManager.initLoggers();
4248
}
4349

50+
NamedLogger.getOrCreate(Loggers.Extension).debug("Metadata", {
51+
metadata: await PackageJsonUtils.getMetadata(context),
52+
});
53+
4454
context.subscriptions.push(
4555
commands.registerCommand(
4656
"databricks.logs.openFolder",
@@ -230,7 +240,7 @@ export function activate(context: ExtensionContext): PublicApi | undefined {
230240
});
231241

232242
//utils
233-
const utilCommands = new UtilsCommands();
243+
const utilCommands = new UtilsCommands.UtilsCommands();
234244
context.subscriptions.push(
235245
commands.registerCommand(
236246
"databricks.utils.openExternal",

packages/databricks-vscode/src/logger/LoggerManager.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@ import {unlink, access} from "fs/promises";
1010
export class LoggerManager {
1111
constructor(readonly context: ExtensionContext) {}
1212

13-
private getFileTransport(filename: string) {
13+
private getFileTransport(
14+
filename: string,
15+
extraOptions?: Omit<
16+
transports.FileTransportOptions,
17+
"filename" | "format"
18+
>
19+
) {
1420
return new transports.File({
1521
format: format.combine(format.timestamp(), format.json()),
1622
filename: filename,
23+
...extraOptions,
1724
});
1825
}
1926

@@ -34,8 +41,10 @@ export class LoggerManager {
3441
return loggers.add(name, {
3542
level: "debug",
3643
transports: [
37-
getOutputConsoleTransport(outputChannel),
38-
this.getFileTransport(logFile),
44+
getOutputConsoleTransport(outputChannel, {
45+
level: "debug",
46+
}),
47+
this.getFileTransport(logFile, {level: "all"}),
3948
],
4049
});
4150
},
@@ -45,8 +54,6 @@ export class LoggerManager {
4554

4655
/**
4756
This logger collects all the logs in the extension.
48-
49-
TODO Make this logger log to a seperate (or common?) output console in vscode
5057
*/
5158
NamedLogger.getOrCreate(
5259
"Extension",
@@ -55,8 +62,10 @@ export class LoggerManager {
5562
return loggers.add(name, {
5663
level: "error",
5764
transports: [
58-
getOutputConsoleTransport(outputChannel),
59-
this.getFileTransport(logFile),
65+
getOutputConsoleTransport(outputChannel, {
66+
level: "error",
67+
}),
68+
this.getFileTransport(logFile, {level: "all"}),
6069
],
6170
});
6271
},

packages/databricks-vscode/src/logger/outputConsoleTransport.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ function recursiveTruncate(obj: any, depth: number) {
5454
return obj;
5555
}
5656

57-
export function getOutputConsoleTransport(outputChannel: OutputChannel) {
57+
export function getOutputConsoleTransport(
58+
outputChannel: OutputChannel,
59+
extraOptions?: Omit<transports.StreamTransportOptions, "stream" | "format">
60+
) {
5861
return new transports.Stream({
5962
format: format((info: any) => {
6063
const stripped = Object.assign({}, info) as any;
@@ -93,5 +96,6 @@ export function getOutputConsoleTransport(outputChannel: OutputChannel) {
9396
stream: new OutputConsoleStream(outputChannel, {
9497
defaultEncoding: "utf-8",
9598
}),
99+
...extraOptions,
96100
});
97101
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from "./fileUtils";
22
export * as UrlUtils from "./urlUtils";
3-
export * from "./UtilsCommands";
3+
export * as UtilsCommands from "./UtilsCommands";
4+
export * as PackageJsonUtils from "./packageJsonUtils";
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import assert from "assert";
2+
import {writeFile} from "fs/promises";
3+
import * as tmp from "tmp";
4+
import {anything, instance, mock, when} from "ts-mockito";
5+
import {ExtensionContext} from "vscode";
6+
import {
7+
getCorrectVsixInstallString,
8+
getMetadata,
9+
isCompatibleArchitecture,
10+
isEqual,
11+
nodeArchMap,
12+
nodeOsMap,
13+
vsixArchMap,
14+
} from "./packageJsonUtils";
15+
16+
describe(__filename, () => {
17+
it("should correctly check compatibility", () => {
18+
assert.ok(
19+
!isCompatibleArchitecture(
20+
"no match",
21+
{os: "macos", arch: "arm64"},
22+
{os: "linux", arch: "arm64"},
23+
{packageName: "test", version: "0.0.0"}
24+
)
25+
);
26+
27+
assert.ok(
28+
isCompatibleArchitecture(
29+
"match",
30+
{os: "macos", arch: "arm64"},
31+
{os: "macos", arch: "arm64"},
32+
{packageName: "test", version: "0.0.0"}
33+
)
34+
);
35+
});
36+
37+
it("should correctly compare archs", () => {
38+
assert.ok(
39+
!isEqual({os: "macos", arch: "arm64"}, {os: "linux", arch: "arm64"})
40+
);
41+
42+
assert.ok(
43+
isEqual({os: "macos", arch: "arm64"}, {os: "macos", arch: "arm64"})
44+
);
45+
});
46+
47+
it("should correctly read metadata", async () => {
48+
const {name: path} = tmp.fileSync();
49+
const metaData = {
50+
name: "name",
51+
version: "version",
52+
arch: {
53+
bricksArch: "bricksArch",
54+
vsixArch: "vsixArch",
55+
},
56+
commitSha: "commitSha",
57+
};
58+
await writeFile(path, JSON.stringify(metaData));
59+
60+
const context = mock<ExtensionContext>();
61+
when(context.asAbsolutePath(anything())).thenReturn(path);
62+
63+
const actualMetadata = await getMetadata(instance(context));
64+
65+
assert.deepEqual(actualMetadata, {
66+
packageName: "name",
67+
version: "version",
68+
bricksArch: "bricksArch",
69+
vsixArch: "vsixArch",
70+
commitSha: "commitSha",
71+
});
72+
});
73+
74+
it("should correctly format vsix install string", () => {
75+
nodeOsMap.forEach((os) => {
76+
nodeArchMap.forEach((arch) => {
77+
const archDetails = {os, arch};
78+
const actual = getCorrectVsixInstallString(archDetails, {
79+
packageName: "name",
80+
version: "0.0.0",
81+
});
82+
83+
const vsixArchString = Array.from(vsixArchMap).find(
84+
(keyValue) => isEqual(keyValue[1], archDetails)
85+
)?.[0];
86+
87+
vsixArchString
88+
? assert.equal(
89+
actual,
90+
`Please install name-${vsixArchString}-0.0.0.vsix`
91+
)
92+
: assert.equal(
93+
actual,
94+
"Current system architecture is not supported."
95+
);
96+
});
97+
});
98+
});
99+
});

0 commit comments

Comments
 (0)