@@ -4,13 +4,50 @@ import {currentReleaseGitBundlePath, defaultLlamaCppGitHubRepo, llamaCppDirector
4
4
import { getBinariesGithubRelease } from "./binariesGithubRelease.js" ;
5
5
6
6
7
- export async function saveCurrentRepoAsReleaseBundle ( ) {
7
+ export async function unshallowAndSquashCurrentRepoAndSaveItAsReleaseBundle ( ) {
8
8
if ( ! ( await fs . pathExists ( llamaCppDirectory ) ) )
9
9
throw new Error ( "llama.cpp directory does not exist" ) ;
10
10
11
11
if ( await fs . pathExists ( currentReleaseGitBundlePath ) )
12
12
await fs . remove ( currentReleaseGitBundlePath ) ;
13
13
14
+ await simpleGit ( llamaCppDirectory ) . addConfig ( "user.name" , "node-llama-cpp-ci" ) ;
15
+ await simpleGit ( llamaCppDirectory ) . addConfig ( "user.email" , "[email protected] " ) ;
16
+
17
+ const currentBranch = await getCurrentTagOrBranch ( ) ;
18
+
19
+ await simpleGit ( llamaCppDirectory ) . fetch ( [ "--unshallow" ] ) ;
20
+
21
+ const lastCommit = await simpleGit ( llamaCppDirectory ) . log ( [ "-1" ] ) ;
22
+ const lastCommitMessage : string | null = lastCommit ?. all ?. [ 0 ] ?. message ;
23
+ const newCommitMessage = "## SQUASHED ##\n\n" + ( lastCommitMessage ?? "" ) ;
24
+
25
+ const newCommitSha = await simpleGit ( llamaCppDirectory ) . raw ( [ "commit-tree" , "HEAD^{tree}" , "-m" , newCommitMessage ] ) ;
26
+ await simpleGit ( llamaCppDirectory ) . reset ( [ "--hard" , newCommitSha . trim ( ) ] ) ;
27
+
28
+ const tags = await simpleGit ( llamaCppDirectory ) . tags ( ) ;
29
+ for ( const tag of tags . all ) {
30
+ await simpleGit ( llamaCppDirectory ) . tag ( [ "--delete" , tag ] ) ;
31
+ }
32
+
33
+ const branches = await simpleGit ( llamaCppDirectory ) . branch ( ) ;
34
+ for ( const branch of branches . all ) {
35
+ try {
36
+ await simpleGit ( llamaCppDirectory ) . branch ( [ "--delete" , branch ] ) ;
37
+ } catch ( err ) {
38
+ // If the branch is not found, it's fine
39
+ // this happens as when there are no branches git returnes an output saying so, and `simpleGit` parses it as a branch,
40
+ // so the list may contain branches that do not exist.
41
+ // Right now, the non-existent branch name returned called `(no`, but I wouldn't want to rely on this specific text,
42
+ // as this is a bug in `simpleGit`.
43
+ }
44
+ }
45
+
46
+ if ( currentBranch != null )
47
+ await simpleGit ( llamaCppDirectory ) . tag ( [ currentBranch ] ) ;
48
+
49
+ await simpleGit ( llamaCppDirectory ) . raw ( [ "gc" , "--aggressive" , "--prune=all" ] ) ;
50
+
14
51
await simpleGit ( llamaCppDirectory ) . raw ( [ "bundle" , "create" , currentReleaseGitBundlePath , "HEAD" ] ) ;
15
52
}
16
53
@@ -32,3 +69,18 @@ export async function getGitBundlePathForRelease(githubOwner: string, githubRepo
32
69
33
70
return currentReleaseGitBundlePath ;
34
71
}
72
+
73
+ async function getCurrentTagOrBranch ( ) {
74
+ const branch = await simpleGit ( llamaCppDirectory ) . revparse ( [ "--abbrev-ref" , "HEAD" ] ) ;
75
+
76
+ if ( branch !== "HEAD" )
77
+ return branch ;
78
+
79
+ const tags = await simpleGit ( llamaCppDirectory ) . tag ( [ "--points-at" , "HEAD" ] ) ;
80
+ const tagArray = tags . split ( "\n" ) . filter ( Boolean ) ;
81
+
82
+ if ( tagArray . length > 0 )
83
+ return tagArray [ 0 ] ;
84
+
85
+ return null ;
86
+ }
0 commit comments