Skip to content
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

fix: refactor way we get COMPOSER_VERSION #7326

Merged
merged 4 commits into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
12 changes: 10 additions & 2 deletions Composer/packages/client/config/env.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const fs = require('fs');
const fs = require('fs-extra');
const path = require('path');
const { execSync } = require('child_process');

Expand Down Expand Up @@ -49,6 +49,14 @@ function getGitSha() {
}
}

function getComposerVersion() {
try {
return fs.readJSONSync(path.join(__dirname, '../../electron-server/package.json')).version;
Copy link
Contributor

Choose a reason for hiding this comment

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

same question

} catch {
return 'unknown';
}
}

// We support resolving modules according to `NODE_PATH`.
// This lets you use absolute paths in imports inside large monorepos:
// https://github.com/facebook/create-react-app/issues/253.
Expand Down Expand Up @@ -88,7 +96,7 @@ function getClientEnvironment(publicUrl) {
PUBLIC_URL: publicUrl,
GIT_SHA: getGitSha().toString().replace('\n', ''),
SDK_PACKAGE_VERSION: '4.12.2', // TODO: change this when Composer supports custom schema/custom runtime
COMPOSER_VERSION: '1.4.0',
COMPOSER_VERSION: getComposerVersion(),
LOCAL_PUBLISH_PATH:
process.env.LOCAL_PUBLISH_PATH || path.resolve(process.cwd(), '../../../extensions/localPublish/hostedBots'),
WEBLOGIN_CLIENTID: process.env.WEBLOGIN_CLIENTID,
Expand Down
2 changes: 1 addition & 1 deletion Composer/packages/client/src/pages/about/About.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const About: React.FC<RouteComponentProps> = () => {
<div css={about.version}>
{formatMessage(`Release: `) +
(isElectron()
? (window as any).appVersion
? process.env.COMPOSER_VERSION
: `${process.env.COMPOSER_VERSION}-${process.env.GIT_SHA}` || 'Unknown')}
</div>
<div css={about.diagnosticsInfo}>
Expand Down
1 change: 1 addition & 0 deletions Composer/packages/electron-server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ function initializeAppUpdater(settings: AppUpdaterSettings) {
}

async function loadServer() {
process.env.COMPOSER_VERSION = app.getVersion();
if (!isDevelopment) {
// only change paths if packaged electron app
const unpackedDir = getUnpackedAsarPath();
Expand Down
4 changes: 1 addition & 3 deletions Composer/packages/electron-server/src/preload.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

const { app, ipcRenderer } = require('electron'); // eslint-disable-line
const { ipcRenderer } = require('electron'); // eslint-disable-line

// expose ipcRenderer to the browser
window.ipcRenderer = ipcRenderer;
// get the app version to hand into the client
window.appVersion = app.getVersion();
// flag to distinguish electron client from web app client
window.__IS_ELECTRON__ = true;
2 changes: 0 additions & 2 deletions Composer/packages/server/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,3 @@ export enum ClaimNames {
export const APPINSIGHTS_INSTRUMENTATIONKEY = process.env.APPINSIGHTS_INSTRUMENTATIONKEY;

export const piiProperties = [];

export const COMPOSER_VERSION = '1.4.0';
3 changes: 1 addition & 2 deletions Composer/packages/server/src/models/bot/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { IFileStorage } from '../storage/interface';
import log from '../../logger';
import { setEnvDefault } from '../../utility/setEnvDefault';
import { useElectronContext } from '../../utility/electronContext';
import { COMPOSER_VERSION } from '../../constants';
import { TelemetryService } from '../../services/telemetry';

import { IOrchestratorNLRList, IOrchestratorProgress, IOrchestratorSettings } from './interface';
Expand Down Expand Up @@ -52,7 +51,7 @@ export type DownSamplingConfig = {

const getUserAgent = () => {
const platform = useElectronContext() ? 'desktop' : 'web';
return `microsoft.bot.composer/${COMPOSER_VERSION} ${platform}`;
return `microsoft.bot.composer/${process.env.COMPOSER_VERSION} ${platform}`;
};

export class Builder {
Expand Down
2 changes: 2 additions & 0 deletions Composer/packages/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ import { mountConversationsRoutes } from './directline/mountConversationRoutes';
import { mountDirectLineRoutes } from './directline/mountDirectlineRoutes';
import { mountAttachmentRoutes } from './directline/mountAttachmentRoutes';
import { cleanHostedBots } from './utility/cleanHostedBots';
import { getVersion } from './utility/getVersion';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const session = require('express-session');

export async function start(electronContext?: ElectronContext): Promise<number | string> {
setEnvDefault('COMPOSER_VERSION', getVersion());
if (electronContext) {
setElectronContext(electronContext);
}
Expand Down
17 changes: 17 additions & 0 deletions Composer/packages/server/src/utility/getVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import path from 'path';

import fs from 'fs-extra';

const isProduction = process.env.NODE_ENV === 'production';

export function getVersion(): string {
try {
const version = fs.readJSONSync(path.join(__dirname, '../../../electron-server/package.json')).version;
Copy link
Contributor

Choose a reason for hiding this comment

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

does this file exist in packed electron?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, but the env variable gets set in the electron start up sequence. So in that case, this will just error and return unknown.

Right now, there is not a lazy evaluation for getting default values using the setEnvDefault function.

return isProduction ? version : `${version}-DEV`;
} catch {
return 'unknown';
}
}