Skip to content

Commit 7acc183

Browse files
authored
Merge pull request #627 from meshery/fixed/wrongUseErr
Make the configuration of ci more simpler and fix the error
2 parents fe5258b + b444424 commit 7acc183

File tree

4 files changed

+74
-249
lines changed

4 files changed

+74
-249
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Default Meshery Istio Workflow
22
on:
33
push:
44
branches:
5-
- "*"
5+
- "master"
66
tags:
77
- "v*"
88
paths-ignore:
@@ -16,103 +16,16 @@ jobs:
1616
name: golangci-lint
1717
runs-on: ubuntu-22.04
1818
steps:
19-
- uses: actions/setup-go@v3
19+
- uses: actions/setup-go@v4
2020
with:
2121
go-version: 1.19
2222
- uses: actions/checkout@v3
2323
- name: golangci-lint
2424
uses: golangci/golangci-lint-action@v3
2525
with:
2626
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
27-
version: v1.49
28-
29-
# Optional: working directory, useful for monorepos
30-
# working-directory: somedir
31-
32-
# Optional: golangci-lint command line arguments.
33-
# args: --issues-exit-code=0
34-
35-
# Optional: show only new issues if it's a pull request. The default value is `false`.
36-
# only-new-issues: true
37-
error_check:
38-
name: Error check
39-
runs-on: ubuntu-22.04
40-
steps:
41-
- name: Check out code
42-
uses: actions/checkout@v3
43-
with:
44-
fetch-depth: 1
45-
- name: Setup Go
46-
uses: actions/setup-go@v3
47-
with:
48-
go-version: 1.19
49-
- run: GOPROXY=https://proxy.golang.org,direct GOSUMDB=off GO111MODULE=on go install github.com/kisielk/errcheck@latest; /home/runner/go/bin/errcheck -tags draft ./...
50-
error_code_check:
51-
name: Error code utility check
52-
runs-on: ubuntu-22.04
53-
steps:
54-
- name: Check out code
55-
uses: actions/checkout@v3
56-
with:
57-
fetch-depth: 1
58-
- name: Setup Go
59-
uses: actions/setup-go@v3
60-
with:
61-
go-version: 1.19
62-
- run: |
63-
errWillHave="level=error"
64-
GOPROXY=https://proxy.golang.org,direct GOSUMDB=off GO111MODULE=on go install github.com/layer5io/meshkit/cmd/errorutil;
65-
err=$(/home/runner/go/bin/errorutil -d . update --skip-dirs meshery -i ./helpers -o ./helpers);
66-
echo "ERR: $err";
67-
if [[ $err == *"$errWillHave"* ]];
68-
then
69-
echo "$err";
70-
return 1;
71-
fi
72-
73-
static_check:
74-
name: Static check
75-
runs-on: ubuntu-22.04
76-
steps:
77-
- name: Check out code
78-
uses: actions/checkout@v3
79-
with:
80-
fetch-depth: 1
81-
- name: Setup Go
82-
uses: actions/setup-go@v3
83-
with:
84-
go-version: 1.19
85-
- uses: dominikh/[email protected]
86-
with:
87-
install-go: false
88-
version: "2022.1"
89-
vet:
90-
name: Vet
91-
runs-on: ubuntu-22.04
92-
steps:
93-
- name: Check out code
94-
uses: actions/checkout@v3
95-
with:
96-
fetch-depth: 1
97-
- name: Setup Go
98-
uses: actions/setup-go@v3
99-
with:
100-
go-version: 1.19
101-
- run: GOPROXY=https://proxy.golang.org,direct GOSUMDB=off GO111MODULE=on go vet -tags draft ./...
102-
sec_check:
103-
name: Security check
104-
runs-on: ubuntu-22.04
105-
env:
106-
GO111MODULE: on
107-
steps:
108-
- name: Check out code
109-
uses: actions/checkout@v3
110-
with:
111-
fetch-depth: 1
112-
- name: Run Gosec Security Scanner
113-
uses: securego/gosec@master
114-
with:
115-
args: -exclude=G301,G304,G107,G101,G110,G204,G409,G305,G302 ./...
27+
version: latest
28+
args: --timeout=5m
11629
tests:
11730
# needs: [lint, error_check, static_check, vet, sec_check]
11831
name: Tests

