diff --git a/.eslintrc b/.eslintrc index 59ae678cd..0d29da98e 100644 --- a/.eslintrc +++ b/.eslintrc @@ -71,5 +71,8 @@ }, "parserOptions": { "project": "./tsconfig.json" + }, + "globals": { + "APP_REVISION": "readonly" } } diff --git a/src/@types/global.d.ts b/src/@types/global.d.ts index aa31011fa..a2dc0d5c3 100644 --- a/src/@types/global.d.ts +++ b/src/@types/global.d.ts @@ -1,5 +1,7 @@ declare const process: NodeJS.Process; +declare var APP_REVISION: string; + declare namespace React { interface HTMLAttributes { // Optimization for DOM nodes prepends and inserts diff --git a/src/components/left/main/LeftMainHeader.tsx b/src/components/left/main/LeftMainHeader.tsx index 6e39bce89..89e677422 100644 --- a/src/components/left/main/LeftMainHeader.tsx +++ b/src/components/left/main/LeftMainHeader.tsx @@ -8,7 +8,7 @@ import { ApiChat } from '../../../api/types'; import { GlobalState } from '../../../global/types'; import { - ANIMATION_LEVEL_MAX, APP_NAME, APP_REVISION, APP_VERSION, DEBUG, FEEDBACK_URL, + ANIMATION_LEVEL_MAX, APP_NAME, APP_VERSION, DEBUG, FEEDBACK_URL, } from '../../../config'; import { IS_SINGLE_COLUMN_LAYOUT } from '../../../util/environment'; import buildClassName from '../../../util/buildClassName'; diff --git a/src/config.ts b/src/config.ts index 4a08b78c9..081c5dd29 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,6 +1,5 @@ export const APP_NAME = process.env.APP_NAME || 'Telegram WebZ'; export const APP_VERSION = process.env.APP_VERSION!; -export const APP_REVISION = process.env.APP_REVISION; export const DEBUG = ( process.env.APP_ENV !== 'production' && process.env.APP_ENV !== 'perf' && process.env.APP_ENV !== 'test' diff --git a/webpack.config.js b/webpack.config.js index c46caf187..3abe7758e 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -2,6 +2,7 @@ const path = require('path'); const dotenv = require('dotenv'); const { + DefinePlugin, EnvironmentPlugin, ProvidePlugin, } = require('webpack'); @@ -128,6 +129,12 @@ module.exports = (env = {}, argv = {}) => { TELEGRAM_T_API_HASH: undefined, TEST_SESSION: null, }), + new DefinePlugin({ + APP_REVISION: DefinePlugin.runtimeValue(() => { + const { branch, commit } = getGitMetadata(); + return JSON.stringify((!branch || branch === 'HEAD') ? commit : branch); + }, argv.mode === 'development' ? true : []), + }), new ProvidePlugin({ Buffer: ['buffer', 'Buffer'], }), @@ -153,3 +160,10 @@ module.exports = (env = {}, argv = {}) => { }), }; }; + +function getGitMetadata() { + const gitRevisionPlugin = new GitRevisionPlugin(); + const branch = process.env.HEAD || gitRevisionPlugin.branch(); + const commit = gitRevisionPlugin.commithash().substring(0, 7); + return { branch, commit }; +}