Skip to content

Commit

Permalink
refactor: configure golangci-lint and upgrade github actions (yonahd#246
Browse files Browse the repository at this point in the history
)

* refactor: configure golangci-lint and upgrade github actions

* fix: golangci-lint timeout issue
  • Loading branch information
cecobask authored Apr 30, 2024
1 parent 6ee101a commit 8adabd8
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 33 deletions.
27 changes: 11 additions & 16 deletions .github/workflows/merge-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,27 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

- name: Install dependencies
run: go get .

- name: Vet
run: go vet ./...

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4
with:
version: latest
skip-pkg-cache: true
skip-cache: true

- name: Build
run: go build -v ./...
run: make build

- name: Test
run: go test -v ./... -coverprofile=coverage.txt
run: make test

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage reports
uses: codecov/codecov-action@v4
with:
files: coverage.txt
token: ${{ secrets.CODECOV_TOKEN }}
15 changes: 7 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

- name: Install goreleaser
run: go install github.com/goreleaser/goreleaser@latest

- name: Run goreleaser
run: |
goreleaser release
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: "${{ secrets.RELEASE_GITHUB_TOKEN }}"
GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
.idea/
dist/**
main.exe
coverage.txt
coverage.txt
build/
18 changes: 18 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
run:
timeout: 5m
linters:
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused
- gci
linters-settings:
gci:
sections:
- standard
- default
- prefix(github.com/yonahd/kor)
custom-order: true
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.PHONY: *

build:
go build -o build/kor main.go

lint:
golangci-lint run

lint-fix:
golangci-lint run --fix

test:
go test -race -coverprofile=coverage.txt -shuffle on ./...
1 change: 1 addition & 0 deletions cmd/kor/clusterroles.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/spf13/cobra"

"github.com/yonahd/kor/pkg/kor"
"github.com/yonahd/kor/pkg/utils"
)
Expand Down
6 changes: 3 additions & 3 deletions pkg/kor/clusterroles.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"os"
"strconv"

"github.com/yonahd/kor/pkg/filters"
v1 "k8s.io/api/rbac/v1"
"k8s.io/utils/strings/slices"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
"k8s.io/utils/strings/slices"

"github.com/yonahd/kor/pkg/filters"
)

func retrieveUsedClusterRoles(clientset kubernetes.Interface, filterOpts *filters.Options) ([]string, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/kor/clusterroles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
"sort"
"testing"

"github.com/yonahd/kor/pkg/filters"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/kubernetes/scheme"

"github.com/yonahd/kor/pkg/filters"
)

func createTestClusterRoles(t *testing.T) *fake.Clientset {
Expand Down
3 changes: 1 addition & 2 deletions pkg/kor/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import (
"reflect"
"strings"

batchv1 "k8s.io/api/batch/v1"

appsv1 "k8s.io/api/apps/v1"
autoscalingv1 "k8s.io/api/autoscaling/v1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
policyv1beta1 "k8s.io/api/policy/v1beta1"
Expand Down
1 change: 0 additions & 1 deletion pkg/kor/pods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"

fake "k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/kubernetes/scheme"

Expand Down

0 comments on commit 8adabd8

Please sign in to comment.