Skip to content

Commit a0efb02

Browse files
Adding staticcheck to the CI
This commit adds static check to our CI and fixes all of its complaints.
1 parent c54db6a commit a0efb02

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

.github/workflows/pullrequest.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ jobs:
2727
- name: run linter
2828
run: golint -set_exit_status ./cmd/kubectl-image ./cmd/imgctrl ./controllers/... ./services/...
2929

30+
staticcheck:
31+
name: staticcheck
32+
runs-on: ubuntu-latest
33+
container:
34+
image: quay.io/tagger/actions-image:latest
35+
steps:
36+
- name: check out code
37+
uses: actions/checkout@v2
38+
with:
39+
repository: ${{ github.event.pull_request.head.repo.full_name }}
40+
ref: ${{ github.event.pull_request.head.ref }}
41+
42+
- name: run staticcheck
43+
run: staticcheck ./...
44+
3045
unit:
3146
name: unit
3247
runs-on: ubuntu-latest
@@ -47,6 +62,7 @@ jobs:
4762
needs:
4863
- lint
4964
- unit
65+
- staticcheck
5066
runs-on: ubuntu-latest
5167
container:
5268
image: quay.io/tagger/actions-image:latest
@@ -65,6 +81,7 @@ jobs:
6581
needs:
6682
- lint
6783
- unit
84+
- staticcheck
6885
runs-on: ubuntu-latest
6986
steps:
7087
- name: check out code

infra/images/v1beta1/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,14 @@ func (t *ImageImport) FlaggedAsConsumedDuration() (time.Duration, error) {
151151
}
152152

153153
strsince := t.Annotations[ImageImportConsumedFlagAnnotation]
154-
since, err := time.Parse(time.ANSIC, strsince)
154+
flagtime, err := time.Parse(time.ANSIC, strsince)
155155
if err != nil {
156156
return 0, fmt.Errorf(
157157
"bogus %s annotation: %w", ImageImportConsumedFlagAnnotation, err,
158158
)
159159
}
160160

161-
return time.Now().Sub(since), nil
161+
return time.Since(flagtime), nil
162162
}
163163

164164
// CurrentReferenceForImage looks through provided Image and returns the most recent imported

services/imageimport.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ func (t *ImageImport) Import(
301301
return nil, fmt.Errorf("fail to mirror image: %w", err)
302302
}
303303

304-
latency := time.Now().Sub(start).Seconds()
304+
latency := time.Since(start).Seconds()
305305
metrics.MirrorLatency.Observe(latency)
306306
}
307307

services/imageio.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (t *ImageIO) Push(ctx context.Context, ns, name string, fpath string) error
7070
metrics.PushFailures.Inc()
7171
return
7272
}
73-
latency := time.Now().Sub(start).Seconds()
73+
latency := time.Since(start).Seconds()
7474
metrics.PushLatency.Observe(latency)
7575
metrics.PushSuccesses.Inc()
7676
}()
@@ -126,7 +126,7 @@ func (t *ImageIO) Pull(ctx context.Context, ns, name string) (*os.File, func(),
126126
return
127127
}
128128

129-
latency := time.Now().Sub(start).Seconds()
129+
latency := time.Since(start).Seconds()
130130
metrics.PullLatency.Observe(latency)
131131
metrics.PullSuccesses.Inc()
132132
}()

0 commit comments

Comments
 (0)