Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: move golang lint to makefile from ci after bump go1.23 #142

Closed
13 tasks done
whg517 opened this issue Sep 2, 2024 · 1 comment
Closed
13 tasks done

[Feature]: move golang lint to makefile from ci after bump go1.23 #142

whg517 opened this issue Sep 2, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request tracking list The issue contains a task list to tracking

Comments

@whg517
Copy link
Member

whg517 commented Sep 2, 2024

Duplicates

I have searched the existing issues

Summary 💡

trace:

Examples 🌈

updated ci lint:

--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -23,47 +23,17 @@ jobs:
 
 
   golang-lint:
-    name: Golang Lint
-    runs-on: ubuntu-22.04
+    name: golang-lint
+    runs-on: ubuntu-latest
     steps:
-    - uses: actions/checkout@v3
-    - uses: actions/setup-go@v4
-      with:
-        go-version: '1.22'
-        cache: false
-    - name: golangci-lint
-      uses: golangci/golangci-lint-action@v3
-      with:
-        # Require: The version of golangci-lint to use.
-        # When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
-        # When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
-        version: v1.54
-
-        # Optional: working directory, useful for monorepos
-        # working-directory: somedir
-
-        # Optional: golangci-lint command line arguments.
-        #
-        # Note: By default, the `.golangci.yml` file should be at the root of the repository.
-        # The location of the configuration file can be changed by using `--config=`
-        # args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0
-        args: --timeout=30m
-
-        # Optional: show only new issues if it's a pull request. The default value is `false`.
-        # only-new-issues: true
-
-        # Optional: if set to true, then all caching functionality will be completely disabled,
-        #           takes precedence over all other caching options.
-        # skip-cache: true
-
-        # Optional: if set to true, then the action won't cache or restore ~/go/pkg.
-        # skip-pkg-cache: true
-
-        # Optional: if set to true, then the action won't cache or restore ~/.cache/go-build.
-        # skip-build-cache: true
-
-        # Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
-        # install-mode: "goinstall"
+      - uses: actions/checkout@v3
+      - uses: actions/setup-go@v4
+        with:
+          go-version: '1.23'
+          cache: false
+      - name: golangci-lint
+        run: |
+          make lint

updated makefile

--- a/Makefile
+++ b/Makefile
@@ -119,6 +119,23 @@ fmt: ## Run go fmt against code.
 vet: ## Run go vet against code.
        go vet ./...
 
+
+GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
+GOLANGCI_LINT_VERSION ?= v1.60.3
+golangci-lint:
+       @[ -f $(GOLANGCI_LINT) ] || { \
+       set -e ;\
+       curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) $(GOLANGCI_LINT_VERSION) ;\
+       }
+
+.PHONY: lint
+lint: golangci-lint ## Run golangci-lint linter & yamllint
+       $(GOLANGCI_LINT) run --timeout 5m
+
+.PHONY: lint-fix
+lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
+       $(GOLANGCI_LINT) run --fix
+
 .PHONY: test
 test: manifests generate fmt vet envtest ## Run tests.
        KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
@@ -126,7 +143,7 @@ test: manifests generate fmt vet envtest ## Run tests.
 ##@ Build
 
 .PHONY: build
-build: manifests generate fmt vet ## Build manager binary.
+build: manifests generate fmt vet lint ## Build manager binary.
        go build -o bin/manager cmd/main.go
 
 .PHONY: run

Motivation 🔦

No response

@whg517 whg517 added the enhancement New feature or request label Sep 2, 2024
@whg517 whg517 added the tracking list The issue contains a task list to tracking label Sep 2, 2024
@whg517
Copy link
Member Author

whg517 commented Sep 2, 2024

if get an error when generate manifest, make sure controller-gen version above v0.1.6.2

@whg517 whg517 closed this as completed Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request tracking list The issue contains a task list to tracking
Projects
None yet
Development

No branches or pull requests

2 participants