From f8c8f5caf2197aa7242cd0942619345b7ea3f1cb Mon Sep 17 00:00:00 2001 From: Nikolai Rodionov Date: Fri, 27 Feb 2026 10:55:09 +0100 Subject: [PATCH] Update deps and add CI Signed-off-by: Nikolai Rodionov --- .github/workflows/test.yaml | 33 +++++++++++++++++++++++++++++++++ .gitignore | 4 +++- Makefile | 20 ++++++++++++++++---- go.mod | 2 +- rand/source_test.go | 1 + 5 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..f53d764 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,33 @@ +name: Tests and linters + +on: + pull_request: + branches: + - main + push: + branches: + - main + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - name: Get go version + run: echo "GO_VERSION=$(make desired_go_version)" >> "${GITHUB_ENV}" + - uses: actions/setup-go@v6 + with: + go-version: ${{ env.GO_VERSION }} + - run: make lint + + unit-test: + runs-on: ubuntu-latest + needs: lint + steps: + - uses: actions/checkout@v6 + - name: Get go version + run: echo "GO_VERSION=$(make desired_go_version)" >> "${GITHUB_ENV}" + - uses: actions/setup-go@v6 + with: + go-version: ${{ env.GO_VERSION }} + - run: make test diff --git a/.gitignore b/.gitignore index 10d5b57..399c6f1 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,6 @@ # Goland /.idea/ -*.iml \ No newline at end of file +*.iml + +bin diff --git a/Makefile b/Makefile index 03be030..313e32f 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,8 @@ SRC = $(shell find . -type f -name '*.go') +GOLANGCI_LINT_VERSION ?= v2.3.1 +LOCALBIN ?= $(shell pwd)/bin +$(LOCALBIN): + mkdir -p $(LOCALBIN) run: $(SRC) @go run cmd/main.go @@ -6,13 +10,21 @@ run: $(SRC) test: $(SRC) @go test ./... -lint: $(SRC) +fmt: $(SRC) @gofmt -s -l -w $^ @goimports -w $^ - @golint ./... - @golangci-lint run --enable-all -D gomnd -D funlen ./... + +lint: ## lint go code + echo "desired golangci-lint version is ${GOLANGCI_LINT_VERSION}" + @go mod download + test -s $(LOCALBIN)/golangci-lint || GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${GOLANGCI_LINT_VERSION} + $(LOCALBIN)/golangci-lint --version + $(LOCALBIN)/golangci-lint run ./... --timeout 240s clean: @go clean -testcache -.PHONY: run test lint clean \ No newline at end of file +.PHONY: run test lint clean + +desired_go_version: ## get a desired go version from the Containerfile + @grep -o -P '(?<=go ).*' go.mod diff --git a/go.mod b/go.mod index b14828a..891651c 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/db-operator/can-haz-password -go 1.17 +go 1.25.0 require ( github.com/geozelot/intree v1.0.1 diff --git a/rand/source_test.go b/rand/source_test.go index f1bc4a2..1e163a1 100644 --- a/rand/source_test.go +++ b/rand/source_test.go @@ -45,6 +45,7 @@ func TestCryptoRandomSource(t *testing.T) { // If the point falls within the bounds of a circle (eg. a radius from a origin point). // Then count that point as falling inside of the circle, as well as inside of the bounding box. + //nolint:all if math.Pow(x, 2)+math.Pow(y, 2) <= 1.0 { circle++ }