0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-12 22:10:44 -05:00

Bake build data directly into the executable (!297)

This is primarily to stop confusion when a user overwrites their `aki_data` folder with an old version, the data shown in logs/server console is now based on compile time data instead of runtime data.

- New build.json file added to the `obj/ide/` folder that gets populated with the build data on build
- Moved asset copying prior to packaging, so that `obj/ide/build.json` is available at package time
- Updated all references of core.commit, and core.buildTime to use globalThis
- Updated all references of core.akiVersion to use globalThis with a fallback if not found (When running in VSCode for example)

Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com>
Reviewed-on: SPT-AKI/Server#297
Co-authored-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
Co-committed-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
This commit is contained in:
DrakiaXYZ 2024-04-18 07:54:16 +00:00 committed by chomp
parent 688e2b77cd
commit 820a5caccb
12 changed files with 67 additions and 28 deletions

View File

@ -155,27 +155,32 @@ const downloadPnpm = async () =>
const copyLicense = () => gulp.src([licenseFile]).pipe(rename("LICENSE-Server.txt")).pipe(gulp.dest(buildDir));
/**
* Writes the latest Git commit hash to the core.json configuration file.
* Writes the latest build data to the core.json and build.json configuration files.
*/
const writeCommitHashToCoreJSON = async () =>
const writeBuildDataToJSON = async () =>
{
try
{
const coreJSONPath = path.resolve(dataDir, "configs", "core.json");
const coreJSON = await fs.readFile(coreJSONPath, "utf8");
const parsed = JSON.parse(coreJSON);
// Fetch the latest Git commit hash
const gitResult = await exec("git rev-parse HEAD", { stdout: "pipe" });
// Update the commit hash in the core.json object
parsed.commit = gitResult.stdout.trim() || "";
// Update core.json
const coreJSONPath = path.resolve(dataDir, "configs", "core.json");
const coreJSON = await fs.readFile(coreJSONPath, "utf8");
const coreParsed = JSON.parse(coreJSON);
// Add build timestamp
parsed.buildTime = new Date().getTime();
coreParsed.commit = gitResult.stdout.trim() || "";
coreParsed.buildTime = new Date().getTime();
await fs.writeFile(coreJSONPath, JSON.stringify(coreParsed, null, 4));
// Write the updated object back to core.json
await fs.writeFile(coreJSONPath, JSON.stringify(parsed, null, 4));
// Write build.json
const buildJsonPath = path.join("obj", "ide", "build.json");
const buildInfo = {};
buildInfo.commit = coreParsed.commit;
buildInfo.buildTime = coreParsed.buildTime;
buildInfo.akiVersion = coreParsed.akiVersion;
await fs.writeFile(buildJsonPath, JSON.stringify(buildInfo, null, 4));
}
catch (error)
{
@ -195,7 +200,7 @@ const createHashFile = async () =>
};
// Combine all tasks into addAssets
const addAssets = gulp.series(copyAssets, downloadPnpm, copyLicense, writeCommitHashToCoreJSON, createHashFile);
const addAssets = gulp.series(copyAssets, downloadPnpm, copyLicense, writeBuildDataToJSON, createHashFile);
/**
* Cleans the build directory.
@ -313,9 +318,9 @@ const build = (packagingType) =>
cleanBuild,
validateJSONs,
compile,
addAssets,
fetchPackageImage,
anonPackaging,
addAssets,
updateBuildProperties,
cleanCompiled,
];

View File

@ -964,7 +964,9 @@ export class GameController
protected logProfileDetails(fullProfile: IAkiProfile): void
{
this.logger.debug(`Profile made with: ${fullProfile.aki.version}`);
this.logger.debug(`Server version: ${this.coreConfig.akiVersion} ${this.coreConfig.commit}`);
this.logger.debug(
`Server version: ${globalThis.G_AKIVERSION || this.coreConfig.akiVersion} ${globalThis.G_COMMIT}`,
);
this.logger.debug(`Debug enabled: ${globalThis.G_DEBUG_CONFIGURATION}`);
this.logger.debug(`Mods enabled: ${globalThis.G_MODS_ENABLED}`);
}

View File

@ -2,6 +2,7 @@ import "reflect-metadata";
import "source-map-support/register";
import { Program } from "@spt-aki/Program";
import * as buildInfo from "./build.json";
globalThis.G_DEBUG_CONFIGURATION = true;
globalThis.G_RELEASE_CONFIGURATION = true;
@ -10,5 +11,9 @@ globalThis.G_MODS_TRANSPILE_TS = true;
globalThis.G_LOG_REQUESTS = true;
globalThis.G_WATERMARK_ENABLED = true;
globalThis.G_AKIVERSION = buildInfo.akiVersion;
globalThis.G_COMMIT = buildInfo.commit;
globalThis.G_BUILDTIME = buildInfo.buildTime;
const program = new Program();
program.start();

View File

@ -2,6 +2,7 @@ import "reflect-metadata";
import "source-map-support/register";
import { Program } from "@spt-aki/Program";
import * as buildInfo from "./build.json";
globalThis.G_DEBUG_CONFIGURATION = true;
globalThis.G_RELEASE_CONFIGURATION = true;
@ -10,5 +11,9 @@ globalThis.G_MODS_TRANSPILE_TS = true;
globalThis.G_LOG_REQUESTS = true;
globalThis.G_WATERMARK_ENABLED = true;
globalThis.G_AKIVERSION = buildInfo.akiVersion;
globalThis.G_COMMIT = buildInfo.commit;
globalThis.G_BUILDTIME = buildInfo.buildTime;
const program = new Program();
program.start();

View File

@ -2,6 +2,7 @@ import "reflect-metadata";
import "source-map-support/register";
import { Program } from "@spt-aki/Program";
import * as buildInfo from "./build.json";
globalThis.G_DEBUG_CONFIGURATION = true;
globalThis.G_RELEASE_CONFIGURATION = true;
@ -10,5 +11,9 @@ globalThis.G_MODS_TRANSPILE_TS = true;
globalThis.G_LOG_REQUESTS = true;
globalThis.G_WATERMARK_ENABLED = false;
globalThis.G_AKIVERSION = buildInfo.akiVersion;
globalThis.G_COMMIT = buildInfo.commit;
globalThis.G_BUILDTIME = buildInfo.buildTime;
const program = new Program();
program.start();

View File

@ -2,6 +2,7 @@ import "reflect-metadata";
import "source-map-support/register";
import { Program } from "@spt-aki/Program";
import * as buildInfo from "./build.json";
globalThis.G_DEBUG_CONFIGURATION = false;
globalThis.G_RELEASE_CONFIGURATION = true;
@ -10,5 +11,9 @@ globalThis.G_MODS_TRANSPILE_TS = true;
globalThis.G_LOG_REQUESTS = false;
globalThis.G_WATERMARK_ENABLED = false;
globalThis.G_AKIVERSION = buildInfo.akiVersion;
globalThis.G_COMMIT = buildInfo.commit;
globalThis.G_BUILDTIME = buildInfo.buildTime;
const program = new Program();
program.start();

View File

@ -2,13 +2,18 @@ import "reflect-metadata";
import "source-map-support/register";
import { Program } from "@spt-aki/Program";
import * as buildInfo from "./build.json";
globalThis.G_DEBUG_CONFIGURATION = true;
globalThis.G_RELEASE_CONFIGURATION = false;
globalThis.G_MODS_ENABLED = true;
globalThis.G_MODS_TRANSPILE_TS = false;
globalThis.G_LOG_REQUESTS = true;
globalThis.G_WATERMARK_ENABLED = true;
globalThis.G_WATERMARK_ENABLED = false;
globalThis.G_AKIVERSION = buildInfo.akiVersion;
globalThis.G_COMMIT = buildInfo.commit;
globalThis.G_BUILDTIME = buildInfo.buildTime;
const program = new Program();
program.start();

View File

@ -0,0 +1,5 @@
{
"akiVersion": "",
"commit": "",
"buildTime": 0
}

View File

@ -329,7 +329,7 @@ export class PreAkiModLoader implements IModLoader
*/
protected isModCombatibleWithAki(mod: IPackageJsonData): boolean
{
const akiVersion = this.akiConfig.akiVersion;
const akiVersion = globalThis.G_AKIVERSION || this.akiConfig.akiVersion;
const modName = `${mod.author}-${mod.name}`;
// Error and prevent loading If no akiVersion property exists

View File

@ -53,7 +53,7 @@ export class ConfigServer
}
}
this.logger.info(`Commit hash: ${(this.configs[ConfigTypes.CORE] as ICoreConfig).commit || "DEBUG"}`);
this.logger.info(`Build date: ${(this.configs[ConfigTypes.CORE] as ICoreConfig).buildTime || "DEBUG"}`);
this.logger.info(`Commit hash: ${globalThis.G_COMMIT || "DEBUG"}`);
this.logger.info(`Build date: ${globalThis.G_BUILDTIME || "DEBUG"}`);
}
}

