Skip to content

Commit 746b8f7

Browse files
authored
Update golangci integration (#637)
* Update golangci integration * Fix newly discovered errcheck complaints * Increase timeout value
1 parent cbaa17d commit 746b8f7

13 files changed

Lines changed: 99 additions & 90 deletions

File tree

.github/workflows/golangci-lint.yml

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,19 @@ on:
77

88
permissions:
99
contents: read
10-
# Optional: allow read access to pull request. Use with `only-new-issues` option.
1110
pull-requests: read
1211

1312
jobs:
1413
golangci:
1514
name: lint
1615
runs-on: ubuntu-latest
1716
steps:
18-
- uses: actions/checkout@v4
19-
- uses: actions/setup-go@v5
17+
- uses: actions/checkout@v5
18+
- uses: actions/setup-go@v6
2019
with:
21-
go-version: '1.24'
22-
cache: false
20+
go-version: '1.25'
2321
- name: golangci-lint
24-
uses: golangci/golangci-lint-action@v6
22+
uses: golangci/golangci-lint-action@v8
2523
with:
26-
# Require: The version of golangci-lint to use.
27-
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
28-
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
29-
version: v1.64
30-
31-
# Optional: working directory, useful for monorepos
32-
# working-directory: somedir
33-
34-
# Optional: golangci-lint command line arguments.
35-
#
36-
# Note: By default, the `.golangci.yml` file should be at the root of the repository.
37-
# The location of the configuration file can be changed by using `--config=`
38-
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0
39-
40-
# Optional: show only new issues if it's a pull request. The default value is `false`.
41-
# only-new-issues: true
42-
43-
# Optional: if set to true, then all caching functionality will be completely disabled,
44-
# takes precedence over all other caching options.
45-
# skip-cache: true
46-
47-
# Optional: if set to true, then the action won't cache or restore ~/go/pkg.
48-
# skip-pkg-cache: true
49-
50-
# Optional: if set to true, then the action won't cache or restore ~/.cache/go-build.
51-
# skip-build-cache: true
52-
53-
# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
54-
# install-mode: "goinstall"
24+
version: v2.4
25+
args: --timeout 5m

.github/workflows/unit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: Setup Go
1515
uses: actions/setup-go@v4
1616
with:
17-
go-version: '1.24.x'
17+
go-version: '1.25.x'
1818
- name: Install dependencies
1919
run: go mod download
2020
- name: Test with the Go CLI

.golangci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1+
version: '2'
12
linters:
23
# Enable specific linter
34
# https://golangci-lint.run/usage/linters/#enabled-by-default
45
enable:
56
- staticcheck
67
- govet
7-
output:
8-
formats:
9-
- format: colored-line-number

cmd/backup/archive.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,11 @@ func getCompressionWriter(file *os.File, algo string, concurrency int) (io.Write
121121
}
122122
}
123123

