diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..899d4f4 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,68 @@ +name: Continuous Integration +on: + pull_request: + types: [opened, synchronize, reopened] + paths-ignore: + - '**/*.md' + push: + branches: + - main + paths-ignore: + - '**/*.md' + +jobs: + report: + name: Report + runs-on: ubuntu-latest + outputs: + non_docs_changed: ${{ steps.fileschanged.outputs.non_doc_files_changed }} + steps: + - name: ref + run: echo ${{ github.ref }} + - name: event_name + run: echo ${{ github.event_name }} + - name: checkout + uses: actions/checkout@v4 + with: + fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }} + - id: fileschanged + run: | + case '${{ github.event_name }}' in + push) + firstCommit='${{ github.event.before }}' + lastCommit='${{ github.event.after }}' + ;; + pull_request) + firstCommit='${{ github.event.pull_request.base.sha }}' + lastCommit='${{ github.event.pull_request.head.sha }}' + ;; + esac + changedFiles=$(git diff --name-only --diff-filter=d "${firstCommit}" "${lastCommit}") + echo "Files changed: $changedFiles" + NON_MD_FILES=$(echo "$changedFiles" | grep -v '\.md$' || true) + if [ -n "$NON_MD_FILES" ]; then + echo "non_doc_files_changed=true" >> $GITHUB_OUTPUT + else + echo "non_doc_files_changed=false" >> $GITHUB_OUTPUT + fi + ci: + name: CI + runs-on: ubuntu-latest + needs: [ report ] + if: needs.report.outputs.non_docs_changed == 'true' + steps: + - name: checkout + uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + - name: golangci-lint + uses: golangci/golangci-lint-action@v7 + with: + version: v2.1.2 + - name: vet + run: make vet + - name: Test + run: make test + - name: Build + run: make build-all diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..835766a --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,33 @@ +name: Release +on: + push: + tags: + - 'v*' + +jobs: + report: + name: Report + runs-on: ubuntu-latest + steps: + - name: ref + run: echo ${{ github.ref }} + - name: event_name + run: echo ${{ github.event_name }} + release: + name: Release + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + - name: Build for all platforms + run: | + make build-all + - name: Release + uses: softprops/action-gh-release@v2 + with: + files: | + dist/* diff --git a/Makefile b/Makefile index a389e24..1168b44 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,36 @@ -.PHONY: all build +.PHONY: all build vet test + + +PLATFORMS ?= linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64 windows/arm64 + +GOOS?=$(shell uname -s | tr '[:upper:]' '[:lower:]') +GOARCH?=$(shell uname -m) + +BINDIR := dist +FILENAME := nekko + +BINARY ?= $(BINDIR)/$(FILENAME)-$(GOOS)-$(GOARCH) + +.PRECIOUS: $(foreach platform,$(PLATFORMS),$(BINDIR)/$(FILENAME)-$(subst /,-,$(platform))) + all: build -build: dist/nekko -dist/nekko: - go build -o $@ ./cmd/nekko +build-all: $(foreach platform,$(PLATFORMS),build-local-$(subst /,-,$(platform))) + +build-local-%: $(BINDIR)/$(FILENAME)-%; + +build: $(BINARY) + +vet: + go vet ./... + +test: + go test -v ./... + +$(BINDIR): + mkdir -p $@ + +$(BINDIR)/$(FILENAME)-%: GOOS=$(word 1,$(subst -, ,$*)) +$(BINDIR)/$(FILENAME)-%: GOARCH=$(word 2,$(subst -, ,$*)) +$(BINDIR)/$(FILENAME)-%: $(BINDIR) + GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $@ ./cmd/nekko diff --git a/cmd/nekko/run.go b/cmd/nekko/run.go index 3efbd21..9e8ec87 100644 --- a/cmd/nekko/run.go +++ b/cmd/nekko/run.go @@ -159,7 +159,9 @@ func runCommand(conf *config, logger *log.Logger, v *viper.Viper) (*cobra.Comman flags.StringP("image", "i", "ghcr.io/nekkoai/onnx-eis", "Image to run the model, determined by runtime option, or can be set explicitly") flags.StringP("command", "c", "", "Command to run inside the container (default determined by runtime)") - cmd.MarkFlagRequired("model") + if err := cmd.MarkFlagRequired("model"); err != nil { + return nil, err + } bindFlags(cmd, v) diff --git a/pkg/runtime/onnxruntime/onnxruntime.go b/pkg/runtime/onnxruntime/onnxruntime.go index f67f309..1e86978 100644 --- a/pkg/runtime/onnxruntime/onnxruntime.go +++ b/pkg/runtime/onnxruntime/onnxruntime.go @@ -39,7 +39,7 @@ func (o *onnxRuntime) Content() (map[string][]byte, error) { if err != nil { return nil, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("failed to fetch: %s", resp.Status)