diff --git a/.github/workflows/image-builder.yml b/.github/workflows/image-builder.yml index 3da8603..fe563ca 100644 --- a/.github/workflows/image-builder.yml +++ b/.github/workflows/image-builder.yml @@ -12,7 +12,7 @@ env: PLATFORMS: linux/amd64,linux/arm64 jobs: - server-image-build: + build: runs-on: ubuntu-latest strategy: matrix: diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..bd59806 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,39 @@ +name: Go test + +on: + push: + branches: [main] + tags: + - v* + pull_request_target: + types: [opened, reopened, synchronize] + +jobs: + test: + name: test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + go-version: "1.21" + + - name: Run tests + run: go test ./... + + golangci-lint: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + go-version: "1.21" + + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.55 + args: --timeout=5m diff --git a/.gitignore b/.gitignore index e5e078c..a49e8de 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ dist/* examples/samples cover.out +bin/ diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..38a5f6e --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,5 @@ +linters: + # Enable specific linter + # https://golangci-lint.run/usage/linters/#enabled-by-default + enable: + - goimports diff --git a/Makefile b/Makefile index ff96d2b..4884403 100644 --- a/Makefile +++ b/Makefile @@ -23,13 +23,10 @@ GO_FILES:=$(shell find . -type f -name '*.go' -print) .PHONY: build build_all clean -fmt: - go fmt ./... +lint: golangci-lint + $(GOLANGCI_LINT) run -vet: - go vet ./... - -test: fmt vet +test: lint go test ./... -coverprofile cover.out build_all: $(BUILD_TARGETS) @@ -56,3 +53,15 @@ $(BINARIES): $(GO_FILES) clean: rm $(BINARIES)* + +## Location to install dependencies to +LOCALBIN ?= $(shell pwd)/bin +$(LOCALBIN): + mkdir -p $(LOCALBIN) + +## Tool Binaries +GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint + +golangci-lint: $(GOLANGCI_LINT) +$(GOLANGCI_LINT): $(LOCALBIN) + GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest