[Dev] Refactor version update

This commit is contained in:
Alexander Zinchuk 2023-06-02 15:06:29 +02:00
parent 82f42b6e35
commit eb69bd6768
13 changed files with 37 additions and 18 deletions

View File

@ -1,4 +1,3 @@
src/lib/rlottie/rlottie-wasm.js
src/lib/video-preview/libav*
src/lib/video-preview/polyfill/*
@ -19,3 +18,5 @@ src/lib/secret-sauce/
playwright.config.ts
dist/*
deploy/update_version.js

21
deploy/update_version.js Normal file
View File

@ -0,0 +1,21 @@
const path = require('path');
const fs = require('fs');
const ROOT_PATH = `${path.dirname(__filename)}/..`;
const PATCH_VERSION_PATH = `${ROOT_PATH}/.patch-version`;
const PACKAGE_JSON_PATH = `${ROOT_PATH}/package.json`;
const VERSION_TXT_PATH = `${ROOT_PATH}/public/version.txt`;
// This patch value is used to override the one from package.json
const currentPatch = fs.existsSync(PATCH_VERSION_PATH) ? Number(fs.readFileSync(PATCH_VERSION_PATH, 'utf-8')) : -1;
const packageJsonContent = fs.readFileSync(PACKAGE_JSON_PATH, 'utf-8');
const currentVersion = JSON.parse(packageJsonContent).version;
const [major, minor] = currentVersion.split('.');
const newPatch = currentPatch + 1;
const newVersion = [major, minor, newPatch].join('.');
const newPackageJsonContent = packageJsonContent.replace(`"version": "${currentVersion}"`, `"version": "${newVersion}"`);
fs.writeFileSync(PATCH_VERSION_PATH, String(newPatch), 'utf-8');
fs.writeFileSync(PACKAGE_JSON_PATH, newPackageJsonContent, 'utf-8');
fs.writeFileSync(VERSION_TXT_PATH, newVersion, 'utf-8');

View File

@ -4,16 +4,14 @@
"description": "",
"main": "index.js",
"scripts": {
"dev": "cross-env APP_ENV=development APP_VERSION=$(npm run version:print --silent) webpack serve --mode development",
"dev": "cross-env APP_ENV=development webpack serve --mode development",
"dev:mocked": "cross-env APP_ENV=test APP_MOCKED_CLIENT=1 webpack serve --mode development --port 1235",
"build:mocked": "cross-env APP_ENV=test APP_MOCKED_CLIENT=1 webpack --mode development",
"build:staging": "cross-env APP_ENV=staging APP_VERSION=$(npm run version:inc --silent) webpack --mode development && ./deploy/copy_to_dist.sh",
"build:production": "npm i && APP_VERSION=$(npm run version:inc --silent) webpack && ./deploy/copy_to_dist.sh",
"deploy:production": "npm run build:production && git add -A && git commit -a -m '[Build]' --no-verify && git push",
"postversion": "npm run version:update",
"version:print": "echo \"$(node -p -e \"require('./package.json').version.match(/^\\d+\\.\\d+/)[0]\").$(cat .patch-version || echo 0)\"",
"version:update": "npm run version:print --silent > ./public/version.txt",
"version:inc": "echo $((`cat .patch-version || echo -1` + 1)) > .patch-version && npm run version:update && npm run version:print",
"build:staging": "cross-env APP_ENV=staging webpack --mode development && ./deploy/copy_to_dist.sh",
"build:production": "npm i && webpack && ./deploy/copy_to_dist.sh",
"deploy:production": "npm run update_version && npm run build:production && git add -A && git commit -a -m '[Build]' --no-verify && git push",
"postversion": "rm -rf .patch-version && npm run update_version",
"update_version": "node ./deploy/update_version.js",
"telegraph:update_changelog": "node ./dev/telegraphChangelog.js",
"check": "tsc && stylelint \"**/*.{css,scss}\" && eslint . --ext .ts,.tsx,.js --ignore-pattern src/lib/gramjs",
"check:fix": "npm run check -- --fix",

View File

