Improve server version logging info
- Capture commit date and print that next to the branch - Info for being on a dev branch - Info for not being on the latest commit (fetch should've gotten it, if update script was run)
This commit is contained in:
parent
f9e74ea9bf
commit
514c40228c
13
server.js
13
server.js
|
@ -475,7 +475,18 @@ const autorunUrl = new URL(
|
||||||
const setupTasks = async function () {
|
const setupTasks = async function () {
|
||||||
const version = await getVersion();
|
const version = await getVersion();
|
||||||
|
|
||||||
console.log(`SillyTavern ${version.pkgVersion}` + (version.gitBranch ? ` '${version.gitBranch}' (${version.gitRevision})` : ''));
|
// Print formatted header
|
||||||
|
console.log();
|
||||||
|
console.log(`SillyTavern ${version.pkgVersion}`);
|
||||||
|
console.log(version.gitBranch ? `Running '${version.gitBranch}' (${version.gitRevision}) - ${version.commitDate}` : '');
|
||||||
|
if (version.gitBranch && !['staging', 'release'].includes(version.gitBranch)) {
|
||||||
|
console.log('INFO: Currently running a dev branch.');
|
||||||
|
console.log(` If this isn't a dev environment, consider switching via 'git switch staging' or 'git switch release'.`);
|
||||||
|
} else if (version.gitBranch && !version.isLatest) {
|
||||||
|
console.log('INFO: Currently not on the latest commit.');
|
||||||
|
console.log(` Run 'git pull' to upate. If you have any conflicts, run 'git reset --hard' and 'git pull' to reset your branch.`)
|
||||||
|
}
|
||||||
|
console.log();
|
||||||
|
|
||||||
// TODO: do endpoint init functions depend on certain directories existing or not existing? They should be callable
|
// TODO: do endpoint init functions depend on certain directories existing or not existing? They should be callable
|
||||||
// in any order for encapsulation reasons, but right now it's unknown if that would break anything.
|
// in any order for encapsulation reasons, but right now it's unknown if that would break anything.
|
||||||
|
|
18
src/util.js
18
src/util.js
|
@ -73,19 +73,29 @@ function getBasicAuthHeader(auth) {
|
||||||
/**
|
/**
|
||||||
* Returns the version of the running instance. Get the version from the package.json file and the git revision.
|
* Returns the version of the running instance. Get the version from the package.json file and the git revision.
|
||||||
* Also returns the agent string for the Horde API.
|
* Also returns the agent string for the Horde API.
|
||||||
* @returns {Promise<{agent: string, pkgVersion: string, gitRevision: string | null, gitBranch: string | null}>} Version info object
|
* @returns {Promise<{agent: string, pkgVersion: string, gitRevision: string | null, gitBranch: string | null, commitDate: string | null, isLatest: boolean}>} Version info object
|
||||||
*/
|
*/
|
||||||
async function getVersion() {
|
async function getVersion() {
|
||||||
let pkgVersion = 'UNKNOWN';
|
let pkgVersion = 'UNKNOWN';
|
||||||
let gitRevision = null;
|
let gitRevision = null;
|
||||||
let gitBranch = null;
|
let gitBranch = null;
|
||||||
|
let commitDate = null;
|
||||||
|
let isLatest = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const pkgJson = require(path.join(process.cwd(), './package.json'));
|
const pkgJson = require(path.join(process.cwd(), './package.json'));
|
||||||
pkgVersion = pkgJson.version;
|
pkgVersion = pkgJson.version;
|
||||||
if (!process['pkg'] && commandExistsSync('git')) {
|
if (!process['pkg'] && commandExistsSync('git')) {
|
||||||
const git = simpleGit();
|
const git = simpleGit();
|
||||||
gitRevision = await git.cwd(process.cwd()).revparse(['--short', 'HEAD']);
|
const cwd = process.cwd();
|
||||||
gitBranch = await git.cwd(process.cwd()).revparse(['--abbrev-ref', 'HEAD']);
|
gitRevision = await git.cwd(cwd).revparse(['--short', 'HEAD']);
|
||||||
|
gitBranch = await git.cwd(cwd).revparse(['--abbrev-ref', 'HEAD']);
|
||||||
|
commitDate = await git.cwd(cwd).show(['-s', '--format=%ci', gitRevision]);
|
||||||
|
|
||||||
|
// Might fail, but exception is caught. Just don't run anything relevant after in this block...
|
||||||
|
const localLatest = await git.cwd(cwd).revparse(['HEAD']);
|
||||||
|
const remoteLatest = await git.cwd(cwd).revparse([`origin/${gitBranch}`]);
|
||||||
|
isLatest = localLatest === remoteLatest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
|
@ -93,7 +103,7 @@ async function getVersion() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const agent = `SillyTavern:${pkgVersion}:Cohee#1207`;
|
const agent = `SillyTavern:${pkgVersion}:Cohee#1207`;
|
||||||
return { agent, pkgVersion, gitRevision, gitBranch };
|
return { agent, pkgVersion, gitRevision, gitBranch, commitDate: commitDate?.trim() ?? null, isLatest };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue