Skip to content

Commit ac3801e

Browse files
rchincharchamarthy
authored andcommitted
lint: upgrade golangci-lint
Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
1 parent 5f04092 commit ac3801e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+3038
-2575
lines changed

.github/workflows/ci-cd.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
services:
1717
s3mock:
18-
image: localstack/localstack-full
18+
image: ghcr.io/project-zot/localstack/localstack:0.13.2
1919
env:
2020
SERVICES: s3
2121
ports:

.github/workflows/golangci-lint.yaml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
tags:
5+
- v*
6+
branches:
7+
- master
8+
- main
9+
pull_request:
10+
permissions:
11+
contents: read
12+
# Optional: allow read access to pull request. Use with `only-new-issues` option.
13+
# pull-requests: read
14+
jobs:
15+
golangci:
16+
name: lint
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v2
20+
- name: golangci-lint
21+
uses: golangci/golangci-lint-action@v2
22+
with:
23+
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
24+
version: v1.43.0
25+
26+
# Optional: working directory, useful for monorepos
27+
# working-directory: somedir
28+
29+
# Optional: golangci-lint command line arguments.
30+
# args: --issues-exit-code=0
31+
args: --config ./golangcilint.yaml --enable-all --build-tags extended,containers_image_openpgp ./cmd/... ./pkg/...
32+
33+
# Optional: show only new issues if it's a pull request. The default value is `false`.
34+
# only-new-issues: true
35+
36+
# Optional: if set to true then the action will use pre-installed Go.
37+
# skip-go-installation: true
38+
39+
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
40+
# skip-pkg-cache: true
41+
42+
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
43+
# skip-build-cache: true

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ---
22
# Stage 1: Install certs, build binary, create default config file
33
# ---
4-
FROM docker.io/golang:1.16 AS builder
4+
FROM ghcr.io/project-zot/golang:1.16 AS builder
55
ARG COMMIT
66
RUN mkdir -p /go/src/github.com/project-zot/zot
77
WORKDIR /go/src/github.com/project-zot/zot

Dockerfile-arch

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ---
22
# Stage 1: Install certs, build binary, create default config file
33
# ---
4-
FROM docker.io/golang:1.16 AS builder
4+
FROM ghcr.io/project-zot/golang:1.16 AS builder
55
ARG COMMIT
66
ARG ARCH
77
RUN mkdir -p /go/src/github.com/project-zot/zot

Dockerfile-arch-minimal

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ---
22
# Stage 1: Install certs, build binary, create default config file
33
# ---
4-
FROM docker.io/golang:1.16 AS builder
4+
FROM ghcr.io/project-zot/golang:1.16 AS builder
55
ARG COMMIT
66
ARG ARCH
77
RUN mkdir -p /go/src/github.com/project-zot/zot

Dockerfile-conformance

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# ---
22
# Stage 1: Install certs, build binary, create default config file
33
# ---
4-
FROM docker.io/golang:1.16-alpine AS builder
4+
FROM ghcr.io/project-zot/golang:1.16 AS builder
55
ARG COMMIT
6-
RUN apk --update add git make ca-certificates
6+
RUN apt-get update && apt-get install -y git make ca-certificates
77
RUN mkdir -p /go/src/github.com/project-zot/zot
88
WORKDIR /go/src/github.com/project-zot/zot
99
COPY . .
1010
RUN make COMMIT=$COMMIT clean binary
11-
RUN echo -e '# Default config file for zot server\n\
11+
RUN echo '# Default config file for zot server\n\
1212
http:\n\
1313
address: 0.0.0.0\n\
1414
port: 5000\n\

Dockerfile-minimal

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ---
22
# Stage 1: Install certs, build binary, create default config file
33
# ---
4-
FROM docker.io/golang:1.16 AS builder
4+
FROM ghcr.io/project-zot/golang:1.16 AS builder
55
ARG COMMIT
66
RUN mkdir -p /go/src/github.com/project-zot/zot
77
WORKDIR /go/src/github.com/project-zot/zot

Makefile

