From f54865e00a1a4a4c9700672582dabef30790b2f7 Mon Sep 17 00:00:00 2001 From: Henrique Espindola Date: Wed, 29 Mar 2023 17:34:42 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20ci(goreleaser.yml):=20update=20g?= =?UTF-8?q?oreleaser=20config=20to=20include=20separate=20builds=20for=20l?= =?UTF-8?q?inux-amd64,=20darwin-amd64,=20and=20darwin-arm64=20=F0=9F=94=8D?= =?UTF-8?q?=20chore(.gitignore):=20add=20flags/version.txt=20to=20.gitigno?= =?UTF-8?q?re?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🆕 chore(.goreleaser): add support for darwin-arm64 builds 🚀 chore(goreleaser): add linux-amd64 build configuration 🔨 chore(Makefile): add generate target 🔨 chore(flags): add version variable and generate script 🔨 chore(cli): add version variable to kong.Vars 🚀 feat(commands.go): add version flag to print version information and quit 📝 docs(commands.go): add help text for version flag 📝 docs(commands.go): add help text for count-tokens command 🐛 fix(get_version.sh): add newline at the end of file --- .github/workflows/goreleaser.yml | 12 ++++++------ .gitignore | 1 + .goreleaser/{macos.yaml => darwin-amd64.yaml} | 2 +- .goreleaser/{macos-m1.yaml => darwin-arm64.yaml} | 2 +- .goreleaser/{linux.yaml => linux-amd64.yaml} | 2 +- Makefile | 7 +++++-- flags/flags.go | 8 ++++++++ interfaces/cli/cli.go | 6 +++++- interfaces/cli/commands.go | 11 +++++++++++ scripts/get_version.sh | 2 ++ 10 files changed, 41 insertions(+), 12 deletions(-) rename .goreleaser/{macos.yaml => darwin-amd64.yaml} (95%) rename .goreleaser/{macos-m1.yaml => darwin-arm64.yaml} (95%) rename .goreleaser/{linux.yaml => linux-amd64.yaml} (95%) create mode 100644 scripts/get_version.sh diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index 93719e8..6e3d0f4 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -8,7 +8,7 @@ permissions: contents: write jobs: - linux: + linux-amd64: runs-on: ubuntu-latest steps: - name: Checkout @@ -35,12 +35,12 @@ jobs: with: distribution: goreleaser version: latest - args: release --config .goreleaser/linux.yaml --clean + args: release --config .goreleaser/linux-amd64.yaml --clean env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} OPENAI_API_KEY: mock - macos: + darwin-amd64: runs-on: macos-latest steps: - name: Checkout @@ -64,12 +64,12 @@ jobs: with: distribution: goreleaser version: latest - args: release --config .goreleaser/macos.yaml --clean + args: release --config .goreleaser/darwin-amd64.yaml --clean env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} OPENAI_API_KEY: mock - macos-m1: + darwin-arm64: runs-on: macos-latest steps: - name: Checkout @@ -94,7 +94,7 @@ jobs: with: distribution: goreleaser version: latest - args: release --config .goreleaser/macos-m1.yaml --clean + args: release --config .goreleaser/darwin-arm64.yaml --clean env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} OPENAI_API_KEY: mock diff --git a/.gitignore b/.gitignore index a10b3d0..c9a2895 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ cmd/chloe/chloe logging.iml dist/ +flags/version.txt diff --git a/.goreleaser/macos.yaml b/.goreleaser/darwin-amd64.yaml similarity index 95% rename from .goreleaser/macos.yaml rename to .goreleaser/darwin-amd64.yaml index b11a277..dc0b06b 100644 --- a/.goreleaser/macos.yaml +++ b/.goreleaser/darwin-amd64.yaml @@ -23,7 +23,7 @@ archives: - goos: windows format: zip checksum: - name_template: checksums-macos.txt + name_template: checksums-darwin-amd64.txt snapshot: name_template: "{{ incpatch .Version }}-next" changelog: diff --git a/.goreleaser/macos-m1.yaml b/.goreleaser/darwin-arm64.yaml similarity index 95% rename from .goreleaser/macos-m1.yaml rename to .goreleaser/darwin-arm64.yaml index bfa4af6..5ae8b3f 100644 --- a/.goreleaser/macos-m1.yaml +++ b/.goreleaser/darwin-arm64.yaml @@ -23,7 +23,7 @@ archives: - goos: windows format: zip checksum: - name_template: checksums-macos-m1.txt + name_template: checksums-darwin-arm64.txt snapshot: name_template: "{{ incpatch .Version }}-next" changelog: diff --git a/.goreleaser/linux.yaml b/.goreleaser/linux-amd64.yaml similarity index 95% rename from .goreleaser/linux.yaml rename to .goreleaser/linux-amd64.yaml index 6b1a7b4..9066ab2 100644 --- a/.goreleaser/linux.yaml +++ b/.goreleaser/linux-amd64.yaml @@ -24,7 +24,7 @@ archives: - goos: windows format: zip checksum: - name_template: checksums-linux.txt + name_template: checksums-linux-amd64.txt snapshot: name_template: "{{ incpatch .Version }}-next" changelog: diff --git a/Makefile b/Makefile index c44a3c1..4a362a2 100644 --- a/Makefile +++ b/Makefile @@ -2,14 +2,17 @@ ifdef TARGET target := --target ${TARGET} endif -.PHONY: all tokenizer build clean +.PHONY: all tokenizer generate build clean all: tokenizer build tokenizer: cd tokenizer && cargo -C tiktoken-cffi build ${target} --release -Z unstable-options --out-dir . -build: tokenizer +generate: + go generate ./... + +build: tokenizer generate CGO_ENABLED=1 go build -o ./cmd/chloe/chloe ./cmd/chloe/main.go clean: diff --git a/flags/flags.go b/flags/flags.go index b6f24d3..438433b 100644 --- a/flags/flags.go +++ b/flags/flags.go @@ -1,3 +1,11 @@ package flags +import ( + _ "embed" +) + var InteractiveCLI bool + +//go:generate bash ../scripts/get_version.sh +//go:embed version.txt +var Version string diff --git a/interfaces/cli/cli.go b/interfaces/cli/cli.go index ca98d35..920dfc6 100644 --- a/interfaces/cli/cli.go +++ b/interfaces/cli/cli.go @@ -3,6 +3,7 @@ package cli import ( "context" "github.com/alecthomas/kong" + "github.com/kamushadenes/chloe/flags" "github.com/kamushadenes/chloe/memory" ) @@ -29,7 +30,10 @@ func Handle(ctx context.Context) error { kong.UsageOnError(), kong.ConfigureHelp(kong.HelpOptions{ Compact: true, - })) + }), + kong.Vars{ + "version": flags.Version, + }) return kongCtx.Run(&Globals{Context: ctx}) } diff --git a/interfaces/cli/commands.go b/interfaces/cli/commands.go index 1cb0150..e845d0f 100644 --- a/interfaces/cli/commands.go +++ b/interfaces/cli/commands.go @@ -22,12 +22,23 @@ var CLIFlags struct { TTS TTSCmd `cmd:"tts" short:"t" help:"Generate an audio from a prompt"` Forget ForgetCmd `cmd:"forget" short:"f" help:"Forget all users"` CountTokens CountTokensCmd `cmd:"count-tokens" help:"Count tokens"` + Version VersionFlag `name:"version" help:"Print version information and quit"` } func parseFlags() *kong.Context { return kong.Parse(&CLIFlags) } +type VersionFlag string + +func (v VersionFlag) Decode(ctx *kong.DecodeContext) error { return nil } +func (v VersionFlag) IsBool() bool { return true } +func (v VersionFlag) BeforeApply(app *kong.Kong, vars kong.Vars) error { + fmt.Println(vars["version"]) + app.Exit(0) + return nil +} + type CompleteCmd struct { Prompt []string `arg:"" optional:"" help:"Prompt to complete"` } diff --git a/scripts/get_version.sh b/scripts/get_version.sh new file mode 100644 index 0000000..7ecfe61 --- /dev/null +++ b/scripts/get_version.sh @@ -0,0 +1,2 @@ +#!/bin/bash +git describe --tags --abbrev=0 > version.txt \ No newline at end of file