Skip to content

Commit

Permalink
📦 include git short sha in builds
Browse files Browse the repository at this point in the history
  • Loading branch information
yusufcanb committed Mar 8, 2024
1 parent 5cd510b commit 9e7fa54
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
8 changes: 4 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ type TlmApp struct {
suggestModelfile string
}

func New(version string) *TlmApp {
func New(version, buildSha string) *TlmApp {
con := config.New()
con.LoadOrCreateConfig()

o, _ := ollama.ClientFromEnvironment()
sug := suggest.New(o, suggestModelfile)
exp := explain.New(o, explainModelfile)
sug := suggest.New(o)
exp := explain.New(o)
ins := install.New(o, suggestModelfile, explainModelfile)

cliApp := &cli.App{
Expand All @@ -59,7 +59,7 @@ func New(version string) *TlmApp {
Aliases: []string{"v"},
Usage: "Prints tlm version.",
Action: func(c *cli.Context) error {
fmt.Printf("tlm %s (%s/%s)", version, runtime.GOOS, runtime.GOARCH)
fmt.Printf("tlm %s %s on %s/%s", version, buildSha, runtime.GOOS, runtime.GOARCH)
return nil
},
},
Expand Down
3 changes: 2 additions & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ New-Item -ItemType Directory -Path "dist"
# Build Function (Helper)
Function Build-Target($os, $version, $arch) {
$outputName = "${appName}_${version}_${os}_${arch}"
$sha1 = (git rev-parse --short HEAD).Trim()
if ($os -eq "windows") {
$outputName += ".exe"
}

Write-Output "Building for $os/$arch (version: $version) -> $outputName"
# Invokes the Go toolchain (assumes it's in the PATH)
go build -o "dist/$version/$outputName" "main.go"
go build -o "dist/$version/$outputName" -ldflags "-X main.sha1ver=$sha1" "main.go"
}

# Build for each target OS
Expand Down
3 changes: 2 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ build() {
app_name=$2
version=$3
arch=$4
sha1=$(git rev-parse --short HEAD | tr -d '\n')

# Determine output filename with optional .exe extension
output_name="${app_name}_${version}_${os}_${arch}"
Expand All @@ -14,7 +15,7 @@ build() {
fi

echo "Building for $os/$arch (version: $version) -> $output_name"
CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -o "dist/${version}/${output_name}" main.go
CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -o "dist/${version}/${output_name}" -ldflags "-X main.sha1ver=$sha1" main.go
}

# Operating systems to target
Expand Down
5 changes: 2 additions & 3 deletions explain/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import (

type Explain struct {
api *ollama.Client
modelfile string
modelfileName string
}

func New(api *ollama.Client, modelfile string) *Explain {
e := &Explain{api: api, modelfile: modelfile, modelfileName: "explain:7b"}
func New(api *ollama.Client) *Explain {
e := &Explain{api: api, modelfileName: "explain:7b"}
return e
}
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (

//go:embed VERSION
var version string
var sha1ver string

func main() {
tlm := app.New(version)
tlm := app.New(version, sha1ver)
if err := tlm.App.Run(os.Args); err != nil {
log.Fatal(err)
}
Expand Down
5 changes: 2 additions & 3 deletions suggest/suggest.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import (

type Suggest struct {
api *ollama.Client
modelfile string
modelfileName string
}

func New(api *ollama.Client, modelfile string) *Suggest {
return &Suggest{api: api, modelfile: modelfile, modelfileName: "suggest:7b"}
func New(api *ollama.Client) *Suggest {
return &Suggest{api: api, modelfileName: "suggest:7b"}
}

0 comments on commit 9e7fa54

Please sign in to comment.