124-
func writeTarball(path string, tarWriter *tar.Writer, prefix string) error {
124+
func writeTarball(path string, tarWriter *tar.Writer, prefix string) (returnErr error) {
125125
fileInfo, err := os.Lstat(path)
126126
if err != nil {
127-
return errwrap.Wrap(err, fmt.Sprintf("error getting file info for %s", path))
127+
returnErr = errwrap.Wrap(err, fmt.Sprintf("error getting file info for %s", path))
128+
return
128129
}
129130

130131
if fileInfo.Mode()&os.ModeSocket == os.ModeSocket {
@@ -135,19 +136,22 @@ func writeTarball(path string, tarWriter *tar.Writer, prefix string) error {
135136
if fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink {
136137
var err error
137138
if link, err = os.Readlink(path); err != nil {
138-
return errwrap.Wrap(err, fmt.Sprintf("error resolving symlink %s", path))
139+
returnErr = errwrap.Wrap(err, fmt.Sprintf("error resolving symlink %s", path))
140+
return
139141
}
140142
}
141143

142144
header, err := tar.FileInfoHeader(fileInfo, link)
143145
if err != nil {
144-
return errwrap.Wrap(err, "error getting file info header")
146+
returnErr = errwrap.Wrap(err, "error getting file info header")
147+
return
145148
}
146149
header.Name = strings.TrimPrefix(path, prefix)
147150

148151
err = tarWriter.WriteHeader(header)
149152
if err != nil {
150-
return errwrap.Wrap(err, "error writing file info header")
153+
returnErr = errwrap.Wrap(err, "error writing file info header")
154+
return
151155
}
152156

153157
if !fileInfo.Mode().IsRegular() {
@@ -156,13 +160,17 @@ func writeTarball(path string, tarWriter *tar.Writer, prefix string) error {
156160

157161
file, err := os.Open(path)
158162
if err != nil {
159-
return errwrap.Wrap(err, fmt.Sprintf("error opening %s", path))
163+
returnErr = errwrap.Wrap(err, fmt.Sprintf("error opening %s", path))
164+
return
160165
}
161-
defer file.Close()
166+
defer func() {
167+
returnErr = file.Close()
168+
}()
162169

163170
_, err = io.Copy(tarWriter, file)
164171
if err != nil {
165-
return errwrap.Wrap(err, fmt.Sprintf("error copying %s to tar writer", path))
172+
returnErr = errwrap.Wrap(err, fmt.Sprintf("error copying %s to tar writer", path))
173+
return
166174
}
167175

168176
return nil

cmd/backup/config_provider.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,13 @@ func source(path string) (map[string]string, error) {
153153
currentValue, currentOk := os.LookupEnv(key)
154154
defer func() {
155155
if currentOk {
156-
os.Setenv(key, currentValue)
156+
_ = os.Setenv(key, currentValue)
157157
return
158158
}
159-
os.Unsetenv(key)
159+
_ = os.Unsetenv(key)
160160
}()
161161
result[key] = value
162-
os.Setenv(key, value)
162+
_ = os.Setenv(key, value)
163163
}
164164
}
165165
return result, nil

cmd/backup/config_provider_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ func TestSource(t *testing.T) {
6060
},
6161
}
6262

63-
os.Setenv("QUX", "yyy")
64-
defer os.Unsetenv("QUX")
63+
_ = os.Setenv("QUX", "yyy")
64+
defer func() {
65+
_ = os.Unsetenv("QUX")
66+
}()
6567

6668
for _, test := range tests {
6769
t.Run(test.name, func(t *testing.T) {

cmd/backup/exec.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,12 @@ func (s *script) runLabeledCommands(label string) error {
177177
s.logger.Info(fmt.Sprintf("Running %s command %s for container %s", label, cmd, strings.TrimPrefix(c.Names[0], "/")))
178178
stdout, stderr, err := s.exec(c.ID, cmd, user)
179179
if s.c.ExecForwardOutput {
180-
os.Stderr.Write(stderr)
181-
os.Stdout.Write(stdout)
180+
if _, err := os.Stderr.Write(stderr); err != nil {
181+
return errwrap.Wrap(err, "error writing to stderr")
182+
}
183+
if _, err := os.Stdout.Write(stdout); err != nil {
184+
return errwrap.Wrap(err, "error writing to stdout")
185+
}
182186
}
183187
if err != nil {
184188
return errwrap.Wrap(err, "error executing command")

cmd/backup/stop_restart.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"time"
1414

1515
"github.com/docker/cli/cli/command/service/progress"
16-
"github.com/docker/docker/api/types/container"
1716
ctr "github.com/docker/docker/api/types/container"
1817
"github.com/docker/docker/api/types/filters"
1918
"github.com/docker/docker/api/types/swarm"
@@ -66,7 +65,7 @@ func awaitContainerCountForService(cli *client.Client, serviceID string, count i
6665
),
6766
)
6867
case <-poll.C:
69-
containers, err := cli.ContainerList(context.Background(), container.ListOptions{
68+
containers, err := cli.ContainerList(context.Background(), ctr.ListOptions{
7069
Filters: filters.NewArgs(filters.KeyValuePair{
7170
Key: "label",
7271
Value: fmt.Sprintf("com.docker.swarm.service.id=%s", serviceID),
@@ -124,11 +123,11 @@ func (s *script) stopContainersAndServices() (func() error, error) {
124123
labelValue,
125124
)
126125

127-
allContainers, err := s.cli.ContainerList(context.Background(), container.ListOptions{})
126+
allContainers, err := s.cli.ContainerList(context.Background(), ctr.ListOptions{})
128127
if err != nil {
129128
return noop, errwrap.Wrap(err, "error querying for containers")
130129
}
131-
containersToStop, err := s.cli.ContainerList(context.Background(), container.ListOptions{
130+
containersToStop, err := s.cli.ContainerList(context.Background(), ctr.ListOptions{
132131
Filters: filters.NewArgs(filters.KeyValuePair{
133132
Key: "label",
134133
Value: filterMatchLabel,
@@ -215,7 +214,7 @@ func (s *script) stopContainersAndServices() (func() error, error) {
215214
)
216215
}
217216

218-
var stoppedContainers []container.Summary
217+
var stoppedContainers []ctr.Summary
219218
var stopErrors []error
220219
for _, container := range containersToStop {
221220
if err := s.cli.ContainerStop(context.Background(), container.ID, ctr.StopOptions{}); err != nil {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/offen/docker-volume-backup
22

3-
go 1.24.0
3+
go 1.25
44

55
require (
66
filippo.io/age v1.2.1

internal/storage/dropbox/dropbox.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,32 @@ func (b *dropboxStorage) Name() string {
8787
}
8888

8989
// Copy copies the given file to the WebDav storage backend.
90-
func (b *dropboxStorage) Copy(file string) error {
90+
func (b *dropboxStorage) Copy(file string) (returnErr error) {
9191
_, name := path.Split(file)
9292

9393
folderArg := files.NewCreateFolderArg(b.DestinationPath)
9494
if _, err := b.client.CreateFolderV2(folderArg); err != nil {
9595
switch err := err.(type) {
9696
case files.CreateFolderV2APIError:
9797
if err.EndpointError.Path.Tag != files.WriteErrorConflict {
98-
return errwrap.Wrap(err, fmt.Sprintf("error creating directory '%s'", b.DestinationPath))
98+
returnErr = errwrap.Wrap(err, fmt.Sprintf("error creating directory '%s'", b.DestinationPath))
99+
return
99100
}
100101
b.Log(storage.LogLevelInfo, b.Name(), "Destination path '%s' already exists, no new directory required.", b.DestinationPath)
101102
default:
102-
return errwrap.Wrap(err, fmt.Sprintf("error creating directory '%s'", b.DestinationPath))
103+
returnErr = errwrap.Wrap(err, fmt.Sprintf("error creating directory '%s'", b.DestinationPath))
104+
return
103105
}
104106
}
105107

106108
r, err := os.Open(file)
107109
if err != nil {
108-
return errwrap.Wrap(err, "error opening the file to be uploaded")
110+
returnErr = errwrap.Wrap(err, "error opening the file to be uploaded")
111+
return
109112
}
110-
defer r.Close()
113+
defer func() {
114+
returnErr = r.Close()
115+
}()
111116

112117
// Start new upload session and get session id
113118
b.Log(storage.LogLevelInfo, b.Name(), "Starting upload session for backup '%s' at path '%s'.", file, b.DestinationPath)
@@ -116,7 +121,8 @@ func (b *dropboxStorage) Copy(file string) error {
116121
uploadSessionStartArg := files.NewUploadSessionStartArg()
117122
uploadSessionStartArg.SessionType = &files.UploadSessionType{Tagged: dropbox.Tagged{Tag: files.UploadSessionTypeConcurrent}}
118123
if res, err := b.client.UploadSessionStart(uploadSessionStartArg, nil); err != nil {
119-
return errwrap.Wrap(err, "error starting the upload session")
124+
returnErr = errwrap.Wrap(err, "error starting the upload session")
125+
return
120126
} else {
121127
sessionId = res.SessionId
122128
}
@@ -197,7 +203,8 @@ loop:
197203
files.NewCommitInfo(path.Join(b.DestinationPath, name)),
198204
), nil)
199205
if err != nil {
200-
return errwrap.Wrap(err, "error finishing the upload session")
206+
returnErr = errwrap.Wrap(err, "error finishing the upload session")
207+
return
201208
}
202209

203210
b.Log(storage.LogLevelInfo, b.Name(), "Uploaded a copy of backup '%s' at path '%s'.", file, b.DestinationPath)

0 commit comments

Comments
 (0)