Skip to content

Commit

Permalink
ci: update dependency versions~
Browse files Browse the repository at this point in the history
  • Loading branch information
yowpark committed Dec 15, 2023
1 parent a3957aa commit 59b559a
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 34 deletions.
61 changes: 61 additions & 0 deletions utils/typescript/version/scripts/change-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import path from 'path';
import fs from 'fs';

export function changePackageJsonMainVersion(path: string, version: string): void {
const contents = fs.readFileSync(path, 'utf-8');

const regex = /"version": "(\d+\.\d+\.\d+)",/;
const match = contents.match(regex);
if (!match) {
throw new Error(`Could not find version in ${path}`);
}
const oldVersion = match[1];
const newContents = contents.replace(oldVersion, version);
fs.writeFileSync(path, newContents);
console.log(`Updated ${path} version`);
}

export function changePyProjectTomlVersion(path: string, version: string): void {
const contents = fs.readFileSync(path, 'utf-8');

const regex = /version = "(\d+\.\d+\.\d+)"/;
const match = contents.match(regex);
if (!match) {
throw new Error(`Could not find version in ${path}`);
}
const oldVersion = match[1];
const newContents = contents.replace(oldVersion, version);
fs.writeFileSync(path, newContents);
console.log(`Updated ${path} version`);
}

export function changePythonRequirementsVersion(path: string, key: string, version: string): void {
const contents = fs.readFileSync(path, 'utf-8');

const regex = new RegExp(`${key}==\\d+\\.\\d+\\.\\d+`);
const match = contents.match(regex);

if (!match) {
throw new Error(`Could not find ${key} in ${path}`);
}

const oldVersion = match[0];
const newContents = contents.replace(oldVersion, `${key}==${version}`);
fs.writeFileSync(path, newContents);
console.log(`Updated ${path} version`);
}

export function changePackageJsonDependenciesVersion(path: string, key: string, version: string): void {
const contents = fs.readFileSync(path, 'utf-8');

const regex = new RegExp(`"${key}": "\\d+\\.\\d+\\.\\d+"`);
const match = contents.match(regex);
if (!match) {
throw new Error(`Could not find ${key} in ${path}`);
}

const oldVersion = match[0];
const newContents = contents.replace(oldVersion, `"${key}": "${version}"`);
fs.writeFileSync(path, newContents);
console.log(`Updated ${path} version`);
}
68 changes: 34 additions & 34 deletions utils/typescript/version/scripts/version.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { program } from 'commander';
import path from 'path';
import fs from 'fs';
import {
changePackageJsonDependenciesVersion,
changePackageJsonMainVersion,
changePyProjectTomlVersion,
changePythonRequirementsVersion,
} from './change-version';

const INVALID_PATH = 'INVALID_PATH';

