From df14837174ef4c3cad366301d6e333bb0aa99a18 Mon Sep 17 00:00:00 2001 From: Cosmin Cojocar Date: Mon, 6 Feb 2023 14:15:05 +0100 Subject: [PATCH] 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 --- .github/workflows/ci.yml | 12 +++++------- .github/workflows/release.yml | 4 ++-- Makefile | 10 +++------- analyzer_test.go | 9 ++++++++- report/html/writer.go | 1 - 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc74e5c..8add85e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,17 +10,15 @@ jobs: test: strategy: matrix: - go_version: - - '1.18.10' # TODO: remove this once actions/setup-go@v3 uses latest as latest; see https://github.com/securego/gosec/pull/880 - - '1.19.5' # TODO: remove this once actions/setup-go@v3 uses latest as latest; see https://github.com/securego/gosec/pull/880 + version: [{go: '1.19.5', golangci: 'v1.50.1'}, {go: '1.20', golangci: 'latest'}] runs-on: ubuntu-latest env: GO111MODULE: on steps: - - name: Setup go ${{ matrix.go_version }} + - name: Setup go ${{ matrix.version.go }} uses: actions/setup-go@v3 with: - go-version: ${{ matrix.go_version }} + go-version: ${{ matrix.version.go }} - name: Checkout Source uses: actions/checkout@v3 - uses: actions/cache@v3 @@ -32,7 +30,7 @@ jobs: - name: lint uses: golangci/golangci-lint-action@v3 with: - version: latest + version: ${{ matrix.version.golangci }} - name: Run Tests run: make test coverage: @@ -44,7 +42,7 @@ jobs: - name: Setup go uses: actions/setup-go@v3 with: - 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 + go-version: '1.20' - name: Checkout Source uses: actions/checkout@v3 - uses: actions/cache@v3 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e01d9da..4adb32a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,7 +17,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: '1.19.5' + go-version: '1.20' - name: Install Cosign uses: sigstore/cosign-installer@v2 with: @@ -66,7 +66,7 @@ jobs: tags: ${{steps.meta.outputs.tags}} labels: ${{steps.meta.outputs.labels}} push: true - build-args: GO_VERSION=1.19 + build-args: GO_VERSION=1.20 - name: Sign Docker Image run: cosign sign -key /tmp/cosign.key ${TAGS} env: diff --git a/Makefile b/Makefile index 9c630eb..093c8a9 100644 --- a/Makefile +++ b/Makefile @@ -14,12 +14,11 @@ GO := GO111MODULE=on go GO_NOMOD :=GO111MODULE=off go GOPATH ?= $(shell $(GO) env GOPATH) GOBIN ?= $(GOPATH)/bin -GOLINT ?= $(GOBIN)/golint GOSEC ?= $(GOBIN)/gosec GINKGO ?= $(GOBIN)/ginkgo GO_MINOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2) GOVULN_MIN_VERSION = 17 -GO_VERSION = 1.19 +GO_VERSION = 1.20 default: $(MAKE) build @@ -34,7 +33,7 @@ install-govulncheck: go install golang.org/x/vuln/cmd/govulncheck@latest; \ fi -test: install-test-deps build fmt lint sec govulncheck +test: install-test-deps build fmt vet sec govulncheck $(GINKGO) -v --fail-fast fmt: @@ -42,10 +41,7 @@ fmt: @FORMATTED=`$(GO) fmt ./...` @([ ! -z "$(FORMATTED)" ] && printf "Fixed unformatted files:\n$(FORMATTED)") || true -lint: - @echo "LINTING: golint" - $(GO_NOMOD) get -u golang.org/x/lint/golint - $(GOLINT) -set_exit_status ./... +vet: @echo "VETTING" $(GO) vet ./... diff --git a/analyzer_test.go b/analyzer_test.go index e84cae1..177c81f 100644 --- a/analyzer_test.go +++ b/analyzer_test.go @@ -4,6 +4,7 @@ import ( "errors" "log" "os" + "regexp" "strings" . "github.com/onsi/ginkgo/v2" @@ -152,13 +153,19 @@ var _ = Describe("Analyzer", func() { err = analyzer.Process(buildTags, pkg.Path) Expect(err).ShouldNot(HaveOccurred()) _, _, errors := analyzer.Report() - Expect(len(errors)).To(Equal(1)) + foundErr := false for _, ferr := range errors { Expect(len(ferr)).To(Equal(1)) + match, err := regexp.MatchString(ferr[0].Err, `expected declaration, found '}'`) + if !match || err != nil { + continue + } + foundErr = true Expect(ferr[0].Line).To(Equal(4)) Expect(ferr[0].Column).To(Equal(5)) Expect(ferr[0].Err).Should(MatchRegexp(`expected declaration, found '}'`)) } + Expect(foundErr).To(BeTrue()) }) It("should not report errors when a nosec line comment is present", func() { diff --git a/report/html/writer.go b/report/html/writer.go index 125b7cd..9ddd5c4 100644 --- a/report/html/writer.go +++ b/report/html/writer.go @@ -1,7 +1,6 @@ package html import ( - // use go embed to import template _ "embed" "html/template" "io"