@ -2,6 +2,7 @@ declare const process: NodeJS.Process;
declare module '*.module.scss';
declare const APP_VERSION: string;
declare const APP_REVISION: string;
declare namespace React {

View File

@ -15,7 +15,7 @@ import type {
} from '../../types';
import {
DEBUG, DEBUG_GRAMJS, UPLOAD_WORKERS, IS_TEST, APP_VERSION, SUPPORTED_VIDEO_CONTENT_TYPES, VIDEO_MOV_TYPE,
DEBUG, DEBUG_GRAMJS, UPLOAD_WORKERS, IS_TEST, SUPPORTED_VIDEO_CONTENT_TYPES, VIDEO_MOV_TYPE,
} from '../../../config';
import {
onRequestPhoneNumber, onRequestCode, onRequestPassword, onRequestRegistration,

View File

@ -11,7 +11,7 @@ import { LeftColumnContent, SettingsScreens } from '../../../types';
import {
ANIMATION_LEVEL_MAX,
ANIMATION_LEVEL_MIN,
APP_NAME, APP_VERSION,
APP_NAME,
ARCHIVED_FOLDER_ID,
BETA_CHANGELOG_URL,
DEBUG,

View File

@ -1,7 +1,6 @@
import type { ApiLimitType } from './global/types';
export const APP_NAME = process.env.APP_NAME || 'Telegram Web A';
export const APP_VERSION = process.env.APP_VERSION!;
export const RELEASE_DATETIME = process.env.RELEASE_DATETIME;
export const PRODUCTION_HOSTNAME = 'web.telegram.org';

View File

@ -9,7 +9,6 @@ import type {
import {
ANIMATION_END_DELAY,
APP_VERSION,
RELEASE_DATETIME,
FAST_SMOOTH_MAX_DURATION,
SERVICE_NOTIFICATIONS_USER_ID,

View File

@ -7,7 +7,7 @@ import { MAIN_THREAD_ID } from '../../../api/types';
import type { ActionReturnType, GlobalState } from '../../types';
import {
APP_VERSION, DEBUG, GLOBAL_STATE_CACHE_CUSTOM_EMOJI_LIMIT, INACTIVE_MARKER, PAGE_TITLE, IS_ELECTRON,
DEBUG, GLOBAL_STATE_CACHE_CUSTOM_EMOJI_LIMIT, INACTIVE_MARKER, PAGE_TITLE, IS_ELECTRON,
} from '../../../config';
import getReadableErrorText from '../../../util/getReadableErrorText';
import {

View File

@ -13,7 +13,7 @@ import { IS_MULTITAB_SUPPORTED } from './util/windowEnvironment';
import './global/init';
import {
APP_VERSION, DEBUG, MULTITAB_LOCALSTORAGE_KEY, STRICTERDOM_ENABLED,
DEBUG, MULTITAB_LOCALSTORAGE_KEY, STRICTERDOM_ENABLED,
} from './config';
import { establishMultitabRole, subscribeToMasterChange } from './util/establishMultitabRole';
import { requestGlobal, subscribeToMultitabBroadcastChannel } from './util/multitab';

View File

@ -7,7 +7,7 @@ import type { ApiInitialArgs } from '../api/types';
import type { GlobalState } from '../global/types';
import { IS_MULTITAB_SUPPORTED } from './windowEnvironment';
import { APP_VERSION, DATA_BROADCAST_CHANNEL_NAME, MULTITAB_LOCALSTORAGE_KEY } from '../config';
import { DATA_BROADCAST_CHANNEL_NAME, MULTITAB_LOCALSTORAGE_KEY } from '../config';
import { deepMerge } from './deepMerge';
import { selectTabState } from '../global/selectors';
import {

View File

@ -1,5 +1,5 @@
import {
APP_VERSION, DEBUG, IS_MOCKED_CLIENT, IS_ELECTRON,
DEBUG, IS_MOCKED_CLIENT, IS_ELECTRON,
} from '../config';
import { getGlobal } from '../global';
import { hasStoredSession } from './sessions';

View File

@ -193,7 +193,6 @@ export default function createConfig(
APP_MOCKED_CLIENT,
// eslint-disable-next-line no-null/no-null
APP_NAME: null,
APP_VERSION: appVersion,
IS_ELECTRON: false,
APP_TITLE,
RELEASE_DATETIME: Date.now(),
@ -203,6 +202,7 @@ export default function createConfig(
TEST_SESSION: null,
}),
new DefinePlugin({
APP_VERSION: JSON.stringify(appVersion),
APP_REVISION: DefinePlugin.runtimeValue(() => {
const { branch, commit } = getGitMetadata();
const shouldDisplayCommit = APP_ENV === 'staging' || !branch || branch === 'HEAD';