Skip to content

Commit 9582eb6

Browse files
committed
lint gha job
Signed-off-by: CrazyMax <[email protected]>
1 parent 5302241 commit 9582eb6

File tree

7 files changed

+79
-42
lines changed

7 files changed

+79
-42
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111

1212
env:
1313
DESTDIR: ./bin
14-
GO_VERSION: 1.16.7
14+
GO_VERSION: 1.18.5
1515

1616
jobs:
1717
validate:
@@ -20,6 +20,7 @@ jobs:
2020
fail-fast: false
2121
matrix:
2222
target:
23+
- lint
2324
- validate-vendor
2425
steps:
2526
-

.golangci.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
run:
2+
timeout: 10m
3+
modules-download-mode: vendor
4+
5+
linters:
6+
enable:
7+
- gofmt
8+
- govet
9+
- deadcode
10+
- depguard
11+
- goimports
12+
- ineffassign
13+
- misspell
14+
- unused
15+
- varcheck
16+
- revive
17+
- staticcheck
18+
- typecheck
19+
- structcheck
20+
disable-all: true
21+
22+
linters-settings:
23+
depguard:
24+
list-type: blacklist
25+
include-go-root: true
26+
packages:
27+
# The io/ioutil package has been deprecated.
28+
# https://go.dev/doc/go1.16#ioutil
29+
- io/ioutil
30+
31+
issues:
32+
exclude-rules:
33+
- linters:
34+
- revive
35+
text: "stutters"

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
ARG GO_VERSION=1.18.5
44
ARG XX_VERSION=1.1.2
55
ARG OSXCROSS_VERSION=11.3-r7-alpine
6+
ARG GOLANGCI_LINT_VERSION=v1.47.3
67

78
ARG PKG=github.com/docker/docker-credential-helpers
89

@@ -48,6 +49,14 @@ RUN --mount=type=bind,target=.,rw <<EOT
4849
fi
4950
EOT
5051

52+
FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint
53+
FROM gobase AS lint
54+
RUN apk add musl-dev gcc libsecret-dev pass
55+
RUN --mount=type=bind,target=. \
56+
--mount=type=cache,target=/root/.cache \
57+
--mount=from=golangci-lint,source=/usr/bin/golangci-lint,target=/usr/bin/golangci-lint \
58+
golangci-lint run ./...
59+
5160
FROM gobase AS version
5261
ARG PKG
5362
RUN --mount=target=. \

Makefile

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
.PHONY: all deps osxkeychain secretservice test validate wincred pass deb
1+
.PHONY: all osxkeychain secretservice test lint validate-vendor fmt validate wincred pass deb vendor
22

3-
TRAVIS_OS_NAME ?= linux
43
VERSION := $(shell grep 'const Version' credentials/version.go | awk -F'"' '{ print $$2 }')
54

65
all: test
76

8-
deps:
9-
go get -u golang.org/x/lint/golint
10-
117
clean:
128
rm -rf bin
139
rm -rf release
@@ -50,28 +46,16 @@ test:
5046
# tests all packages except vendor
5147
go test -v `go list ./... | grep -v /vendor/`
5248

53-
vet: vet_$(TRAVIS_OS_NAME)
54-
go vet ./credentials
55-
56-
vet_win:
57-
go vet ./wincred
58-
59-
vet_osx:
60-
go vet ./osxkeychain
61-
62-
vet_linux:
63-
go vet ./secretservice
64-
6549
lint:
66-
for p in `go list ./... | grep -v /vendor/`; do \
67-
golint $$p ; \
68-
done
50+
docker buildx bake lint
51+
52+
validate-vendor:
53+
docker buildx bake vendor-validate
6954

7055
fmt:
7156
gofmt -s -l `ls **/*.go | grep -v vendor`
7257

73-
validate: vet lint fmt
74-
58+
validate: lint validate-vendor fmt
7559

7660
BUILDIMG:=docker-credential-secretservice-$(VERSION)
7761
deb:
@@ -84,14 +68,9 @@ deb:
8468
docker run --rm --net=none $(BUILDIMG) tar cf - /release | tar xf -
8569
docker rmi $(BUILDIMG)
8670

87-
.PHONY: vendor
8871
vendor:
8972
$(eval $@_TMP_OUT := $(shell mktemp -d -t docker-output.XXXXXXXXXX))
9073
docker buildx bake --set "*.output=type=local,dest=$($@_TMP_OUT)" vendor
9174
rm -rf ./vendor
9275
cp -R "$($@_TMP_OUT)"/* .
9376
rm -rf "$($@_TMP_OUT)"
94-
95-
.PHONY: validate-vendor
96-
validate-vendor:
97-
docker buildx bake vendor-validate

client/client_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/json"
55
"fmt"
66
"io"
7-
"io/ioutil"
87
"strings"
98
"testing"
109

@@ -32,7 +31,7 @@ type mockProgram struct {
3231
// Output returns responses from the remote credentials helper.
3332
// It mocks those responses based in the input in the mock.
3433
func (m *mockProgram) Output() ([]byte, error) {
35-
in, err := ioutil.ReadAll(m.input)
34+
in, err := io.ReadAll(m.input)
3635
if err != nil {
3736
return nil, err
3837
}
@@ -108,8 +107,8 @@ func ExampleStore() {
108107

109108
func TestStore(t *testing.T) {
110109
valid := []credentials.Credentials{
111-
{validServerAddress, "foo", "bar"},
112-
{validServerAddress2, "<token>", "abcd1234"},
110+
{ServerURL: validServerAddress, Username: "foo", Secret: "bar"},
111+
{ServerURL: validServerAddress2, Username: "<token>", Secret: "abcd1234"},
113112
}
114113

115114
for _, v := range valid {
@@ -119,7 +118,7 @@ func TestStore(t *testing.T) {
119118
}
120119

121120
invalid := []credentials.Credentials{
122-
{invalidServerAddress, "foo", "bar"},
121+
{ServerURL: invalidServerAddress, Username: "foo", Secret: "bar"},
123122
}
124123

125124
for _, v := range invalid {
@@ -142,8 +141,8 @@ func ExampleGet() {
142141

143142
func TestGet(t *testing.T) {
144143
valid := []credentials.Credentials{
145-
{validServerAddress, "foo", "bar"},
146-
{validServerAddress2, "<token>", "abcd1234"},
144+
{ServerURL: validServerAddress, Username: "foo", Secret: "bar"},
145+
{ServerURL: validServerAddress2, Username: "<token>", Secret: "abcd1234"},
147146
}
148147

149148
for _, v := range valid {

docker-bake.hcl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,23 @@ group "default" {
2222
}
2323

2424
group "validate" {
25-
targets = ["vendor-validate"]
25+
targets = ["lint", "vendor-validate"]
26+
}
27+
28+
target "lint" {
29+
inherits = ["_common"]
30+
target = "lint"
31+
output = ["type=cacheonly"]
2632
}
2733

2834
target "vendor-validate" {
35+
inherits = ["_common"]
2936
target = "vendor-validate"
3037
output = ["type=cacheonly"]
3138
}
3239

3340
target "vendor" {
41+
inherits = ["_common"]
3442
target = "vendor-update"
3543
output = ["."]
3644
}

pass/pass.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"encoding/base64"
1010
"errors"
1111
"fmt"
12-
"io/ioutil"
12+
"io/fs"
1313
"os"
1414
"os/exec"
1515
"path"
@@ -20,7 +20,7 @@ import (
2020
)
2121

2222
// PASS_FOLDER contains the directory where credentials are stored
23-
const PASS_FOLDER = "docker-credential-helpers" //nolint: golint
23+
const PASS_FOLDER = "docker-credential-helpers" //nolint:revive
2424

2525
// Pass handles secrets using Linux secret-service as a store.
2626
type Pass struct{}
@@ -116,16 +116,22 @@ func getPassDir() string {
116116
func listPassDir(args ...string) ([]os.FileInfo, error) {
117117
passDir := getPassDir()
118118
p := path.Join(append([]string{passDir, PASS_FOLDER}, args...)...)
119-
contents, err := ioutil.ReadDir(p)
119+
entries, err := os.ReadDir(p)
120120
if err != nil {
121121
if os.IsNotExist(err) {
122122
return []os.FileInfo{}, nil
123123
}
124-
125124
return nil, err
126125
}
127-
128-
return contents, nil
126+
infos := make([]fs.FileInfo, 0, len(entries))
127+
for _, entry := range entries {
128+
info, err := entry.Info()
129+
if err != nil {
130+
return nil, err
131+
}
132+
infos = append(infos, info)
133+
}
134+
return infos, nil
129135
}
130136

131137
// Get returns the username and secret to use for a given registry server URL.

0 commit comments

Comments
 (0)