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

Fix issues reported by golangci #623

Merged
Merged
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
58 changes: 58 additions & 0 deletions .github/workflows/run-go-linter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Run go linter

on:
pull_request:
branches: [ main ]
types:
- opened
- reopened
- synchronize
- ready_for_review

jobs:
run-go-linter:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Get changed files
id: changed-files-specific
uses: tj-actions/changed-files@90a06d6ba9543371ab4df8eeca0be07ca6054959
with:
files: |
.github/**
api/**
cmd/**
config/**
controllers/**
deployments/**
examples/**
hack/**
internal/**
module-chart/**
module-resources/**
scripts/**
config.yaml
Dockerfile
go.mod
go.sum
main.go
Makefile
**/*.go
**/*.sh

- name: Set up go environment
if: steps.changed-files-specific.outputs.any_modified == 'true'
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'

- name: Go linter
if: steps.changed-files-specific.outputs.any_modified == 'true'
uses: golangci/golangci-lint-action@v3
with:
version: v1.55.2
skip-cache: true
only-new-issues: true
args: --timeout 2m0s
13 changes: 13 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
run:
allow-parallel-runners: true
output:
format: "colored-tab:stderr,github-actions:stdout"
print-issued-lines: true
print-linter-name: true
uniq-by-line: false
linters:
disable-all: true
enable:
- errcheck
- goimports
- govet
24 changes: 17 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ endif
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

GOLINT_VER = v1.55.2

.PHONY: all
all: build

Expand Down Expand Up @@ -179,10 +181,18 @@ fmt: ## Run go fmt against code.
vet: ## Run go vet against code.
go vet ./...

GOLANG_CI_LINT = $(LOCALBIN)/golangci-lint
GOLANG_CI_LINT_VERSION ?= v1.50.1
.PHONY: lint
lint: ## Download & Build & Run golangci-lint against code.
GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANG_CI_LINT_VERSION)
$(LOCALBIN)/golangci-lint run

go-lint-install: ## linter config in file at root of project -> '.golangci.yaml'
@if [ "$(shell command golangci-lint version --format short)" != "$(GOLINT_VER)" ]; then \
echo golangci in version $(GOLINT_VER) not found. will be downloaded; \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLINT_VER); \
echo golangci installed with version: $(shell command golangci-lint version --format short); \
fi;

.PHONY: go-lint
go-lint: go-lint-install ## linter config in file at root of project -> '.golangci.yaml'
golangci-lint run

.PHONY: fix
fix: go-lint-install ## try to fix automatically issues
go mod tidy
golangci-lint run --fix
9 changes: 5 additions & 4 deletions controllers/btpoperator_controller_updating_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ package controllers

import (
"fmt"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"os"
"time"

"github.com/kyma-project/btp-manager/api/v1alpha1"
"github.com/kyma-project/btp-manager/internal/manifest"
"github.com/kyma-project/btp-manager/internal/ymlutils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
apimachienerytypes "k8s.io/apimachinery/pkg/types"
controllerruntime "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/kyma-project/btp-manager/api/v1alpha1"
"github.com/kyma-project/btp-manager/internal/manifest"
"github.com/kyma-project/btp-manager/internal/ymlutils"
)

const (
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"flag"
"os"

//test

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
Expand Down
Loading