diff --git a/.github/workflows/ui-bff-build.yml b/.github/workflows/ui-bff-build.yml index 3957f5b3..9248d2de 100644 --- a/.github/workflows/ui-bff-build.yml +++ b/.github/workflows/ui-bff-build.yml @@ -24,6 +24,12 @@ jobs: working-directory: clients/ui/bff run: make clean + - name: Lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.57.2 + working-directory: clients/ui/bff/ + - name: Build working-directory: clients/ui/bff run: make build diff --git a/clients/ui/bff/Makefile b/clients/ui/bff/Makefile index 3049355f..f58c08d1 100644 --- a/clients/ui/bff/Makefile +++ b/clients/ui/bff/Makefile @@ -19,6 +19,14 @@ fmt: clean: rm -Rf ./bin +.PHONY: lint +lint: golangci-lint ## Run golangci-lint linter + $(GOLANGCI_LINT) run + +.PHONY: lint-fix +lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes + $(GOLANGCI_LINT) run --fix + .PHONY: vet vet: . go vet ./... @@ -38,3 +46,33 @@ run: fmt vet .PHONY: docker-build docker-build: $(CONTAINER_TOOL) build -t ${IMG} . + +##@ Dependencies + +## Location to install dependencies to +LOCALBIN ?= $(shell pwd)/bin +$(LOCALBIN): + mkdir -p $(LOCALBIN) + +GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION) +GOLANGCI_LINT_VERSION ?= v1.57.2 + +.PHONY: golangci-lint +golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. +$(GOLANGCI_LINT): $(LOCALBIN) + $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,${GOLANGCI_LINT_VERSION}) + + +# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist +# $1 - target path with name of binary (ideally with version) +# $2 - package url which can be installed +# $3 - specific version of package +define go-install-tool +@[ -f $(1) ] || { \ +set -e; \ +package=$(2)@$(3) ;\ +echo "Downloading $${package}" ;\ +GOBIN=$(LOCALBIN) go install $${package} ;\ +mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\ +} +endef \ No newline at end of file diff --git a/clients/ui/bff/docs/contributing.md b/clients/ui/bff/docs/contributing.md new file mode 100644 index 00000000..22ccd788 --- /dev/null +++ b/clients/ui/bff/docs/contributing.md @@ -0,0 +1,11 @@ +# Contributing + +## Running the linter locally +The BFF directory uses golangci-lint to combine multiple linters for a more comprehensive linting process. To install and run simply use: + +```shell +cd clients/ui/bff +make lint +``` + +For more information on configuring golangci-lint see the [documentation](https://golangci-lint.run/). diff --git a/clients/ui/bff/internal/api/errors.go b/clients/ui/bff/internal/api/errors.go index b15e1cd4..686cf7c4 100644 --- a/clients/ui/bff/internal/api/errors.go +++ b/clients/ui/bff/internal/api/errors.go @@ -3,9 +3,10 @@ package api import ( "encoding/json" "fmt" - "github.com/kubeflow/model-registry/ui/bff/internal/integrations" "net/http" "strconv" + + "github.com/kubeflow/model-registry/ui/bff/internal/integrations" ) type HTTPError struct { @@ -91,7 +92,8 @@ func (app *App) methodNotAllowedResponse(w http.ResponseWriter, r *http.Request) app.errorResponse(w, r, httpError) } -func (app *App) failedValidationResponse(w http.ResponseWriter, r *http.Request, errors map[string]string) { +// TODO remove nolint comment below when we use this method +func (app *App) failedValidationResponse(w http.ResponseWriter, r *http.Request, errors map[string]string) { //nolint:unused message, err := json.Marshal(errors) if err != nil { diff --git a/clients/ui/bff/internal/data/model_version_test.go b/clients/ui/bff/internal/data/model_version_test.go index b2da9637..1f842042 100644 --- a/clients/ui/bff/internal/data/model_version_test.go +++ b/clients/ui/bff/internal/data/model_version_test.go @@ -2,17 +2,18 @@ package data import ( "encoding/json" + "net/http" + "net/url" + "testing" + "github.com/brianvoe/gofakeit/v7" "github.com/kubeflow/model-registry/ui/bff/internal/mocks" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" - "net/http" - "net/url" - "testing" ) func TestGetModelVersion(t *testing.T) { - gofakeit.Seed(0) + gofakeit.Seed(0) //nolint:errcheck expected := mocks.GenerateMockModelVersion() @@ -37,7 +38,7 @@ func TestGetModelVersion(t *testing.T) { } func TestCreateModelVersion(t *testing.T) { - gofakeit.Seed(0) + gofakeit.Seed(0) //nolint:errcheck expected := mocks.GenerateMockModelVersion() @@ -62,7 +63,7 @@ func TestCreateModelVersion(t *testing.T) { } func TestUpdateModelVersion(t *testing.T) { - gofakeit.Seed(0) + gofakeit.Seed(0) //nolint:errcheck expected := mocks.GenerateMockModelVersion() @@ -90,7 +91,7 @@ func TestUpdateModelVersion(t *testing.T) { } func TestGetModelArtifactsByModelVersion(t *testing.T) { - gofakeit.Seed(0) + gofakeit.Seed(0) //nolint:errcheck expected := mocks.GenerateMockModelArtifactList() @@ -116,7 +117,7 @@ func TestGetModelArtifactsByModelVersion(t *testing.T) { } func TestCreateModelArtifactByModelVersion(t *testing.T) { - gofakeit.Seed(0) + gofakeit.Seed(0) //nolint:errcheck expected := mocks.GenerateMockModelArtifact() diff --git a/clients/ui/bff/internal/data/registered_model_test.go b/clients/ui/bff/internal/data/registered_model_test.go index 0af73f16..f340527d 100644 --- a/clients/ui/bff/internal/data/registered_model_test.go +++ b/clients/ui/bff/internal/data/registered_model_test.go @@ -2,17 +2,18 @@ package data import ( "encoding/json" + "net/http" + "net/url" + "testing" + "github.com/brianvoe/gofakeit/v7" "github.com/kubeflow/model-registry/ui/bff/internal/mocks" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" - "net/http" - "net/url" - "testing" ) func TestGetAllRegisteredModels(t *testing.T) { - gofakeit.Seed(0) + gofakeit.Seed(0) //nolint:errcheck expected := mocks.GenerateMockRegisteredModelList() @@ -36,7 +37,7 @@ func TestGetAllRegisteredModels(t *testing.T) { } func TestCreateRegisteredModel(t *testing.T) { - gofakeit.Seed(0) + gofakeit.Seed(0) //nolint:errcheck expected := mocks.GenerateMockRegisteredModel() @@ -61,7 +62,7 @@ func TestCreateRegisteredModel(t *testing.T) { } func TestGetRegisteredModel(t *testing.T) { - gofakeit.Seed(0) + gofakeit.Seed(0) //nolint:errcheck expected := mocks.GenerateMockRegisteredModel() @@ -83,7 +84,7 @@ func TestGetRegisteredModel(t *testing.T) { } func TestUpdateRegisteredModel(t *testing.T) { - gofakeit.Seed(0) + gofakeit.Seed(0) //nolint:errcheck expected := mocks.GenerateMockRegisteredModel() @@ -111,7 +112,7 @@ func TestUpdateRegisteredModel(t *testing.T) { } func TestGetAllModelVersions(t *testing.T) { - gofakeit.Seed(0) + gofakeit.Seed(0) //nolint:errcheck expected := mocks.GenerateMockModelVersionList() @@ -139,7 +140,7 @@ func TestGetAllModelVersions(t *testing.T) { } func TestCreateModelVersionForRegisteredModel(t *testing.T) { - gofakeit.Seed(0) + gofakeit.Seed(0) //nolint:errcheck expected := mocks.GenerateMockModelVersion()