mirror of
https://github.com/theroyallab/YALS.git
synced 2026-04-20 14:29:47 +00:00
Main: Add method to embed and fetch git sha
This allows for users to track which version of YALS is compiled. Signed-off-by: kingbri <8082010+kingbri1@users.noreply.github.com>
This commit is contained in:
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
@@ -73,7 +73,7 @@ jobs:
|
||||
export CMAKE_CUDA_ARCHITECTURES="75;86;89;120"
|
||||
fi
|
||||
deno task bindings
|
||||
deno task compile
|
||||
deno task build
|
||||
chmod +x YALS
|
||||
- name: Copy CUDA libraries
|
||||
run: |
|
||||
@@ -183,7 +183,7 @@ jobs:
|
||||
$env:CMAKE_CUDA_ARCHITECTURES="75;86;89;120"
|
||||
}
|
||||
deno task bindings-win
|
||||
deno task compile
|
||||
deno task build
|
||||
- name: Copy vcruntime
|
||||
run: |
|
||||
cp "C:\Windows\System32\vcruntime140.dll" lib
|
||||
|
||||
8
.gitignore
vendored
8
.gitignore
vendored
@@ -45,3 +45,11 @@ templates/*
|
||||
!templates/place_your_templates_here.txt
|
||||
!templates/alpaca.jinja
|
||||
!templates/chatml.jinja
|
||||
|
||||
# Compiled binaries and embedded assets
|
||||
gitSha.txt
|
||||
YALS.exe
|
||||
YALS
|
||||
|
||||
# Markdown
|
||||
.obsidian/
|
||||
|
||||
@@ -9,3 +9,27 @@ export function asyncDefer(callback: () => Promise<void>): AsyncDisposable {
|
||||
[Symbol.asyncDispose]: async () => await callback(),
|
||||
};
|
||||
}
|
||||
|
||||
export async function getCommitSha() {
|
||||
const cmd = new Deno.Command("git", {
|
||||
args: ["rev-parse", "--short", "HEAD"],
|
||||
});
|
||||
try {
|
||||
const { stdout } = await cmd.output();
|
||||
const sha = new TextDecoder().decode(stdout).trim();
|
||||
|
||||
return sha;
|
||||
} catch (error) {
|
||||
console.error(`Failed to get commit SHA: ${error}`);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getYalsVersion() {
|
||||
try {
|
||||
return Deno.readTextFileSync(`${import.meta.dirname}/gitSha.txt`)
|
||||
.trim();
|
||||
} catch {
|
||||
return await getCommitSha();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
"tasks": {
|
||||
"dev": "deno run -A --watch main.ts",
|
||||
"start": "deno run --allow-read --allow-write=api_tokens.yml --allow-env --allow-sys --allow-net --allow-ffi main.ts",
|
||||
"compile": "deno compile --allow-read --allow-write=api_tokens.yml --allow-env --allow-sys --allow-net --allow-ffi main.ts",
|
||||
"bindings": "cd bindings && ./bindings.sh",
|
||||
"bindings-win": "cd bindings && powershell -ExecutionPolicy Bypass -File bindings.ps1"
|
||||
"bindings-win": "cd bindings && powershell -ExecutionPolicy Bypass -File bindings.ps1",
|
||||
"generate-sha": "deno run --allow-run --allow-write=gitSha.txt generateGitSha.ts",
|
||||
"compile": "deno compile --allow-read --allow-write=api_tokens.yml --allow-env --allow-sys --allow-net --allow-ffi --include=gitSha.txt main.ts",
|
||||
"build": "deno task generate-sha && deno task compile"
|
||||
},
|
||||
"imports": {
|
||||
"@/": "./",
|
||||
|
||||
12
generateGitSha.ts
Normal file
12
generateGitSha.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { getCommitSha } from "@/common/utils.ts";
|
||||
|
||||
if (import.meta.main) {
|
||||
const sha = await getCommitSha();
|
||||
|
||||
if (sha) {
|
||||
await Deno.writeTextFile("gitSha.txt", sha);
|
||||
console.log(`Successfully wrote Git SHA (${sha}) to gitSha.txt.`);
|
||||
} else {
|
||||
console.log("Failed to write Git SHA due to the errors above.");
|
||||
}
|
||||
}
|
||||
12
main.ts
12
main.ts
@@ -2,12 +2,22 @@ import { createApi } from "@/api/server.ts";
|
||||
import { loadAuthKeys } from "@/common/auth.ts";
|
||||
import { parseArgs } from "@/common/args.ts";
|
||||
import { config, loadConfig } from "@/common/config.ts";
|
||||
import { setupLogger } from "@/common/logging.ts";
|
||||
import { logger, setupLogger } from "@/common/logging.ts";
|
||||
import { loadModel } from "@/common/modelContainer.ts";
|
||||
import { getYalsVersion } from "@/common/utils.ts";
|
||||
|
||||
if (import.meta.main) {
|
||||
await setupLogger();
|
||||
|
||||
// Use Promise resolution to avoid nested try/catch
|
||||
const version = await getYalsVersion();
|
||||
|
||||
if (version) {
|
||||
logger.info(`Using YALS commit ${version}`);
|
||||
} else {
|
||||
logger.info("Could not find YALS commit version. Launching anyway.");
|
||||
}
|
||||
|
||||
// Parse CLI args
|
||||
const { args, usage } = parseArgs();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user