From 51ae72b5cbf2b1abb47f89b7d5952e148db596ec Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Tue, 30 Jul 2024 12:49:50 +0500 Subject: [PATCH] Front version (#6181) Signed-off-by: Denis Bykhov --- common/scripts/show_tag.js | 31 ++++++++++++++++++++++ desktop-package/package.json | 8 +++--- desktop-package/scripts/publish-version.sh | 2 +- desktop/package.json | 12 ++++----- desktop/src/main/start.ts | 5 ++-- desktop/src/ui/platform.ts | 6 ++++- desktop/src/ui/preload.ts | 3 ++- desktop/src/ui/types.ts | 1 + desktop/webpack.config.js | 3 ++- dev/prod/public/config.json | 5 ++-- dev/prod/src/platform.ts | 7 ++++- packages/presentation/src/plugin.ts | 3 ++- plugins/guest-resources/src/connect.ts | 14 ++++++++-- plugins/workbench-resources/src/connect.ts | 14 ++++++++-- pods/front/package.json | 4 +-- server/front/src/index.ts | 2 ++ server/front/src/starter.ts | 7 +++++ 17 files changed, 101 insertions(+), 26 deletions(-) create mode 100644 common/scripts/show_tag.js diff --git a/common/scripts/show_tag.js b/common/scripts/show_tag.js new file mode 100644 index 0000000000..4d405ce6f2 --- /dev/null +++ b/common/scripts/show_tag.js @@ -0,0 +1,31 @@ +// +// Copyright © 2024 Hardcore Engineering Inc. +// +// Licensed under the Eclipse Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. You may +// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// + +const exec = require('child_process').exec + +exec('git describe --tags --abbrev=0', (err, stdout, stderr) => { + if (err !== null) { + console.log('"0.6.0"') + } + const rawVersion = stdout.trim().replace('v', '').split('.') + if (rawVersion.length === 3) { + const version = { + major: parseInt(rawVersion[0]), + minor: parseInt(rawVersion[1]), + patch: parseInt(rawVersion[2]) + } + console.log(`"${version.major}.${version.minor}.${version.patch}"`) + } +}) diff --git a/desktop-package/package.json b/desktop-package/package.json index 4285b1a0b5..0b7e3cb98d 100644 --- a/desktop-package/package.json +++ b/desktop-package/package.json @@ -7,10 +7,10 @@ "scripts": { "_phase:package": "rushx package", "package": "rushx bump && rm -rf ./dist && cp -r ../desktop/dist . && cp ../desktop/.env ./dist && echo 'done'", - "dist": "cross-env CSC_IDENTITY_AUTO_DISCOVERY=false NODE_ENV=production MODEL_VERSION=$(node ../common/scripts/show_version.js) electron-builder build -p onTag", - "dist-local": "cross-env CSC_IDENTITY_AUTO_DISCOVERY=false NODE_ENV=production MODEL_VERSION=$(node ../common/scripts/show_version.js) electron-builder build", - "dist-signed": "cross-env CSC_IDENTITY_AUTO_DISCOVERY=true NODE_ENV=production MODEL_VERSION=$(node ../common/scripts/show_version.js) electron-builder build -c.afterSign=scripts/notarize.js -p onTag", - "dist-mac-win": "cross-env CSC_IDENTITY_AUTO_DISCOVERY=false NODE_ENV=production MODEL_VERSION=$(node ../common/scripts/show_version.js) electron-builder build --windows --x64", + "dist": "cross-env CSC_IDENTITY_AUTO_DISCOVERY=false NODE_ENV=production VERSION=$(node ../common/scripts/show_tag.js) MODEL_VERSION=$(node ../common/scripts/show_version.js) electron-builder build -p onTag", + "dist-local": "cross-env CSC_IDENTITY_AUTO_DISCOVERY=false NODE_ENV=production VERSION=$(node ../common/scripts/show_tag.js) MODEL_VERSION=$(node ../common/scripts/show_version.js) electron-builder build", + "dist-signed": "cross-env CSC_IDENTITY_AUTO_DISCOVERY=true NODE_ENV=production VERSION=$(node ../common/scripts/show_tag.js) MODEL_VERSION=$(node ../common/scripts/show_version.js) electron-builder build -c.afterSign=scripts/notarize.js -p onTag", + "dist-mac-win": "cross-env CSC_IDENTITY_AUTO_DISCOVERY=false NODE_ENV=production VERSION=$(node ../common/scripts/show_tag.js) MODEL_VERSION=$(node ../common/scripts/show_version.js) electron-builder build --windows --x64", "format": "echo done", "bump": "bump-package-version" }, diff --git a/desktop-package/scripts/publish-version.sh b/desktop-package/scripts/publish-version.sh index 06fabf74b4..3bc113c3a7 100755 --- a/desktop-package/scripts/publish-version.sh +++ b/desktop-package/scripts/publish-version.sh @@ -1,7 +1,7 @@ #!/bin/bash endpoint=https://47fadbaa4ecbea9f3e8b7043a4584e27.r2.cloudflarestorage.com bucket=desktop-distro -rawVersion=$(node common/scripts/show_version.js) +rawVersion=$(node common/scripts/show_tag.js) version=${rawVersion:1:${#rawVersion}-2} cd desktop-package/deploy diff --git a/desktop/package.json b/desktop/package.json index cb1136e7c8..6314c15e04 100644 --- a/desktop/package.json +++ b/desktop/package.json @@ -8,12 +8,12 @@ "build:watch": "tsc", "_phase:package": "rushx package", "_phase:validate": "compile validate", - "package": "rushx bump && cross-env MODEL_VERSION=$(node ../common/scripts/show_version.js) NODE_ENV=production webpack --stats-error-details && echo 'done'", - "webpack": "cross-env MODEL_VERSION=$(node ../common/scripts/show_version.js) NODE_ENV=development webpack --stats-error-details --progress -w", - "devp": "cross-env MODEL_VERSION=$(node ../common/scripts/show_version.js) NODE_ENV=production CLIENT_TYPE=dev webpack --progress -w", - "dev": "cross-env MODEL_VERSION=$(node ../common/scripts/show_version.js) NODE_ENV=development webpack --progress -w", - "start": "cross-env MODEL_VERSION=$(node ../common/scripts/show_version.js) NODE_ENV=production electron .", - "start-dev": "cross-env MODEL_VERSION=$(node ../common/scripts/show_version.js) NODE_ENV=development electron .", + "package": "rushx bump && cross-env MODEL_VERSION=$(node ../common/scripts/show_version.js) VERSION=$(node ../common/scripts/show_tag.js) NODE_ENV=production webpack --stats-error-details && echo 'done'", + "webpack": "cross-env MODEL_VERSION=$(node ../common/scripts/show_version.js) VERSION=$(node ../common/scripts/show_tag.js) NODE_ENV=development webpack --stats-error-details --progress -w", + "devp": "cross-env MODEL_VERSION=$(node ../common/scripts/show_version.js) VERSION=$(node ../common/scripts/show_tag.js) NODE_ENV=production CLIENT_TYPE=dev webpack --progress -w", + "dev": "cross-env MODEL_VERSION=$(node ../common/scripts/show_version.js) VERSION=$(node ../common/scripts/show_tag.js) NODE_ENV=development webpack --progress -w", + "start": "cross-env MODEL_VERSION=$(node ../common/scripts/show_version.js) VERSION=$(node ../common/scripts/show_tag.js) NODE_ENV=production electron .", + "start-dev": "cross-env MODEL_VERSION=$(node ../common/scripts/show_version.js) VERSION=$(node ../common/scripts/show_tag.js) NODE_ENV=development electron .", "format": "format", "bump": "bump-package-version" }, diff --git a/desktop/src/main/start.ts b/desktop/src/main/start.ts index 55d410dade..71b035ebd7 100644 --- a/desktop/src/main/start.ts +++ b/desktop/src/main/start.ts @@ -73,7 +73,7 @@ if (require('electron-squirrel-startup') === true) { app.quit() } -console.log('Running Huly', process.env.MODEL_VERSION, isMac, isDev, process.env.NODE_ENV) +console.log('Running Huly', process.env.MODEL_VERSION, process.env.VERSION, isMac, isDev, process.env.NODE_ENV) function hookOpenWindow (window: BrowserWindow): void { window.webContents.setWindowOpenHandler(({ url }) => { @@ -226,7 +226,8 @@ ipcMain.handle('get-main-config', (event, path) => { CONFIG_URL: process.env.CONFIG_URL ?? '', FRONT_URL, INITIAL_URL: process.env.INITIAL_URL ?? '', - MODEL_VERSION: process.env.MODEL_VERSION ?? '' + MODEL_VERSION: process.env.MODEL_VERSION ?? '', + VERSION: process.env.VERSION ?? '', } return cfg }) diff --git a/desktop/src/ui/platform.ts b/desktop/src/ui/platform.ts index 6b3085f3d9..8006d2a9e9 100644 --- a/desktop/src/ui/platform.ts +++ b/desktop/src/ui/platform.ts @@ -211,7 +211,11 @@ export async function configurePlatform (): Promise { if (config.MODEL_VERSION != null) { console.log('Minimal Model version requirement', config.MODEL_VERSION) - setMetadata(presentation.metadata.RequiredVersion, config.MODEL_VERSION) + setMetadata(presentation.metadata.ModelVersion, config.MODEL_VERSION) + } + if (config.VERSION != null) { + console.log('Minimal version requirement', config.VERSION) + setMetadata(presentation.metadata.FrontVersion, config.VERSION) } setMetadata(telegram.metadata.TelegramURL, config.TELEGRAM_URL ?? 'http://localhost:8086') setMetadata(gmail.metadata.GmailURL, config.GMAIL_URL ?? 'http://localhost:8087') diff --git a/desktop/src/ui/preload.ts b/desktop/src/ui/preload.ts index 357cf71dec..164457e296 100644 --- a/desktop/src/ui/preload.ts +++ b/desktop/src/ui/preload.ts @@ -47,7 +47,8 @@ const expose: IPCMainExposed = { ...mainConfig, INITIAL_URL: openArg ?? '', UPLOAD_URL: concatLink(mainConfig.FRONT_URL, serverConfig.UPLOAD_URL), - MODEL_VERSION: mainConfig.MODEL_VERSION + MODEL_VERSION: mainConfig.MODEL_VERSION, + VERSION: mainConfig.VERSION } ipcRenderer.send('set-combined-config', combinedConfig) diff --git a/desktop/src/ui/types.ts b/desktop/src/ui/types.ts index d87eec0466..36abe5d687 100644 --- a/desktop/src/ui/types.ts +++ b/desktop/src/ui/types.ts @@ -10,6 +10,7 @@ export interface Config { FRONT_URL: string UPLOAD_URL: string MODEL_VERSION?: string + VERSION?: string TELEGRAM_URL: string GMAIL_URL: string CALENDAR_URL: string diff --git a/desktop/webpack.config.js b/desktop/webpack.config.js index 0e33fac985..d1712c5b2b 100644 --- a/desktop/webpack.config.js +++ b/desktop/webpack.config.js @@ -67,7 +67,8 @@ module.exports = [ ...(doValidate ? [new ForkTsCheckerWebpackPlugin()] : []), new Dotenv({ path: prod ? '.env' : '.env-dev' }), new DefinePlugin({ - 'process.env.MODEL_VERSION': JSON.stringify(process.env.MODEL_VERSION) + 'process.env.MODEL_VERSION': JSON.stringify(process.env.MODEL_VERSION), + 'process.env.VERSION': JSON.stringify(process.env.VERSION) }) ], module: { diff --git a/dev/prod/public/config.json b/dev/prod/public/config.json index 1630beba51..97c6971b9b 100644 --- a/dev/prod/public/config.json +++ b/dev/prod/public/config.json @@ -3,7 +3,6 @@ "COLLABORATOR_URL": "ws://localhost:3078", "COLLABORATOR_API_URL": "http://localhost:3078", "UPLOAD_URL":"/files", - "MODEL_VERSION": null, "TELEGRAM_URL": "http://localhost:8086", "GMAIL_URL": "http://localhost:8088", "CALENDAR_URL": "http://localhost:8095", @@ -15,5 +14,7 @@ "PRINT_URL": "http://localhost:4005", "SIGN_URL": "http://localhost:4006", "ANALYTICS_COLLECTOR_URL": "http://localhost:4077", - "BRANDING_URL": "/branding.json" + "BRANDING_URL": "/branding.json", + "VERSION": "0.6.266", + "MODEL_VERSION": "0.6.266" } \ No newline at end of file diff --git a/dev/prod/src/platform.ts b/dev/prod/src/platform.ts index d1fef250a0..f6f301c85f 100644 --- a/dev/prod/src/platform.ts +++ b/dev/prod/src/platform.ts @@ -120,6 +120,7 @@ export interface Config { ACCOUNTS_URL: string UPLOAD_URL: string MODEL_VERSION: string + VERSION: string COLLABORATOR_URL: string COLLABORATOR_API_URL: string REKONI_URL: string @@ -291,7 +292,11 @@ export async function configurePlatform() { if (config.MODEL_VERSION != null) { console.log('Minimal Model version requirement', config.MODEL_VERSION) - setMetadata(presentation.metadata.RequiredVersion, config.MODEL_VERSION) + setMetadata(presentation.metadata.ModelVersion, config.MODEL_VERSION) + } + if (config.VERSION != null) { + console.log('Minimal version requirement', config.VERSION) + setMetadata(presentation.metadata.FrontVersion, config.VERSION) } setMetadata(telegram.metadata.TelegramURL, config.TELEGRAM_URL ?? 'http://localhost:8086') setMetadata(gmail.metadata.GmailURL, config.GMAIL_URL ?? 'http://localhost:8087') diff --git a/packages/presentation/src/plugin.ts b/packages/presentation/src/plugin.ts index d081075e85..05efb3e116 100644 --- a/packages/presentation/src/plugin.ts +++ b/packages/presentation/src/plugin.ts @@ -126,7 +126,8 @@ export default plugin(presentationId, { FilePreviewExtension: '' as ComponentExtensionId }, metadata: { - RequiredVersion: '' as Metadata, + ModelVersion: '' as Metadata, + FrontVersion: '' as Metadata, Draft: '' as Metadata>, UploadURL: '' as Metadata, CollaboratorUrl: '' as Metadata, diff --git a/plugins/guest-resources/src/connect.ts b/plugins/guest-resources/src/connect.ts index 181d387362..c9ef545952 100644 --- a/plugins/guest-resources/src/connect.ts +++ b/plugins/guest-resources/src/connect.ts @@ -2,6 +2,7 @@ import { Analytics } from '@hcengineering/analytics' import client from '@hcengineering/client' import core, { ClientConnectEvent, + concatLink, setCurrentAccount, versionToString, type AccountClient, @@ -105,6 +106,15 @@ export async function connect (title: string): Promise { } versionError.set(`${currentVersionStr} => ${reconnectVersionStr}`) } + + const frontUrl = getMetadata(presentation.metadata.FrontUrl) ?? '' + const currentFrontVersion = getMetadata(presentation.metadata.FrontVersion) + if (currentFrontVersion !== undefined) { + const frontConfig = await (await fetch(concatLink(frontUrl, '/config.json'))).json() + if (frontConfig?.version !== undefined && frontConfig.version !== currentFrontVersion) { + location.reload() + } + } } })() } catch (err) { @@ -127,7 +137,7 @@ export async function connect (title: string): Promise { version = await _client.findOne(core.class.Version, {}) console.log('Model version', version) - const requiredVersion = getMetadata(presentation.metadata.RequiredVersion) + const requiredVersion = getMetadata(presentation.metadata.ModelVersion) if (requiredVersion !== undefined && version !== undefined) { console.log('checking min model version', requiredVersion) const versionStr = versionToString(version) @@ -140,7 +150,7 @@ export async function connect (title: string): Promise { } catch (err: any) { Analytics.handleError(err) console.error(err) - const requirdVersion = getMetadata(presentation.metadata.RequiredVersion) + const requirdVersion = getMetadata(presentation.metadata.ModelVersion) console.log('checking min model version', requirdVersion) if (requirdVersion !== undefined) { versionError.set(`'unknown' => ${requirdVersion}`) diff --git a/plugins/workbench-resources/src/connect.ts b/plugins/workbench-resources/src/connect.ts index 391567ab1c..62faafa29a 100644 --- a/plugins/workbench-resources/src/connect.ts +++ b/plugins/workbench-resources/src/connect.ts @@ -2,6 +2,7 @@ import { Analytics } from '@hcengineering/analytics' import client from '@hcengineering/client' import core, { ClientConnectEvent, + concatLink, getCurrentAccount, MeasureMetricsContext, metricsToString, @@ -211,6 +212,15 @@ export async function connect (title: string): Promise { } versionError.set(`${currentVersionStr} != ${reconnectVersionStr}`) } + + const frontUrl = getMetadata(presentation.metadata.FrontUrl) ?? '' + const currentFrontVersion = getMetadata(presentation.metadata.FrontVersion) + if (currentFrontVersion !== undefined) { + const frontConfig = await (await fetch(concatLink(frontUrl, '/config.json'))).json() + if (frontConfig?.version !== undefined && frontConfig.version !== currentFrontVersion) { + location.reload() + } + } } })() } catch (err) { @@ -265,7 +275,7 @@ export async function connect (title: string): Promise { ) console.log('Model version', version) - const requiredVersion = getMetadata(presentation.metadata.RequiredVersion) + const requiredVersion = getMetadata(presentation.metadata.ModelVersion) if (requiredVersion !== undefined && version !== undefined && requiredVersion !== '') { console.log('checking min model version', requiredVersion) const versionStr = versionToString(version) @@ -278,7 +288,7 @@ export async function connect (title: string): Promise { } catch (err: any) { console.error(err) Analytics.handleError(err) - const requiredVersion = getMetadata(presentation.metadata.RequiredVersion) + const requiredVersion = getMetadata(presentation.metadata.ModelVersion) console.log('checking min model version', requiredVersion) if (requiredVersion !== undefined) { versionError.set(`'unknown' => ${requiredVersion}`) diff --git a/pods/front/package.json b/pods/front/package.json index b4fff43f88..6f5050d442 100644 --- a/pods/front/package.json +++ b/pods/front/package.json @@ -14,14 +14,14 @@ "_phase:package": "rushx package", "_phase:docker-build": "rushx docker:build", "_phase:docker-staging": "rushx docker:staging", - "bundle": "mkdir -p bundle && esbuild src/__start.ts --keep-names --define:process.env.MODEL_VERSION=$(node ../../common/scripts/show_version.js) --bundle --minify --platform=node --external:sharp --outfile=bundle/bundle.js --log-level=error --sourcemap=external", + "bundle": "mkdir -p bundle && esbuild src/__start.ts --keep-names --define:process.env.MODEL_VERSION=$(node ../../common/scripts/show_version.js) --define:process.env.VERSION=$(node ../../common/scripts/show_tag.js) --bundle --minify --platform=node --external:sharp --outfile=bundle/bundle.js --log-level=error --sourcemap=external", "package": "rm -rf ./dist && cp -r ../../dev/prod/dist . && cp -r ../../dev/prod/public/* ./dist/ && rm ./dist/config.json", "docker:build": "../../common/scripts/docker_build.sh hardcoreeng/front", "docker:staging": "../../common/scripts/docker_tag.sh hardcoreeng/front staging", "docker:push": "../../common/scripts/docker_tag.sh hardcoreeng/front", "docker:tbuild": "docker build -t hardcoreeng/front . --platform=linux/amd64 && ../../common/scripts/docker_tag_push.sh hardcoreeng/front", "format": "format src", - "run-local": "cross-env MINIO_ACCESS_KEY=minioadmin MINIO_SECRET_KEY=minioadmin MINIO_ENDPOINT=localhost SERVER_SECRET='secret' ACCOUNTS_URL=http://localhost:3000 UPLOAD_URL=/files ELASTIC_URL=http://localhost:9200 MODEL_VERSION=$(node ../../common/scripts/show_version.js) PUBLIC_DIR='.' ts-node ./src/__start.ts", + "run-local": "cross-env MINIO_ACCESS_KEY=minioadmin MINIO_SECRET_KEY=minioadmin MINIO_ENDPOINT=localhost SERVER_SECRET='secret' ACCOUNTS_URL=http://localhost:3000 UPLOAD_URL=/files ELASTIC_URL=http://localhost:9200 MODEL_VERSION=$(node ../../common/scripts/show_version.js) VERSION=$(node ../../common/scripts/show_tag.js) PUBLIC_DIR='.' ts-node ./src/__start.ts", "test": "jest --passWithNoTests --silent --forceExit", "_phase:build": "compile transpile src", "_phase:test": "jest --passWithNoTests --silent --forceExit", diff --git a/server/front/src/index.ts b/server/front/src/index.ts index 50c41d0cd2..d59b3aec39 100644 --- a/server/front/src/index.ts +++ b/server/front/src/index.ts @@ -241,6 +241,7 @@ export function start ( accountsUrl: string uploadUrl: string modelVersion: string + version: string rekoniUrl: string telegramUrl: string gmailUrl: string @@ -290,6 +291,7 @@ export function start ( ACCOUNTS_URL: config.accountsUrl, UPLOAD_URL: config.uploadUrl, MODEL_VERSION: config.modelVersion, + VERSION: config.version, REKONI_URL: config.rekoniUrl, TELEGRAM_URL: config.telegramUrl, GMAIL_URL: config.gmailUrl, diff --git a/server/front/src/starter.ts b/server/front/src/starter.ts index dde158120c..6ba2d4ae47 100644 --- a/server/front/src/starter.ts +++ b/server/front/src/starter.ts @@ -93,6 +93,12 @@ export function startFront (ctx: MeasureContext, extraConfig?: Record