diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index c6c50bc..65c5475 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -15,12 +15,12 @@ jobs: # Only ubuntu allows for docker support - https://docs.github.com/en/actions/using-containerized-services/about-service-containers runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Set up Go - uses: actions/setup-go@v5 + uses: actions/setup-go@v6 with: - go-version: '1.25.7' + go-version: '1.26.1' - name: Build run: go build -v ./... @@ -37,19 +37,21 @@ jobs: - "windows-latest" - "macos-latest" steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 + - uses: actions/checkout@v6 + - uses: actions/setup-go@v6 with: # use really old 1.21 version to validate claim in docs go-version: '1.21' - name: Test run: make test + env: + GOTOOLCHAIN: auto newgo: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 + - uses: actions/checkout@v6 + - uses: actions/setup-go@v6 with: go-version: "1.26" - name: Test diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 5ee008f..cbbcd73 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -16,10 +16,10 @@ jobs: name: lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 + - uses: actions/checkout@v6 + - uses: actions/setup-go@v6 with: - go-version: '1.25' + go-version: '1.26' cache: false - name: golangci-lint uses: golangci/golangci-lint-action@v9 @@ -27,7 +27,8 @@ jobs: # Require: The version of golangci-lint to use. # When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version. # When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit. - version: v2.9.0 + # Version should be the same as in the Makefile + version: v2.11.4 # Optional: working directory, useful for monorepos # working-directory: somedir @@ -52,4 +53,4 @@ jobs: # skip-build-cache: true # Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'. - # install-mode: "goinstall" \ No newline at end of file + # install-mode: "goinstall" diff --git a/.gitignore b/.gitignore index d029ec3..32bac60 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ usql go.work .idea +/tools/golangci-lint diff --git a/Makefile b/Makefile index 0582933..e1d8cdf 100644 --- a/Makefile +++ b/Makefile @@ -21,8 +21,8 @@ integration-test: itest: integration-test .PHONY: lint -lint: - golangci-lint run -v +lint: tools/golangci-lint + tools/golangci-lint run -v .PHONY: checks checks: check_tidy check_vuln check_modern @@ -39,6 +39,18 @@ check_vuln: .PHONY: check_modern check_modern: - go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@v0.20.0 ./... + test -z "$$(go fix -diff ./... | tee /dev/stderr)" # non-zero exit status on issues found # nb: modernize is not part of golangci-lint yet - https://github.com/golangci/golangci-lint/issues/686 + +# Tools targets + +tools: + mkdir -p tools + +tools/golangci-lint: tools +# Version must be the same as in golangci-lint Github action +# We install golangci-lint as recommended in the docs. See the same docs for a discussion about go run and +# go get -tool alternatives - https://golangci-lint.run/docs/welcome/install/ . +# Delete tools/golangci-lint if this target is updated (may be automated in the future) + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b ./tools v2.11.4 \ No newline at end of file diff --git a/go.mod b/go.mod index 68ef86b..1318278 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/sclgo/usqlgen -go 1.25.7 +go 1.26.1 require ( github.com/ansel1/merry/v2 v2.2.3 @@ -20,7 +20,6 @@ require ( dario.cat/mergo v1.0.1 // indirect github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c // indirect - github.com/BurntSushi/toml v1.5.0 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/containerd/log v0.1.0 // indirect @@ -79,21 +78,13 @@ require ( go.opentelemetry.io/otel/trace v1.34.0 // indirect golang.org/x/crypto v0.46.0 // indirect golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac // indirect - golang.org/x/exp/typeparams v0.0.0-20231108232855-2478ac86f678 // indirect - golang.org/x/mod v0.30.0 // indirect - golang.org/x/sync v0.19.0 // indirect golang.org/x/sys v0.39.0 // indirect golang.org/x/term v0.38.0 // indirect golang.org/x/text v0.32.0 // indirect golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect - golang.org/x/tools v0.39.0 // indirect - golang.org/x/tools/go/expect v0.1.1-deprecated // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - honnef.co/go/tools v0.6.1 // indirect modernc.org/libc v1.61.13 // indirect modernc.org/mathutil v1.7.1 // indirect modernc.org/memory v1.8.2 // indirect ) - -tool honnef.co/go/tools/cmd/staticcheck diff --git a/go.sum b/go.sum index 521ecf5..ac18183 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,6 @@ github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9 github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8= github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c h1:udKWzYgxTojEKWjV8V+WSxDXJ4NFATAsZjh8iIbsQIg= github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= -github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg= -github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/ansel1/merry/v2 v2.2.3 h1:/gBjiifpoymj+iV/8QApOET6Q4++DZJp55VR6fcHkIQ= @@ -176,8 +174,6 @@ golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU= golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0= golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac h1:l5+whBCLH3iH2ZNHYLbAe58bo7yrN4mVcnkHDYz5vvs= golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac/go.mod h1:hH+7mtFmImwwcMvScyxUhjuVHR3HGaDPMn9rMSUUbxo= -golang.org/x/exp/typeparams v0.0.0-20231108232855-2478ac86f678 h1:1P7xPZEwZMoBoz0Yze5Nx2/4pxj6nw9ZqHWXqP0iRgQ= -golang.org/x/exp/typeparams v0.0.0-20231108232855-2478ac86f678/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.30.0 h1:fDEXFVZ/fmCKProc/yAXXUijritrDzahmwwefnjoPFk= @@ -218,8 +214,6 @@ golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roY golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.39.0 h1:ik4ho21kwuQln40uelmciQPp9SipgNDdrafrYA4TmQQ= golang.org/x/tools v0.39.0/go.mod h1:JnefbkDPyD8UU2kI5fuf8ZX4/yUeh9W877ZeBONxUqQ= -golang.org/x/tools/go/expect v0.1.1-deprecated h1:jpBZDwmgPhXsKZC6WhL20P4b/wmnpsEAGHaNy0n/rJM= -golang.org/x/tools/go/expect v0.1.1-deprecated/go.mod h1:eihoPOH+FgIqa3FpoTwguz/bVUSGBlGQU67vpBeOrBY= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -240,8 +234,6 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= -honnef.co/go/tools v0.6.1 h1:R094WgE8K4JirYjBaOpz/AvTyUu/3wbmAoskKN/pxTI= -honnef.co/go/tools v0.6.1/go.mod h1:3puzxxljPCe8RGJX7BIy1plGbxEOZni5mR2aXe3/uk4= modernc.org/cc/v4 v4.24.4 h1:TFkx1s6dCkQpd6dKurBNmpo+G8Zl4Sq/ztJ+2+DEsh0= modernc.org/cc/v4 v4.24.4/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0= modernc.org/ccgo/v4 v4.23.16 h1:Z2N+kk38b7SfySC1ZkpGLN2vthNJP1+ZzGZIlH7uBxo= diff --git a/internal/gen/dbmgr.go b/internal/gen/dbmgr.go index e67650f..ecee957 100644 --- a/internal/gen/dbmgr.go +++ b/internal/gen/dbmgr.go @@ -279,16 +279,17 @@ func writeActuals(ctx context.Context, stmt *sql.Stmt, actuals []any, rowsAffect } func makeQuery(clen int, rows int, tableSpec string, placeholder func(n int) string) string { - query := "INSERT INTO " + tableSpec + " VALUES " + var query strings.Builder + query.WriteString("INSERT INTO " + tableSpec + " VALUES ") placeholders := make([]string, clen) for i := range rows { for j := range clen { placeholders[j] = placeholder(i*clen + j + 1) } - query += "(" + strings.Join(placeholders, ", ") + ")" + query.WriteString("(" + strings.Join(placeholders, ", ") + ")") if i < rows-1 { - query += ", " + query.WriteString(", ") } } - return query + return query.String() } diff --git a/internal/gen/filetools.go b/internal/gen/filetools.go index 8279ef7..e67c9e6 100644 --- a/internal/gen/filetools.go +++ b/internal/gen/filetools.go @@ -1,17 +1,17 @@ package gen import ( - "github.com/ansel1/merry/v2" "io/fs" "os" "path/filepath" + + "github.com/ansel1/merry/v2" ) func chmod(path string) error { return merry.Wrap(filepath.WalkDir(path, chmodHandler)) } -//nolint:unused seems to be a bug in staticheck U1000 but couldn't reproduce in a minimal example func chmodHandler(path string, d fs.DirEntry, err error) error { if err != nil { return err diff --git a/internal/gen/gen.go b/internal/gen/gen.go index 1da9167..c46b533 100644 --- a/internal/gen/gen.go +++ b/internal/gen/gen.go @@ -74,8 +74,7 @@ func (i Input) AllDownload() (Result, error) { cmd.Stderr = io.MultiWriter(&errorBuf, os.Stderr) err = cmd.Run() if err != nil { - var exitErr *exec.ExitError - if !errors.As(err, &exitErr) || exitErr.ExitCode() != 1 || outputBuf.Len() > 0 { + if exitErr, ok := errors.AsType[*exec.ExitError](err); !ok || exitErr.ExitCode() != 1 || outputBuf.Len() == 0 { return result, merry.Wrap(err, merry.AppendMessagef("while running go mod download with stdout length %d and stderr output \n%s", outputBuf.Len(), &errorBuf)) } // We ignore exit code 1 with non-empty output, because this indicates a partial success of