+12-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ COMMIT_HASH=$(shell git describe --always --tags --long)
44
GO_VERSION=$(shell go version | awk '{print $$3}')
55
COMMIT ?= $(if $(shell git status --porcelain --untracked-files=no),$(COMMIT_HASH)-dirty,$(COMMIT_HASH))
66
CONTAINER_RUNTIME := $(shell command -v podman 2> /dev/null || echo docker)
7-
PATH := bin:$(PATH)
87
TMPDIR := $(shell mktemp -d)
8+
TOOLSDIR := hack/tools
9+
PATH := bin:$(TOOLSDIR)/bin:$(PATH)
910
STACKER := $(shell which stacker)
11+
GOLINTER := $(TOOLSDIR)/bin/golangci-lint
1012
OS ?= linux
1113
ARCH ?= amd64
1214

@@ -55,11 +57,15 @@ covhtml:
5557
cat coverage-extended.txt coverage-minimal.txt > coverage.txt
5658
go tool cover -html=coverage.txt -o coverage.html
5759

60+
$(GOLINTER):
61+
mkdir -p $(TOOLSDIR)/bin
62+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(TOOLSDIR)/bin v1.43.0
63+
$(GOLINTER) version
64+
5865
.PHONY: check
59-
check: ./golangcilint.yaml
60-
golangci-lint --version || curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.26.0
61-
golangci-lint --config ./golangcilint.yaml run --enable-all --build-tags extended,containers_image_openpgp ./...
62-
golangci-lint --config ./golangcilint.yaml run --enable-all --build-tags minimal,containers_image_openpgp ./...
66+
check: ./golangcilint.yaml $(GOLINTER)
67+
$(GOLINTER) --config ./golangcilint.yaml run --enable-all --out-format=colored-line-number --build-tags minimal,containers_image_openpgp ./...
68+
$(GOLINTER) --config ./golangcilint.yaml run --enable-all --out-format=colored-line-number --build-tags extended,containers_image_openpgp ./...
6369

6470
swagger/docs.go:
6571
swag -v || go install github.com/swaggo/swag/cmd/swag
@@ -76,6 +82,7 @@ update-licenses:
7682
.PHONY: clean
7783
clean:
7884
rm -f bin/zot*
85+
rm -rf hack
7986

8087
.PHONY: run
8188
run: binary test

errors/errors.go

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var (
2727
ErrCacheMiss = errors.New("cache: miss")
2828
ErrRequireCred = errors.New("ldap: bind credentials required")
2929
ErrInvalidCred = errors.New("ldap: invalid credentials")
30+
ErrEmptyJSON = errors.New("cli: config json is empty")
3031
ErrInvalidArgs = errors.New("cli: Invalid Arguments")
3132
ErrInvalidFlagsCombination = errors.New("cli: Invalid combination of flags")
3233
ErrInvalidURL = errors.New("cli: invalid URL format")
@@ -45,4 +46,5 @@ var (
4546
ErrInvalidRepositoryName = errors.New("routes: not a repository name")
4647
ErrSyncMissingCatalog = errors.New("sync: couldn't fetch upstream registry's catalog")
4748
ErrMethodNotSupported = errors.New("storage: method not supported")
49+
ErrInvalidMetric = errors.New("metrics: invalid metric func")
4850
)

golangcilint.yaml

+24-6
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,33 @@ run:
55

66
linters:
77
enable-all: true
8-
disable: funlen,godox,gocognit
9-
10-
output:
11-
format: colored-line-number
8+
disable: funlen,gocognit,exhaustivestruct,paralleltest,forbidigo,ireturn,wrapcheck,exhaustive
129

1310
linters-settings:
1411
dupl:
15-
# tokens count to trigger issue, 150 by default
1612
threshold: 200
1713
nestif:
18-
# their are various nested if else, therefore specifying complexity as 26
1914
min-complexity: 26
15+
cyclop:
16+
max-complexity: 40
17+
skip-tests: true
18+
varnamelen:
19+
check-return: true
20+
ignore-type-assert-ok: true
21+
ignore-map-index-ok: true
22+
ignore-chan-recv-ok: true
23+
ignore-names:
24+
- err
25+
- ok
26+
- gc
27+
gomnd:
28+
settings:
29+
mnd:
30+
checks: argument,case,condition,operation,return,assign
31+
ignored-numbers: 10,64
32+
gomoddirectives:
33+
replace-allow-list:
34+
- github.com/aquasecurity/fanal
35+
- github.com/aquasecurity/trivy
36+
- github.com/aquasecurity/trivy-db
37+
- github.com/containers/image/v5

0 commit comments

Comments
 (0)