Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
name: Test

on:
pull_request:
types: [opened]
push:
branches-ignore: [ main ]

branches-ignore: [main]
env:
GO_VERSION: '1.24'
GOLANGCI_LINT_VERSION: 'v2.1'

GO_VERSION: '1.25.5'
GOLANGCI_LINT_VERSION: 'v2.8.0'
jobs:
# Check if there is any dirty change for go mod tidy
go-mod:
Expand All @@ -24,7 +21,6 @@ jobs:
go mod tidy
git diff --exit-code go.mod
git diff --exit-code go.sum

go-test:
needs: go-mod
runs-on: ubuntu-latest
Expand All @@ -34,7 +30,6 @@ jobs:
with:
go-version: ${{ env.GO_VERSION }}
- run: go test ./... -race

golangci-lint:
needs: go-test
runs-on: ubuntu-latest
Expand All @@ -46,7 +41,6 @@ jobs:
- uses: golangci/golangci-lint-action@v8
with:
version: ${{ env.GOLANGCI_LINT_VERSION }}

detect-modules: # ref: https://github.com/golangci/golangci-lint-action/tree/main
needs: [golangci-lint, go-test, go-mod]
runs-on: ubuntu-latest
Expand All @@ -66,7 +60,6 @@ jobs:
path: go.work
- id: set-modules
run: echo "modules=$(go list -m -json | jq -s '.' | jq -c '[.[].Dir]')" >> $GITHUB_OUTPUT

go-mod-examples:
needs: [detect-modules]
runs-on: ubuntu-latest
Expand All @@ -86,7 +79,6 @@ jobs:
git diff --exit-code go.mod
git diff --exit-code go.sum
working-directory: ${{ matrix.modules }}

go-test-examples:
needs: [detect-modules, go-mod-examples]
runs-on: ubuntu-latest
Expand All @@ -105,7 +97,6 @@ jobs:
name: go_work
- run: go test ./...
working-directory: ${{ matrix.modules }}

golangci-lint-examples:
needs: [detect-modules, go-test-examples]
runs-on: ubuntu-latest
Expand Down
14 changes: 14 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ linters:
checks:
- all
- '-QF1008' # not need to fix; we understand how to call nested structs
revive:
rules:
- name: var-naming # waiting for package name will be fixed (incorrect naming)
severity: warning
disabled: false
exclude: [""]
arguments:
- ["ID"] # AllowList
- ["VM"] # DenyList
- - skip-initialism-name-checks: false
upper-case-const: false
skip-package-name-checks: true
skip-package-name-collision-with-go-std: false
extra-bad-package-names: []
exclusions:
generated: lax
presets:
Expand Down
121 changes: 96 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,8 @@
GO=$(shell which go)
GIT=$(shell which git)
GOLANGCI_LINT=$(shell which golangci-lint)

.PHONY: go-check
go-check:
$(call error-if-empty,$(GO),go)

.PHONY: git-check
git-check:
$(call error-if-empty,$(GIT),git)

.PHONY: golangci-lint-check
golangci-lint-check:
$(call error-if-empty,$(GIT),git)

.PHONY: go-module-version
go-module-version: go-check git-check
@echo "go get $(shell $(GO) list ./pkg/app)@$(shell $(GIT) rev-parse HEAD)"

.PHONY: test
test: go-check
@$(GO) test --race --cover ./...

.PHONY: lint
lint: golangci-lint-check
@$(GOLANGCI_LINT) run ./... --fix

.PHONY: examples
examples: go-check examples-mod examples-test examples-lint
@echo "Running examples tests and linting"
Expand All @@ -46,12 +23,106 @@ examples-test: go-check
done

.PHONY: examples-lint
examples-lint: golangci-lint-check
examples-lint: golangci-lint
@for dir in $$(find . -mindepth 2 -name go.mod | sed -r 's/(.*)(go.mod)/\1/g'); do \
echo "Running linter in $${dir}"; \
cd $(CURDIR)/$${dir} && $(GOLANGCI_LINT) run ./... --fix && cd $(CURDIR); \
done

.PHONY: lint
lint: golangci-lint ## Run linter.
@$(GOLANGCI_LINT) run --fix

.PHONY: test
test: go-check
@$(GO) test --race --cover ./...

## Run all generate-* jobs in bulk.
.PHONY: generate
generate: update-workflows-go-version update-workflows-golangci-lint-version


##@ Dependencies

WHOAMI ?= $(shell whoami)

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

## Tool Binaries
GO=$(shell which go)
GIT=$(shell which git)
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
YQ = $(LOCALBIN)/yq

