From afdf236c808fcb0fee10f290ab5380b67d52c359 Mon Sep 17 00:00:00 2001 From: Nick Hale <4175918+njhale@users.noreply.github.com> Date: Fri, 9 Feb 2024 05:13:32 -0500 Subject: [PATCH] fix: goreleaser templating and linting - Fix broken goreleaser templating - Fix validation and improve linting - Correct pre-existing linting errors Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com> --- .golangci.yml | 22 ++++++++++++++++++++++ .goreleaser.yml | 2 +- Makefile | 22 ++++++++++++++++++++-- pkg/engine/cmd.go | 4 ++-- pkg/engine/daemon.go | 4 +++- pkg/server/server.go | 4 ++++ pkg/test/examples_test.go | 1 + 7 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..889ceba6 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,22 @@ +run: + timeout: 5m + +output: + format: github-actions + +linters: + disable-all: true + enable: + - errcheck + - gofmt + - gosimple + - govet + - ineffassign + - staticcheck + - typecheck + - thelper + - unused + - goimports + - whitespace + fast: false + max-same-issues: 50 diff --git a/.goreleaser.yml b/.goreleaser.yml index c1bc4d2f..99b892f5 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -31,7 +31,7 @@ archives: builds: - default - mac - name_template: '{{.Project}}-v{{ .Version }}-{{ if eq .Os "darwin" }}macOS-universal{{ else }}{{ .Os }}-{{ .Arch }}{{ .Arm }}{{ end }}' + name_template: 'gptscript-v{{ .Version }}-{{ if eq .Os "darwin" }}macOS-universal{{ else }}{{ .Os }}-{{ .Arch }}{{ .Arm }}{{ end }}' format_overrides: - goos: windows format: zip diff --git a/Makefile b/Makefile index 42f78b01..c05db3b2 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,30 @@ build: CGO_ENABLED=0 go build -o bin/gptscript -tags "${GO_TAGS}" -ldflags "-s -w" . +tidy: + go mod tidy + test: go test -v ./... -validate: - go vet ./... +GOLANGCI_LINT_VERSION ?= v1.56.1 +lint: + if ! command -v golangci-lint &> /dev/null; then \ + echo "Could not find golangci-lint, installing version $(GOLANGCI_LINT_VERSION)."; \ + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin $(GOLANGCI_LINT_VERSION); \ + fi + golangci-lint run + +validate: tidy lint + if [ -n "$$(git status --porcelain)" ]; then \ + git status --porcelain; \ + echo "Encountered dirty repo!"; \ + git diff; \ + exit 1 \ + ;fi + ci: build ./bin/gptscript ./scripts/ci.gpt + diff --git a/pkg/engine/cmd.go b/pkg/engine/cmd.go index ca4de79b..ceeda580 100644 --- a/pkg/engine/cmd.go +++ b/pkg/engine/cmd.go @@ -77,8 +77,8 @@ func (e *Engine) newCommand(ctx context.Context, extraEnv []string, instructions envMap := map[string]string{} for _, env := range env { - key, value, ok := strings.Cut(env, "=") - key, ok = strings.CutPrefix(key, "GPTSCRIPT_VAR_") + key, value, _ := strings.Cut(env, "=") + key, ok := strings.CutPrefix(key, "GPTSCRIPT_VAR_") if !ok { continue } diff --git a/pkg/engine/daemon.go b/pkg/engine/daemon.go index 6b9162fb..884c02c6 100644 --- a/pkg/engine/daemon.go +++ b/pkg/engine/daemon.go @@ -86,7 +86,9 @@ func (e *Engine) startDaemon(ctx context.Context, tool types.Tool) (string, erro }() context.AfterFunc(ctx, func() { - cmd.Process.Kill() + if err := cmd.Process.Kill(); err != nil { + log.Errorf("daemon failed to kill tool [%s] process: %v", tool.Name, err) + } }) for range 20 { diff --git a/pkg/server/server.go b/pkg/server/server.go index b28d6e23..ad56e6b3 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -53,6 +53,10 @@ func New(opts ...Options) (*Server, error) { events: events, }, })...) + if err != nil { + return nil, err + } + noCacheRunner, err := runner.New(append(runnerOpts, runner.Options{ CacheOptions: runner.CacheOptions{ Cache: new(bool), diff --git a/pkg/test/examples_test.go b/pkg/test/examples_test.go index 747144b4..2a02507a 100644 --- a/pkg/test/examples_test.go +++ b/pkg/test/examples_test.go @@ -55,6 +55,7 @@ func TestEcho(t *testing.T) { } func RequireOpenAPIKey(t *testing.T) { + t.Helper() if os.Getenv("OPENAI_API_KEY") == "" { t.Skip() }