const ROOT_PATH = path.resolve(__dirname, '..', '..', '..', '..');
const UNITY_SERVER_VERSION_FILE_PATH = path.resolve(ROOT_PATH, 'engine/unity/Runtime/Private/Network/Server.cs');
Expand All @@ -9,6 +17,14 @@ const UNITY_SERVER_DOCS_GITREF_VERSION_FILE_PATH = path.resolve(ROOT_PATH, 'docs
const PYTHON_CLIENT_VERSION_FILE_PATH = path.resolve(ROOT_PATH, 'client/python/gamium/pyproject.toml');
const TYPESCRIPT_CLIENT_VERSION_FILE_PATH = path.resolve(ROOT_PATH, 'client/typescript/gamium/package.json');

const GAMIUM_UNITY_SAMPLES_PATH = process.env.GAMIUM_UNITY_SAMPLES_PATH ?? INVALID_PATH;
const GAMIUM_UNITY_SAMPLES_PYTHON_REQUIREMENTS_PATH = path.resolve(GAMIUM_UNITY_SAMPLES_PATH, 'client/python/requirements.txt');
const GAMIUM_UNITY_SAMPLES_TYPESCRIPT_PACKAGEJSON_PATH = path.resolve(GAMIUM_UNITY_SAMPLES_PATH, 'client/typescript/package.json');

const DOGU_ROUTINE_EXAMPLES_PATH = process.env.DOGU_ROUTINE_EXAMPLES_PATH ?? INVALID_PATH;
const DOGU_ROUTINE_EXAMPLES_PYTHON_REQUIREMENTS_PATH = path.resolve(DOGU_ROUTINE_EXAMPLES_PATH, 'gamium/python/pytest/requirements.txt');
const DOGU_ROUTINE_EXAMPLES_TYPESCRIPT_PACKAGEJSON_PATH = path.resolve(DOGU_ROUTINE_EXAMPLES_PATH, 'gamium/typescript/jest/package.json');

function changeUnityServerVersion(version: string) {
const contents = fs.readFileSync(UNITY_SERVER_VERSION_FILE_PATH, 'utf-8');

Expand All @@ -24,17 +40,7 @@ function changeUnityServerVersion(version: string) {
}

function changeUnityServerPackageVersion(version: string) {
const contents = fs.readFileSync(UNITY_SERVER_PACKAGE_VERSION_FILE_PATH, 'utf-8');

const regex = /"version": "(\d+\.\d+\.\d+)",/;
const match = contents.match(regex);
if (!match) {
throw new Error('Could not find version in Unity Server Package');
}
const oldVersion = match[1];
const newContents = contents.replace(oldVersion, version);
fs.writeFileSync(UNITY_SERVER_PACKAGE_VERSION_FILE_PATH, newContents);
console.log('Updated Unity Server Package version');
changePackageJsonMainVersion(UNITY_SERVER_PACKAGE_VERSION_FILE_PATH, version);
}

function changeUnityServerDocsPackageVersion(version: string) {
Expand All @@ -53,31 +59,11 @@ function changeUnityServerDocsPackageVersion(version: string) {
}

function changePythonClientVersion(version: string) {
const contents = fs.readFileSync(PYTHON_CLIENT_VERSION_FILE_PATH, 'utf-8');

const regex = /version = "(\d+\.\d+\.\d+)"/;
const match = contents.match(regex);
if (!match) {
throw new Error('Could not find version in Python Client');
}
const oldVersion = match[1];
const newContents = contents.replace(oldVersion, version);
fs.writeFileSync(PYTHON_CLIENT_VERSION_FILE_PATH, newContents);
console.log('Updated Python Client version');
changePyProjectTomlVersion(PYTHON_CLIENT_VERSION_FILE_PATH, version);
}

function changeTypescriptClientVersion(version: string) {
const contents = fs.readFileSync(TYPESCRIPT_CLIENT_VERSION_FILE_PATH, 'utf-8');

const regex = /"version": "(\d+\.\d+\.\d+)",/;
const match = contents.match(regex);
if (!match) {
throw new Error('Could not find version in Typescript Client');
}
const oldVersion = match[1];
const newContents = contents.replace(oldVersion, version);
fs.writeFileSync(TYPESCRIPT_CLIENT_VERSION_FILE_PATH, newContents);
console.log('Updated Typescript Client version');
changePackageJsonMainVersion(TYPESCRIPT_CLIENT_VERSION_FILE_PATH, version);
}

program.name('version');
Expand All @@ -86,12 +72,26 @@ program
.command('upgrade')
.argument('<version>', 'version to upgrade to')
.action((version) => {
console.log(`Upgrading to ${version}`);
console.log(`>> Upgrading to ${version} << `);
changeUnityServerVersion(version);
changeUnityServerPackageVersion(version);
changeUnityServerDocsPackageVersion(version);
changePythonClientVersion(version);
changeTypescriptClientVersion(version);

if (INVALID_PATH === GAMIUM_UNITY_SAMPLES_PATH) {
console.warn('[WARNING] GAMIUM_UNITY_SAMPLES_PATH is not set, skipping, please set it to upgrade the samples');
} else {
changePythonRequirementsVersion(GAMIUM_UNITY_SAMPLES_PYTHON_REQUIREMENTS_PATH, 'gamium', version);
changePackageJsonDependenciesVersion(GAMIUM_UNITY_SAMPLES_TYPESCRIPT_PACKAGEJSON_PATH, 'gamium', version);
}

if (INVALID_PATH === DOGU_ROUTINE_EXAMPLES_PATH) {
console.warn('[WARNING] DOGU_ROUTINE_EXAMPLES_PATH is not set, skipping, please set it to upgrade the examples');
} else {
changePythonRequirementsVersion(DOGU_ROUTINE_EXAMPLES_PYTHON_REQUIREMENTS_PATH, 'gamium', version);
changePackageJsonDependenciesVersion(DOGU_ROUTINE_EXAMPLES_TYPESCRIPT_PACKAGEJSON_PATH, 'gamium', version);
}
});

program.parse();

0 comments on commit 59b559a

Please sign in to comment.