.golangci.yml

Lines changed: 50 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,144 +1,63 @@
11
linters-settings:
2-
depguard:
3-
list-type: blacklist
4-
packages:
5-
# logging is allowed only by logutils.Log, logrus
6-
# is allowed to use only in logutils package
7-
- github.com/sirupsen/logrus
8-
packages-with-error-message:
9-
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
10-
dupl:
11-
threshold: 100
12-
exhaustive:
13-
default-signifies-exhaustive: false
14-
funlen:
15-
lines: 100
16-
statements: 50
172
gci:
18-
local-prefixes: github.com/golangci/golangci-lint
3+
enabled: true
4+
max-len: 120
5+
line-length: 120
196
goconst:
20-
min-len: 2
21-
min-occurrences: 2
7+
enabled: true
228
gocritic:
23-
enabled-tags:
24-
- diagnostic
25-
- experimental
26-
- opinionated
27-
- performance
28-
- style
29-
disabled-checks:
30-
- dupImport # https://github.com/go-critic/go-critic/issues/845
31-
- ifElseChain
32-
- octalLiteral
33-
- whyNoLint
34-
- wrapperFunc
35-
gocyclo:
36-
min-complexity: 15
37-
goimports:
38-
local-prefixes: github.com/golangci/golangci-lint
39-
golint:
40-
min-confidence: 0
41-
gomnd:
42-
settings:
43-
mnd:
44-
# don't include the "operation" and "assign"
45-
checks: argument,case,condition,return
46-
gosec:
47-
settings:
48-
exclude: -G204
9+
enabled: true
10+
disable:
11+
- parallelize
12+
- nesting
13+
- hugeParam
14+
- hugeStruct
15+
- nestParam
16+
- prealloc
4917
govet:
50-
check-shadowing: false
51-
settings:
52-
printf:
53-
funcs:
54-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
55-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
56-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
57-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
58-
lll:
59-
line-length: 950
60-
maligned:
61-
suggest-new: true
62-
misspell:
63-
locale: US
64-
nolintlint:
65-
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
66-
allow-unused: false # report any unused nolint directives
67-
require-explanation: false # don't require an explanation for nolint directives
68-
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
18+
enabled: true
19+
check-shadowing: true
20+
tests: true
21+
golint:
22+
enabled: true
23+
min-confidence: 0.8
24+
unused:
25+
enabled: true
26+
check-exported: true
27+
check-packages: true
28+
check-generated: true
29+
tests: true
30+
allow-unused-type-export: true
31+
cyclop:
32+
enabled: true
33+
average-strictness: 7
34+
scopelint:
35+
enabled: true
36+
tests: true
37+
6938

39+
# Configuration for golangci-lint that is suitable for a Kubernetes operator project built with Golang
7040
linters:
71-
# please, do not use `enable-all`: it's deprecated and will be removed soon.
72-
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
73-
# https://golangci-lint.run/usage/linters/
74-
disable-all: true
75-
enable:
76-
# TODO: consider continuously if more should be enabled.
77-
# Can also be useful to run with more strict settings before commit locally, i.e. to test for TODOs (godox)
78-
# - bodyclose
79-
# - deadcode
80-
- dogsled
81-
# - dupl
82-
- errcheck
83-
# - exhaustive
84-
# - funlen
85-
# - goconst
86-
# - gocritic
87-
# - gocyclo
88-
- gofmt
89-
- goimports
90-
# - golint
91-
- gomodguard
92-
- gosec
93-
# - gomnd
94-
# - goprintffuncname
95-
- gosimple
41+
enable-all: false
42+
disable-all: false
43+
linters:
44+
- gci
45+
- goconst
46+
- gocritic
9647
- govet
97-
- ineffassign
98-
# - interfacer
99-
- lll
100-
- misspell
101-
# - nakedret
102-
# - nolintlint
103-
# - rowserrcheck
104-
# - scopelint
105-
- staticcheck
106-
# - structcheck
107-
- stylecheck
108-
- typecheck
109-
# - unconvert
110-
# - unparam
48+
- golint
11149
- unused
112-
# - varcheck
113-
- whitespace
114-
- asciicheck
115-
# - gochecknoglobals
116-
# - gocognit
117-
# - godot
118-
# - godox
119-
# - goerr113
120-
# - maligned
121-
# - nestif
122-
# - prealloc
123-
# - testpackage
124-
# - wsl
125-
126-
issues:
127-
# Excluding configuration per-path, per-linter, per-text and per-source
50+
- cyclop
51+
- scopelint
12852
exclude-rules:
129-
- path: _test\.go
130-
linters:
131-
- gomnd
132-
133-
# https://github.com/go-critic/go-critic/issues/926
134-
- linters:
135-
- gocritic
136-
text: "unnecessaryDefer:"
53+
- testpackage
13754

