Skip to content

Commit

Permalink
Merge pull request #20 from tim-mwangi/upgrade-go-agent
Browse files Browse the repository at this point in the history
Upgrade go agent to 1.23
  • Loading branch information
jcchavezs authored Oct 2, 2024
2 parents 23b2a3f + 081de94 commit 5c0cfeb
Show file tree
Hide file tree
Showing 13 changed files with 706 additions and 772 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
go: ["1.19", "1.20", "1.21"]
go: ["1.21", "1.22", "1.23"]
steps:
# Set fetch-depth: 0 to fetch commit history and tags for use in version calculation
- name: Check out code
uses: actions/checkout@v2.3.4
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup go
uses: actions/setup-go@v1
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}

Expand All @@ -31,11 +31,10 @@ jobs:
go get ./...
- name: Lint files
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v6.1.0
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.42
skip-go-installation: true
version: v1.61.0

- name: Run tests
run: go test ./...
6 changes: 3 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
run:
deadline: 5m
timeout: 5m

linters:
disable-all: true
Expand All @@ -14,9 +14,9 @@ linters:
- lll
- misspell
- nakedret
- structcheck
# Replaces structcheck and varcheck.
- unused
- unparam
- varcheck

linters-settings:
dupl:
Expand Down
12 changes: 9 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
module github.com/jcchavezs/porto

go 1.15
go 1.23

require (
github.com/stretchr/testify v1.6.1
golang.org/x/mod v0.3.0
github.com/stretchr/testify v1.9.0
golang.org/x/mod v0.21.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
29 changes: 8 additions & 21 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
72 changes: 41 additions & 31 deletions import.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,7 @@ func findAndAddVanityImportForModuleDir(workingDir, baseAbsDir, absDir string, m

gc += c
} else if fileName := f.Name(); isGoFile(fileName) && !isGoTestFile(fileName) {
shouldEvaluate := true
if len(opts.RestrictToFilesRegexes) > 0 {
shouldEvaluate = matchesAny(opts.RestrictToFilesRegexes, fileName)
} else if len(opts.SkipFilesRegexes) > 0 {
shouldEvaluate = !matchesAny(opts.SkipFilesRegexes, fileName)
}

if !shouldEvaluate {
if !shouldEvaluate(opts, fileName) {
continue
}

Expand All @@ -162,30 +155,11 @@ func findAndAddVanityImportForModuleDir(workingDir, baseAbsDir, absDir string, m

switch err {
case nil:
if opts.WriteResultToFile {
err = writeContentToFile(absFilepath, newContent)
if err != nil {
return 0, fmt.Errorf("failed to write file: %v", err)
}
gc++
} else if opts.ListDiffFiles {
relFilepath, err := filepath.Rel(workingDir, absFilepath)
if err != nil {
return 0, fmt.Errorf("failed to resolve relative path: %v", err)
}
// TODO(jcchavezs): make this pluggable to allow different output formats
// and test assertions.
fmt.Printf("%s: missing right vanity import\n", relFilepath)
gc++
} else {
relFilepath, err := filepath.Rel(workingDir, absFilepath)
if err != nil {
return 0, fmt.Errorf("failed to resolve relative path: %v", err)
}
fmt.Printf("👉 %s\n\n", relFilepath)
fmt.Println(string(newContent))
gc++
err = handleNilErrorCase(opts, absFilepath, newContent, workingDir)
if err != nil {
return 0, err
}
gc++
case errMainPackage:
continue
default:
Expand All @@ -197,6 +171,42 @@ func findAndAddVanityImportForModuleDir(workingDir, baseAbsDir, absDir string, m
return gc, nil
}

func shouldEvaluate(opts Options, fileName string) bool {
shouldEvaluate := true
if len(opts.RestrictToFilesRegexes) > 0 {
shouldEvaluate = matchesAny(opts.RestrictToFilesRegexes, fileName)
} else if len(opts.SkipFilesRegexes) > 0 {
shouldEvaluate = !matchesAny(opts.SkipFilesRegexes, fileName)
}

return shouldEvaluate
}

func handleNilErrorCase(opts Options, absFilepath string, newContent []byte, workingDir string) error {
if opts.WriteResultToFile {
err := writeContentToFile(absFilepath, newContent)
if err != nil {
return fmt.Errorf("failed to write file: %v", err)
}
} else if opts.ListDiffFiles {
relFilepath, err := filepath.Rel(workingDir, absFilepath)
if err != nil {
return fmt.Errorf("failed to resolve relative path: %v", err)
}
// TODO(jcchavezs): make this pluggable to allow different output formats
// and test assertions.
fmt.Printf("%s: missing right vanity import\n", relFilepath)
} else {
relFilepath, err := filepath.Rel(workingDir, absFilepath)
if err != nil {
return fmt.Errorf("failed to resolve relative path: %v", err)
}
fmt.Printf("👉 %s\n\n", relFilepath)
fmt.Println(string(newContent))
}
return nil
}

func matchesAny(regexes []*regexp.Regexp, str string) bool {
for _, fr := range regexes {
if matched := fr.MatchString(str); matched {
Expand Down
2 changes: 1 addition & 1 deletion testdata/codegen/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/jcchavezs/porto/codegen

go 1.15
go 1.23
2 changes: 1 addition & 1 deletion testdata/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/jcchavezs/porto/integration

go 1.15
go 1.23
2 changes: 1 addition & 1 deletion testdata/leftpad/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/jcchavezs/porto-integration-leftpad

go 1.15
go 1.23
2 changes: 1 addition & 1 deletion testdata/nopad/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/jcchavezs/porto-integration/nopad

go 1.15
go 1.23
2 changes: 1 addition & 1 deletion testdata/rightpad/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module jcchavezs.github.io/porto/integration/rightpad

go 1.15
go 1.23
2 changes: 1 addition & 1 deletion testdata/withgomod/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/jcchavezs/porto/testmodule

go 1.15
go 1.23
Loading

0 comments on commit 5c0cfeb

Please sign in to comment.