## TODO: remap in yaml file (version.yaml or smthng)
## Tool Versions
# GO_BUILDER_VERSION must be without 'v' prefix
GO_BUILDER_VERSION = 1.25.5
GOLANGCI_LINT_VERSION = v2.8.0
YQ_VERSION ?= v4.50.1


.PHONY: update-workflows-go-version
update-workflows-go-version: yq
for file in $$(find .github/workflows -name "*.yaml" -o -name "*.yml"); do \
if grep -q "actions/setup-go" $$file; then \
$(YQ) -i '(.env.GO_VERSION) = "$(GO_BUILDER_VERSION)"' $$file; \
fi; \
done
echo "Updated go-version in workflow files to $(GO_BUILDER_VERSION)"

.PHONY: update-workflows-golangci-lint-version
update-workflows-golangci-lint-version: yq
for file in $$(find .github/workflows -name "*.yaml" -o -name "*.yml"); do \
if grep -q "golangci/golangci-lint-action" $$file; then \
$(YQ) -i '(.env.GOLANGCI_LINT_VERSION) = "$(GOLANGCI_LINT_VERSION)"' $$file; \
fi; \
done
echo "Updated golangci-lint version in workflow files to $(GOLANGCI_LINT_VERSION)"

## Installed tools check

.PHONY: go-check
go-check:
$(call error-if-empty,$(GO),go)

.PHONY: git-check
git-check:
$(call error-if-empty,$(GIT),git)

## Tool installations

.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/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))

.PHONY: yq
yq: $(YQ) ## Download yq locally if necessary.
$(YQ): $(LOCALBIN)
$(call go-install-tool,$(YQ),github.com/mikefarah/yq/v4,$(YQ_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
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f "$(1)-$(3)" ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
rm -f $(1) || true ;\
GOBIN=$(LOCALBIN) GOTOOLCHAIN=$(GO_TOOLCHAIN_AUTOINSTALL_VERSION) go install $${package} ;\
mv $(1) $(1)-$(3) ;\
} ;\
ln -sf $(1)-$(3) $(1)
endef


define error-if-empty
@if [[ -z $(1) ]]; then echo "$(2) not installed"; false; fi
endef
endef
35 changes: 17 additions & 18 deletions examples/basic-example-module/hooks/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module basic-example-module

go 1.24
go 1.24.0

require github.com/deckhouse/module-sdk v0.0.0

Expand All @@ -11,7 +11,7 @@ require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.16.3 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/deckhouse/deckhouse/pkg/log v0.0.0-20250814094423-e9f108b41a1a // indirect
github.com/deckhouse/deckhouse/pkg/log v0.1.0 // indirect
github.com/docker/cli v28.2.2+incompatible // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/docker-credential-helpers v0.9.3 // indirect
Expand All @@ -26,12 +26,10 @@ require (
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/gojuno/minimock/v3 v3.4.7 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/btree v1.1.3 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gnostic-models v0.6.9 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/go-containerregistry v0.20.6 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jonboulle/clockwork v0.4.0 // indirect
Expand All @@ -47,9 +45,9 @@ require (
github.com/opencontainers/image-spec v1.1.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.20.5 // indirect
github.com/prometheus/client_golang v1.22.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/common v0.62.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/cobra v1.9.1 // indirect
Expand All @@ -60,28 +58,29 @@ require (
github.com/tidwall/pretty v1.2.0 // indirect
github.com/vbatts/tar-split v0.12.1 // indirect
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/net v0.36.0 // indirect
golang.org/x/net v0.38.0 // indirect
golang.org/x/oauth2 v0.30.0 // indirect
golang.org/x/sync v0.16.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/term v0.29.0 // indirect
golang.org/x/text v0.22.0 // indirect
golang.org/x/time v0.8.0 // indirect
golang.org/x/term v0.30.0 // indirect
golang.org/x/text v0.23.0 // indirect
golang.org/x/time v0.9.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/protobuf v1.36.3 // indirect
google.golang.org/protobuf v1.36.5 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.32.10 // indirect
k8s.io/apiextensions-apiserver v0.32.10 // indirect
k8s.io/apimachinery v0.32.10 // indirect
k8s.io/client-go v0.32.10 // indirect
k8s.io/api v0.33.7 // indirect
k8s.io/apiextensions-apiserver v0.33.7 // indirect
k8s.io/apimachinery v0.33.7 // indirect
k8s.io/client-go v0.33.7 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
sigs.k8s.io/controller-runtime v0.20.4 // indirect
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
sigs.k8s.io/randfill v1.0.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

Expand Down
Loading