13855
run:
56+
enable-cache: true
13957
skip-dirs:
140-
- test/testdata_etc
141-
- internal/cache
142-
- internal/renameio
143-
- internal/robustio
144-
timeout: 5m
58+
- vendor
59+
- bundle
60+
- config
61+
- hack
62+
- helpers
63+
- img

istio/install.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ func (istio *Istio) getExecutable(release, dirName string) (string, error) {
409409

410410
func tarxzf(location string, stream io.Reader) error {
411411
uncompressedStream, err := gzip.NewReader(stream)
412+
412413
if err != nil {
413414
return err
414415
}
@@ -429,34 +430,30 @@ func tarxzf(location string, stream io.Reader) error {
429430
switch header.Typeflag {
430431
case tar.TypeDir:
431432
// File traversal is required to store the extracted manifests at the right place
432-
// #nosec
433-
if err := os.MkdirAll(path.Join(location, header.Name), 0750); err != nil {
433+
if os.MkdirAll(path.Join(location, header.Name), 0750) != nil {
434434
return ErrTarXZF(err)
435435
}
436436
case tar.TypeReg:
437437
// File traversal is required to store the extracted manifests at the right place
438-
// #nosec
439-
outFile, err := os.Create(path.Join(location, header.Name))
440-
if err != nil {
441-
return ErrTarXZF(err)
438+
outFile, createFileErr := os.Create(path.Join(location, header.Name))
439+
if createFileErr != nil {
440+
return ErrTarXZF(createFileErr)
442441
}
443-
// Trust istioctl tar
444-
// #nosec
445-
if _, err := io.Copy(outFile, tarReader); err != nil {
446-
return ErrTarXZF(err)
442+
// Trust istioctl tar hence
443+
if _, copyErr := io.Copy(outFile, tarReader); copyErr != nil {
444+
return ErrTarXZF(copyErr)
447445
}
446+
448447
if err = outFile.Close(); err != nil {
449448
return ErrTarXZF(err)
450449
}
451450

452451
if header.FileInfo().Name() == "istioctl" {
453452
// istioctl binary needs to be executable
454-
// #nosec
455-
if err = os.Chmod(outFile.Name(), 0750); err != nil {
453+
if os.Chmod(outFile.Name(), 0750) != nil {
456454
return ErrMakingBinExecutable(err)
457455
}
458456
}
459-
460457
default:
461458
return ErrTarXZF(err)
462459
}
@@ -465,6 +462,7 @@ func tarxzf(location string, stream io.Reader) error {
465462
return nil
466463
}
467464

465+
// TODO: The defer function is the last change to close the file, if it fails, it will be left open. We should return this error rather than logging it
468466
func unzip(location string, zippedContent io.Reader) error {
469467
// Keep file in memory: Approx size ~ 50MB
470468
// TODO: Find a better approach
@@ -490,7 +488,6 @@ func unzip(location string, zippedContent io.Reader) error {
490488
}()
491489

492490
// need file traversal to place the extracted files at the right place, hence
493-
// #nosec
494491
extractedFilePath := path.Join(location, file.Name)
495492

496493
if file.FileInfo().IsDir() {
@@ -508,11 +505,8 @@ func unzip(location string, zippedContent io.Reader) error {
508505
if err != nil {
509506
return ErrUnzipFile(err)
510507
}
511-
512-
/* #nosec G307 */
513-
514508
defer func() {
515-
if err := outputFile.Close(); err != nil {
509+
if outputFile.Close() != nil {
516510
fmt.Println(err)
517511
}
518512
}()

0 commit comments

Comments
 (0)