Skip to content

Commit

Permalink
Update to Go 1.20 and fix unit tests (#923)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ccojocar committed Feb 6, 2023
1 parent b4270dd commit df14837
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 3 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,18 +33,15 @@ 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:
@echo "FORMATTING"
@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 ./...

Expand Down
9 changes: 8 additions & 1 deletion analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"log"
"os"
"regexp"
"strings"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -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() {
Expand Down
1 change: 0 additions & 1 deletion report/html/writer.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package html

import (
// use go embed to import template
_ "embed"
"html/template"
"io"
Expand Down

0 comments on commit df14837

Please sign in to comment.