Skip to content

Commit

Permalink
Add golangci-lint to CI and resolve warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Vazquez <[email protected]>
  • Loading branch information
austinvazquez committed Feb 22, 2023
1 parent 4a6d4d7 commit ebe8038
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 5 deletions.
27 changes: 25 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
push:
branches:
- master

env:
GO_VERSION: 1.20.x

jobs:
project:
name: Project Checks
Expand All @@ -13,7 +17,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.19.x
go-version: ${{ env.GO_VERSION }}
- uses: actions/checkout@v3
with:
path: src/github.com/containerd/fuse-overlayfs-snapshotter
Expand All @@ -22,6 +26,25 @@ jobs:
with:
working-directory: src/github.com/containerd/fuse-overlayfs-snapshotter

linters:
name: Linters
permissions:
contents: read # for actions/checkout to fetch code
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
runs-on: ubuntu-22.04
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
with:
path: src/github.com/containerd/fuse-overlayfs-snapshotter
- uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
- uses: golangci/golangci-lint-action@v3
with:
version: v1.51.1
working-directory: src/github.com/containerd/fuse-overlayfs-snapshotter

test:
runs-on: ubuntu-22.04
timeout-minutes: 30
Expand All @@ -41,6 +64,6 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.19.x
go-version: ${{ env.GO_VERSION }}
- uses: actions/checkout@v3
- run: make artifacts
5 changes: 4 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ on:
tags:
- 'v*'
- 'test-action-release-*'

env:
GO111MODULE: on
GO_VERSION: 1.20.x

jobs:
release:
runs-on: ubuntu-22.04
timeout-minutes: 20
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.19.x
go-version: ${{ env.GO_VERSION }}
- uses: actions/checkout@v3
with:
path: go/src/github.com/containerd/fuse-overlayfs-snapshotter
Expand Down
26 changes: 26 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
linters:
enable:
- depguard
- exportloopref
- gofmt
- gosec
- ineffassign
- misspell
- nolintlint
- revive
- staticcheck
- tenv
- unconvert
- unused
- vet
disable:
- errcheck

linters-settings:
depguard:
list-type: denylist
include-go-root: true
packages:
# use "io" or "os" instead
# https://go.dev/doc/go1.16#ioutil
- io/ioutil
15 changes: 13 additions & 2 deletions fuseoverlayfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ func (o *snapshotter) Stat(ctx context.Context, key string) (snapshots.Info, err
if err != nil {
return snapshots.Info{}, err
}
defer t.Rollback()
defer func() {
if err := t.Rollback(); err != nil {
logger := log.G(ctx)
logger.Errorf("Error on transaction rollback: %v", err)
}
}()
_, info, _, err := storage.GetInfo(ctx, key)
if err != nil {
return snapshots.Info{}, err
Expand All @@ -120,7 +125,10 @@ func (o *snapshotter) Update(ctx context.Context, info snapshots.Info, fieldpath

info, err = storage.UpdateInfo(ctx, info, fieldpaths...)
if err != nil {
t.Rollback()
rollbackErr := t.Rollback()
if rollbackErr != nil {
return snapshots.Info{}, fmt.Errorf("%w: error on rollback: %w", err, rollbackErr)
}
return snapshots.Info{}, err
}

Expand Down Expand Up @@ -182,6 +190,9 @@ func (o *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, er
return nil, err
}
s, err := storage.GetSnapshot(ctx, key)
if err != nil {
return nil, fmt.Errorf("failed to get snapshot %s from storage: %w", key, err)
}
_, info, _, err := storage.GetInfo(ctx, key)
t.Rollback()
if err != nil {
Expand Down

0 comments on commit ebe8038

Please sign in to comment.