-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
130 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import simpleGit, {SimpleGit} from "simple-git"; | ||
import cliProgress from "cli-progress"; | ||
import chalk from "chalk"; | ||
import fs from "fs-extra"; | ||
import {llamaCppDirectory} from "../config.js"; | ||
import {getGitBundlePathForRelease} from "./gitReleaseBundles.js"; | ||
|
||
|
||
export async function cloneLlamaCppRepo(githubOwner: string, githubRepo: string, tag: string) { | ||
const gitBundleForTag = await getGitBundlePathForRelease(githubOwner, githubRepo, tag); | ||
const remoteGitUrl = `https://github.com/${githubOwner}/${githubRepo}.git`; | ||
|
||
async function withGitCloneProgress<T>(cloneName: string, callback: (gitWithCloneProgress: SimpleGit) => Promise<T>): Promise<T> { | ||
const progressBar = new cliProgress.Bar({ | ||
clearOnComplete: false, | ||
hideCursor: true, | ||
autopadding: true, | ||
format: `${chalk.bold("Clone {repo}")} ${chalk.yellow("{percentage}%")} ${chalk.cyan("{bar}")} ${chalk.grey("{eta_formatted}")}` | ||
}, cliProgress.Presets.shades_classic); | ||
|
||
progressBar.start(100, 0, { | ||
speed: "", | ||
repo: `${githubOwner}/${githubRepo} (${cloneName})` | ||
}); | ||
|
||
const gitWithCloneProgress = simpleGit({ | ||
progress({progress, total, processed}) { | ||
const totalProgress = (processed / 100) + (progress / total); | ||
|
||
progressBar.update(Math.floor(totalProgress * 10000) / 100); | ||
} | ||
}); | ||
|
||
try { | ||
const res = await callback(gitWithCloneProgress); | ||
|
||
progressBar.update(100); | ||
|
||
return res; | ||
} finally { | ||
progressBar.stop(); | ||
} | ||
} | ||
|
||
if (gitBundleForTag != null) { | ||
try { | ||
await withGitCloneProgress("local bundle", async (gitWithCloneProgress) => { | ||
await gitWithCloneProgress.clone(gitBundleForTag, llamaCppDirectory, { | ||
"--quiet": null | ||
}); | ||
|
||
await simpleGit(llamaCppDirectory) | ||
.removeRemote("origin"); | ||
await simpleGit(llamaCppDirectory) | ||
.addRemote("origin", remoteGitUrl); | ||
}); | ||
return; | ||
} catch (err) { | ||
await fs.remove(llamaCppDirectory); | ||
console.error("Failed to clone git bundle, cloning from GitHub instead", err); | ||
} | ||
} | ||
|
||
await withGitCloneProgress("GitHub", async (gitWithCloneProgress) => { | ||
await gitWithCloneProgress.clone(remoteGitUrl, llamaCppDirectory, { | ||
"--depth": 1, | ||
"--branch": tag, | ||
"--quiet": null | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import fs from "fs-extra"; | ||
import simpleGit from "simple-git"; | ||
import {currentReleaseGitBundlePath, defaultLlamaCppGitHubRepo, llamaCppDirectory} from "../config.js"; | ||
import {getBinariesGithubRelease} from "./binariesGithubRelease.js"; | ||
|
||
|
||
export async function saveCurrentRepoAsReleaseBundle() { | ||
if (!(await fs.pathExists(llamaCppDirectory))) | ||
throw new Error("llama.cpp directory does not exist"); | ||
|
||
if (await fs.pathExists(currentReleaseGitBundlePath)) | ||
await fs.remove(currentReleaseGitBundlePath); | ||
|
||
await simpleGit(llamaCppDirectory).raw(["bundle", "create", currentReleaseGitBundlePath, "HEAD"]); | ||
} | ||
|
||
export async function getGitBundlePathForRelease(githubOwner: string, githubRepo: string, release: string) { | ||
const [defaultGithubOwner, defaultGithubRepo] = defaultLlamaCppGitHubRepo.split("/"); | ||
if (githubOwner !== defaultGithubOwner || githubRepo !== defaultGithubRepo) | ||
return null; | ||
|
||
const currentBundleRelease = await getBinariesGithubRelease(); | ||
|
||
if (currentBundleRelease === "latest") | ||
return null; | ||
|
||
if (currentBundleRelease !== release) | ||
return null; | ||
|
||
if (!(await fs.pathExists(currentReleaseGitBundlePath))) | ||
return null; | ||
|
||
return currentReleaseGitBundlePath; | ||
} |