Skip to content

Commit

Permalink
DEV2-2532 - refactor enterprise v1 (#1075)
Browse files Browse the repository at this point in the history
* extract enterprise dependenies

* refactor webpack build

* refactor gh action

* ga extesnion should check the cloudhost url

* add self hosted config section

* revert main extension change

* wip

* fix merge

* review

* dixes

* dixes

* fixes

* fixes

* fixes

* fixes

* DEV2-2703: Add sign in / sign out for self hosted (#1102)

* DEV2-2703: Add sign in / sign out for self hosted (#1102)

* DEV2-2703: Add sign in / sign out for self hosted

* missing settings

* Fix loggin

* use http if needed

* fix ci

* use updater name

* webpack fixes

* validate public build

* validate enterprise build

* fixes

* fix test

---------

Co-authored-by: Assaf Sapir <[email protected]>
  • Loading branch information
dimacodota and Assaf Sapir authored May 17, 2023
1 parent 084bd9a commit b343007
Show file tree
Hide file tree
Showing 57 changed files with 868 additions and 5,328 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/package-enterprise.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Create Enterprise Release

on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*.*.*' # Push events to matching v*, i.e. v1.0.0, v20.15.10
- '!v*.*.*-alpha.*'
workflow_dispatch:

jobs:
build:
name: Create Enterprise Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: '16.19'
- name: Tag Version
id: tag-version
run: echo "RELEASE_VERSION=$(echo ${GITHUB_REF:10})" >> $GITHUB_OUTPUT

- name: modify readme
run: |
echo "" > ./README.md
echo "buildId: ${{ github.sha }}" >> ./README.md
echo "" >> ./README.md
- name: Install
run: yarn install --frozen-lockfile --ignore-optional

- name: Modify package
run: npm pkg set name=\"tabnine-vscode-self-hosted-updater\" && npm pkg set displayName=\"Tabnine Enterprise\" && npm pkg delete __metadata

- name: Package
run: yarn run vsce:package:enterprise --out ./tabnine-vscode-enterprise-${{ steps.tag-version.outputs.RELEASE_VERSION }}.vsix

- name: Package Contains Extension
run: test "$(unzip -l tabnine-vscode-enterprise-${{ steps.tag-version.outputs.RELEASE_VERSION }}.vsix | grep out/extension.js | wc -l)" = "1"

- name: Package is Enterprise Extension
run: test "$(unzip -l tabnine-vscode-enterprise-${{ steps.tag-version.outputs.RELEASE_VERSION }}.vsix | cat out/extension.js | grep tabnine.enterprise)" -eq 1

- name: Set stable version file
run: |
echo ${{ steps.tag-version.outputs.RELEASE_VERSION }} > stable
- name: Authenticate to Google Cloud
uses: "google-github-actions/auth@v1"
with:
credentials_json: ${{ secrets.GCS_RELEASE_KEY }}

- name: ⬆️ Upload latest stable version to GCS
uses: google-github-actions/upload-cloud-storage@v1
with:
path: stable
destination: tabnine-self-hosted-artifacts/vscode
parent: false
gzip: false
headers: |-
content-type: text/plain
- name: ⬆️ Upload vsix to GS
uses: google-github-actions/upload-cloud-storage@v0
with:
path: tabnine-vscode-enterprise-${{ steps.tag-version.outputs.RELEASE_VERSION }}.vsix
destination: tabnine-self-hosted-artifacts/vscode
parent: false
59 changes: 0 additions & 59 deletions .github/workflows/packageOnPrem.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ jobs:
display-name: Tabnine AI
- name: Package Contains Extension
run: test "$(unzip -l tabnine-vscode-${{ steps.package-version.outputs.current-version }}.vsix | grep out/extension.js | wc -l)" = "1"
- name: Package is Public (non enterprise) Extension
run: test "$(unzip -l tabnine-vscode-${{ steps.package-version.outputs.current-version }}.vsix | cat out/extension.js | grep tabnine.enterprise)" -eq 0
- name: Create Release
id: create_release
uses: actions/create-release@v1
Expand Down
28 changes: 24 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,31 @@
"--extensionDevelopmentPath=${workspaceRoot}",
"--logPluginHostCommunication"
],
"stopOnEntry": false,
"sourceMaps": true,
"outDir": "${workspaceRoot}/out/src",
"preLaunchTask": "npm: build"
},
{
"name": "Launch Enterprise Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "code",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}",
"--logPluginHostCommunication"
],
"sourceMaps": true,
"preLaunchTask": "npm: build:enterprise"
},
{
"name": "Launch Extension with vscode from source",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${workspaceFolder:vscode}/scripts/code.sh",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}",
"--logPluginHostCommunication"
],
"sourceMaps": true,
"preLaunchTask": "npm: build"
},
{
Expand All @@ -25,9 +47,7 @@
"--extensionDevelopmentPath=${workspaceRoot}",
"--logPluginHostCommunication"
],
"stopOnEntry": false,
"sourceMaps": true,
"outDir": "${workspaceRoot}/out/src",
"preLaunchTask": "npm: build"
},{
"name": "Extension Tests",
Expand Down
21 changes: 0 additions & 21 deletions buildOnPrem.sh

This file was deleted.

29 changes: 11 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,34 +96,21 @@
"main": "./out/extension",
"scripts": {
"analyze:bundle": "webpack --env analyzeBundle",
"vscode:prepublish": "yarn --frozen-lockfile && yarn clear-out && yarn webpack",
"webpack": "yarn webpack:GA",
"webpack:OnPrem": "webpack --mode production --env onPrem",
"webpack:GA": "webpack --mode production",
"vscode:prepublish": "yarn --frozen-lockfile && yarn clear-out && webpack --mode production --env ${MODE:-public}",
"compile": "webpack --mode development --watch",
"build": "webpack --mode development",
"build:enterprise": "webpack --mode development --env enterprise",
"test:copyassets": "ncp ./src/test/fixture ./out/test/fixture/",
"prettier": "prettier --write src/",
"prettier:check": "prettier --check src/",
"lint": "eslint . --max-warnings 0",
"lint:fix": "eslint . --fix",
"test:prepare": "yarn clear-out && tsc && yarn test:copyassets",
"test": "yarn test:prepare && node ./out/test/runTest.js",
"pretest": "yarn clear-out && tsc && yarn test:copyassets",
"test": "node ./out/test/runTest.js",
"vsce:package": "vsce package",
"onprem:prep": "yarn onprem:prep:package && yarn onprem:prep:readme && yarn onprem:prep:cloudHost",
"onprem:prep:package": "yarn onprem:prep:backuppackage && yarn onprem:prep:includeBinaries && npm pkg set \"name=tabnine-vscode-enterprise\" && yarn onprem:prep:webpack && npm pkg delete __metadata",
"onprem:prep:cloudHost": "cp package.json package.json.back && cat package.json | jq '.contributes.configuration[0].properties += {\"tabnine.cloudHost\": {\"type\": \"string\",\"description\": \"The tabnine cloud host to connect to\"}}' > package.json.onprem && cp package.json.onprem package.json",
"onprem:prep:backuppackage": "cp package.json package.json.original",
"onprem:prep:readme": "#cp README.md README.md.original && echo enterprise > README.md",
"onprem:prep:webpack": "npm pkg set \"scripts.webpack=yarn webpack:OnPrem\"",
"onprem:prep:includeBinaries": "find binaries | grep -i tabnine | xargs -I {} echo !{} >> .vscodeignore && cat .vscodeignore",
"onprem:reset": "yarn onprem:reset:ignore && yarn onprem:reset:package && yarn onprem:reset:readme",
"onprem:reset:package": "cp package.json.original package.json && rm package.json.original",
"onprem:reset:readme": "#cp README.md.original README.md && rm README.md.original",
"onprem:reset:ignore": "cat .vscodeignore | grep -v binaries | tee .vscodeignore",
"vsce:package:enterprise": "MODE=enterprise vsce package",
"vsce:publish": "vsce publish",
"ovsx:publish": "ovsx publish",
"teamcity:test": "tsc && node ./out/test/runTest.js",
"clear-out": "rimraf ./out",
"verify-package-metadata": "node ./verify-package-metadata.js"
},
Expand Down Expand Up @@ -334,6 +321,12 @@
"type": "boolean",
"default": true,
"description": "Use the proxy support for Tabnine (Visual Studio Code must be restarted for this setting to take effect)"
},
"tabnine.cloudHost": {
"type": "string",
"default": null,
"description": "The tabnine cloud host to connect to (restart to take effect)",
"when": "tabnine.enterprise"
}
}
}
Expand Down
22 changes: 2 additions & 20 deletions src/autocompleteInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ import {

import provideCompletionItems from "./provideCompletionItems";
import { COMPLETION_TRIGGERS } from "./globals/consts";
import { ONPREM } from "./onPrem";
import {
isInlineSuggestionProposedApiSupported,
isInlineSuggestionReleasedApiSupported,
} from "./globals/versions";
import { initTracker } from "./inlineSuggestions/documentChangesTracker";
import { initTabOverride } from "./lookAheadSuggestion";
import enableProposed from "./globals/proposedAPI";
import { registerInlineProvider } from "./inlineSuggestions/registerInlineProvider";

let subscriptions: Disposable[] = [];

Expand Down Expand Up @@ -55,20 +53,7 @@ async function reinstallAutocomplete({
(inlineEnabled || snippetsEnabled) &&
(isInlineSuggestionReleasedApiSupported() || (await isDefaultAPIEnabled()))
) {
const provideInlineCompletionItems = (
await import("./provideInlineCompletionItems")
).default;
const inlineCompletionsProvider = {
provideInlineCompletionItems,
};
subscriptions.push(
languages.registerInlineCompletionItemProvider(
{ pattern: "**" },
inlineCompletionsProvider
),
...initTracker()
);
await initTabOverride(subscriptions);
subscriptions.push(await registerInlineProvider());
}

if (autocompleteEnabled) {
Expand Down Expand Up @@ -110,9 +95,6 @@ class InstallOptions {
}

public static get() {
if (ONPREM) {
return new InstallOptions(true, true, false);
}
return new InstallOptions(
isInlineEnabled(),
isSnippetSuggestionsEnabled(),
Expand Down
6 changes: 5 additions & 1 deletion src/binary/Binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ export default class Binary {

private onRestartEventEmitter: EventEmitter<string> = new EventEmitter();

private processRunArgs: string[] = [];

public onRestart(callback: RestartCallback): Disposable {
return this.onRestartEventEmitter.event(callback);
}

public async init(): Promise<void> {
public async init(processRunArgs: string[]): Promise<void> {
this.processRunArgs = processRunArgs;
return this.startChild();
}

Expand Down Expand Up @@ -110,6 +113,7 @@ export default class Binary {

private async startChild() {
const { proc, readLine } = await runBinary([
...this.processRunArgs,
`ide-restart-counter=${this.consecutiveRestarts}`,
]);

Expand Down
3 changes: 0 additions & 3 deletions src/binary/binaryFetcher/binaryValidator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as semver from "semver";
import { ONPREM } from "../../onPrem";
import { asyncExists } from "../../utils/file.utils";
import { runProcess } from "../runProcess";

Expand All @@ -8,8 +7,6 @@ export const BAD_VERSION = "4.0.47";
const TWO_SECONDS_TIMEOUT = 2000;

export default async function isValidBinary(version: string): Promise<boolean> {
if (ONPREM) return true;

if (version === BAD_VERSION || !(await asyncExists(version))) {
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion src/binary/binaryFetcher/bundleDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import {
getUpdateVersionFileUrl,
versionPath,
} from "../paths";
import { EventName, report } from "../../reports/reporter";
import { report } from "../../reports/reporter";
import { setDirectoryFilesAsExecutable } from "../utils";
import EventName from "../../reports/EventName";

type BundlePaths = {
bundlePath: string;
Expand Down
9 changes: 0 additions & 9 deletions src/binary/binaryFetcher/existingVersionHandler.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import { promises as fs } from "fs";
import * as path from "path";
import sortBySemver from "../../utils/semver.utils";
import { asyncFind } from "../../utils/utils";
import isValidBinary from "./binaryValidator";
import { getRootPath, versionPath } from "../paths";
import { setDirectoryFilesAsExecutable } from "../utils";
import { asyncExists } from "../../utils/file.utils";

export default async function handleExistingVersion(): Promise<string | null> {
try {
const versionPaths = await fs.readdir(getRootPath());
await Promise.all(
versionPaths
.map((version) => path.dirname(versionPath(version)))
.filter(async (p) => asyncExists(p))
.map(async (p2) => setDirectoryFilesAsExecutable(p2))
);
const versions = sortBySemver(versionPaths).map(versionPath);
return await asyncFind(versions, isValidBinary);
} catch (e) {
Expand Down
Loading

0 comments on commit b343007

Please sign in to comment.