View File

@ -42,15 +42,15 @@ export class App
this.logger.debug(`RAM: ${(os.totalmem() / 1024 / 1024 / 1024).toFixed(2)}GB`);
this.logger.debug(`PATH: ${this.encodingUtil.toBase64(process.argv[0])}`);
this.logger.debug(`PATH: ${this.encodingUtil.toBase64(process.execPath)}`);
this.logger.debug(`Server: ${this.coreConfig.akiVersion}`);
if (this.coreConfig.buildTime)
this.logger.debug(`Server: ${globalThis.G_AKIVERSION || this.coreConfig.akiVersion}`);
if (globalThis.G_BUILDTIME)
{
this.logger.debug(`Date: ${this.coreConfig.buildTime}`);
this.logger.debug(`Date: ${globalThis.G_BUILDTIME}`);
}
if (this.coreConfig.commit)
if (globalThis.G_COMMIT)
{
this.logger.debug(`Commit: ${this.coreConfig.commit}`);
this.logger.debug(`Commit: ${globalThis.G_COMMIT}`);
}
for (const onLoad of this.onLoadComponents)

View File

@ -108,9 +108,10 @@ export class Watermark
*/
public getVersionTag(withEftVersion = false): string
{
const akiVersion = globalThis.G_AKIVERSION || this.akiConfig.akiVersion;
const versionTag = (globalThis.G_DEBUG_CONFIGURATION)
? `${this.akiConfig.akiVersion} - ${this.localisationService.getText("bleeding_edge_build")}`
: this.akiConfig.akiVersion;
? `${akiVersion} - ${this.localisationService.getText("bleeding_edge_build")}`
: akiVersion;
if (withEftVersion)
{
@ -128,9 +129,10 @@ export class Watermark
*/
public getInGameVersionLabel(): string
{
const akiVersion = globalThis.G_AKIVERSION || this.akiConfig.akiVersion;
const versionTag = (globalThis.G_DEBUG_CONFIGURATION)
? `${this.akiConfig.akiVersion} - BLEEDINGEDGE ${this.akiConfig.commit?.slice(0, 6) ?? ""}`
: `${this.akiConfig.akiVersion} - ${this.akiConfig.commit?.slice(0, 6) ?? ""}`;
? `${akiVersion} - BLEEDINGEDGE ${globalThis.G_COMMIT?.slice(0, 6) ?? ""}`
: `${akiVersion} - ${globalThis.G_COMMIT?.slice(0, 6) ?? ""}`;
return `${this.akiConfig.projectName} ${versionTag}`;
}