Skip to content

Commit df14837

Browse files
authored
Update to Go 1.20 and fix unit tests (#923)
* Fix unit tests for Go 1.20 * Update to Go 1.20 in the build scripts * Remove support for 1.18 in the build * Fix the golangci lint version according to Go version used * Fix golangci version string * Fix gci linter warning * Remove golint in favour of golangci
1 parent b4270dd commit df14837

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

.github/workflows/ci.yml

+5-7
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@ jobs:
1010
test:
1111
strategy:
1212
matrix:
13-
go_version:
14-
- '1.18.10' # TODO: remove this once actions/setup-go@v3 uses latest as latest; see https://github.com/securego/gosec/pull/880
15-
- '1.19.5' # TODO: remove this once actions/setup-go@v3 uses latest as latest; see https://github.com/securego/gosec/pull/880
13+
version: [{go: '1.19.5', golangci: 'v1.50.1'}, {go: '1.20', golangci: 'latest'}]
1614
runs-on: ubuntu-latest
1715
env:
1816
GO111MODULE: on
1917
steps:
20-
- name: Setup go ${{ matrix.go_version }}
18+
- name: Setup go ${{ matrix.version.go }}
2119
uses: actions/setup-go@v3
2220
with:
23-
go-version: ${{ matrix.go_version }}
21+
go-version: ${{ matrix.version.go }}
2422
- name: Checkout Source
2523
uses: actions/checkout@v3
2624
- uses: actions/cache@v3
@@ -32,7 +30,7 @@ jobs:
3230
- name: lint
3331
uses: golangci/golangci-lint-action@v3
3432
with:
35-
version: latest
33+
version: ${{ matrix.version.golangci }}
3634
- name: Run Tests
3735
run: make test
3836
coverage:
@@ -44,7 +42,7 @@ jobs:
4442
- name: Setup go
4543
uses: actions/setup-go@v3
4644
with:
47-
go-version: '1.19.5' # TODO: remove this once actions/setup-go@v3 uses latest as latest; see https://github.com/securego/gosec/pull/880
45+
go-version: '1.20'
4846
- name: Checkout Source
4947
uses: actions/checkout@v3
5048
- uses: actions/cache@v3

.github/workflows/release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Set up Go
1818
uses: actions/setup-go@v3
1919
with:
20-
go-version: '1.19.5'
20+
go-version: '1.20'
2121
- name: Install Cosign
2222
uses: sigstore/cosign-installer@v2
2323
with:
@@ -66,7 +66,7 @@ jobs:
6666
tags: ${{steps.meta.outputs.tags}}
6767
labels: ${{steps.meta.outputs.labels}}
6868
push: true
69-
build-args: GO_VERSION=1.19
69+
build-args: GO_VERSION=1.20
7070
- name: Sign Docker Image
7171
run: cosign sign -key /tmp/cosign.key ${TAGS}
7272
env:

Makefile

+3-7
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ GO := GO111MODULE=on go
1414
GO_NOMOD :=GO111MODULE=off go
1515
GOPATH ?= $(shell $(GO) env GOPATH)
1616
GOBIN ?= $(GOPATH)/bin
17-
GOLINT ?= $(GOBIN)/golint
1817
GOSEC ?= $(GOBIN)/gosec
1918
GINKGO ?= $(GOBIN)/ginkgo
2019
GO_MINOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
2120
GOVULN_MIN_VERSION = 17
22-
GO_VERSION = 1.19
21+
GO_VERSION = 1.20
2322

2423
default:
2524
$(MAKE) build
@@ -34,18 +33,15 @@ install-govulncheck:
3433
go install golang.org/x/vuln/cmd/govulncheck@latest; \
3534
fi
3635

37-
test: install-test-deps build fmt lint sec govulncheck
36+
test: install-test-deps build fmt vet sec govulncheck
3837
$(GINKGO) -v --fail-fast
3938

4039
fmt:
4140
@echo "FORMATTING"
4241
@FORMATTED=`$(GO) fmt ./...`
4342
@([ ! -z "$(FORMATTED)" ] && printf "Fixed unformatted files:\n$(FORMATTED)") || true
4443

45-
lint:
46-
@echo "LINTING: golint"
47-
$(GO_NOMOD) get -u golang.org/x/lint/golint
48-
$(GOLINT) -set_exit_status ./...
44+
vet:
4945
@echo "VETTING"
5046
$(GO) vet ./...
5147

analyzer_test.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"log"
66
"os"
7+
"regexp"
78
"strings"
89

910
. "github.com/onsi/ginkgo/v2"
@@ -152,13 +153,19 @@ var _ = Describe("Analyzer", func() {
152153
err = analyzer.Process(buildTags, pkg.Path)
153154
Expect(err).ShouldNot(HaveOccurred())
154155
_, _, errors := analyzer.Report()
155-
Expect(len(errors)).To(Equal(1))
156+
foundErr := false
156157
for _, ferr := range errors {
157158
Expect(len(ferr)).To(Equal(1))
159+
match, err := regexp.MatchString(ferr[0].Err, `expected declaration, found '}'`)
160+
if !match || err != nil {
161+
continue
162+
}
163+
foundErr = true
158164
Expect(ferr[0].Line).To(Equal(4))
159165
Expect(ferr[0].Column).To(Equal(5))
160166
Expect(ferr[0].Err).Should(MatchRegexp(`expected declaration, found '}'`))
161167
}
168+
Expect(foundErr).To(BeTrue())
162169
})
163170

164171
It("should not report errors when a nosec line comment is present", func() {

report/html/writer.go

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package html
22

33
import (
4-
// use go embed to import template
54
_ "embed"
65
"html/template"
76
"io"

0 commit comments

Comments
 (0)