Skip to content

Commit dcafbc9

Browse files
authored
Introduce CircleCI (#922)
* Introduce CircleCI With this PR, we introduce the CircleCI as a CI pipeline. The old configuration, TravisCI, is removed. A Makefile is also created to allow easier interaction with the different commands available. * Fix all linting issues * Fix goimports version
1 parent 28212d4 commit dcafbc9

18 files changed

+236
-84
lines changed

Diff for: .circleci/config.yml

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
version: 2.1
2+
3+
"-": &go-versions
4+
[ "1.18.10", "1.19.13", "1.20.14", "1.21.9", "1.22.2" ]
5+
6+
executors:
7+
go_executor:
8+
parameters:
9+
version:
10+
type: string
11+
docker:
12+
- image: cimg/go:<< parameters.version >>
13+
14+
jobs:
15+
test:
16+
parameters:
17+
go_version:
18+
type: string
19+
executor:
20+
name: go_executor
21+
version: << parameters.go_version >>
22+
steps:
23+
- checkout
24+
- restore_cache:
25+
keys:
26+
- go-mod-v4-{{ checksum "go.sum" }}
27+
- run:
28+
name: Install Dependencies
29+
command: go mod download
30+
- save_cache:
31+
key: go-mod-v4-{{ checksum "go.sum" }}
32+
paths:
33+
- "/go/pkg/mod"
34+
- run:
35+
name: Run tests
36+
command: |
37+
mkdir -p /tmp/test-reports
38+
gotestsum --junitfile /tmp/test-reports/unit-tests.xml
39+
- store_test_results:
40+
path: /tmp/test-reports
41+
test-race:
42+
parameters:
43+
go_version:
44+
type: string
45+
executor:
46+
name: go_executor
47+
version: << parameters.go_version >>
48+
steps:
49+
- checkout
50+
- restore_cache:
51+
keys:
52+
- go-mod-v4-{{ checksum "go.sum" }}
53+
- run:
54+
name: Install Dependencies
55+
command: go mod download
56+
- save_cache:
57+
key: go-mod-v4-{{ checksum "go.sum" }}
58+
paths:
59+
- "/go/pkg/mod"
60+
- run:
61+
name: Run tests with race detector
62+
command: make test-race
63+
lint:
64+
parameters:
65+
go_version:
66+
type: string
67+
executor:
68+
name: go_executor
69+
version: << parameters.go_version >>
70+
steps:
71+
- checkout
72+
- restore_cache:
73+
keys:
74+
- go-mod-v4-{{ checksum "go.sum" }}
75+
- run:
76+
name: Install Dependencies
77+
command: go mod download
78+
- run:
79+
name: Install tooling
80+
command: |
81+
make tooling
82+
- save_cache:
83+
key: go-mod-v4-{{ checksum "go.sum" }}
84+
paths:
85+
- "/go/pkg/mod"
86+
- run:
87+
name: Linting
88+
command: make lint
89+
- run:
90+
name: Running vulncheck
91+
command: make vuln-check
92+
fmt:
93+
parameters:
94+
go_version:
95+
type: string
96+
executor:
97+
name: go_executor
98+
version: << parameters.go_version >>
99+
steps:
100+
- checkout
101+
- restore_cache:
102+
keys:
103+
- go-mod-v4-{{ checksum "go.sum" }}
104+
- run:
105+
name: Install Dependencies
106+
command: go mod download
107+
- run:
108+
name: Install tooling
109+
command: |
110+
make tooling
111+
- save_cache:
112+
key: go-mod-v4-{{ checksum "go.sum" }}
113+
paths:
114+
- "/go/pkg/mod"
115+
- run:
116+
name: Running formatting
117+
command: |
118+
make fmt
119+
make has-changes
120+
121+
workflows:
122+
version: 2
123+
build-and-test:
124+
jobs:
125+
- test:
126+
matrix:
127+
parameters:
128+
go_version: *go-versions
129+
- test-race:
130+
matrix:
131+
parameters:
132+
go_version: *go-versions
133+
- lint:
134+
matrix:
135+
parameters:
136+
go_version: *go-versions
137+
- fmt:
138+
matrix:
139+
parameters:
140+
go_version: *go-versions

Diff for: .travis.yml

-26
This file was deleted.

Diff for: Makefile

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.ONESHELL:
2+
SHELL = /bin/sh
3+
.SHELLFLAGS = -ec
4+
5+
BASE_PACKAGE := github.com/jmoiron/sqlx
6+
7+
tooling:
8+
go install honnef.co/go/tools/cmd/[email protected]
9+
go install golang.org/x/vuln/cmd/[email protected]
10+
go install golang.org/x/tools/cmd/[email protected]
11+
12+
has-changes:
13+
git diff --exit-code --quiet HEAD --
14+
15+
lint:
16+
go vet ./...
17+
staticcheck -checks=all ./...
18+
19+
fmt:
20+
go list -f '{{.Dir}}' ./... | xargs -I {} goimports -local $(BASE_PACKAGE) -w {}
21+
22+
vuln-check:
23+
govulncheck ./...
24+
25+
test-race:
26+
go test -v -race -count=1 ./...
27+
28+
update-dependencies:
29+
go get -u -t -v ./...
30+
go mod tidy

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# sqlx
22

3-
[![Build Status](https://travis-ci.org/jmoiron/sqlx.svg?branch=master)](https://travis-ci.org/jmoiron/sqlx) [![Coverage Status](https://coveralls.io/repos/github/jmoiron/sqlx/badge.svg?branch=master)](https://coveralls.io/github/jmoiron/sqlx?branch=master) [![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/jmoiron/sqlx) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/jmoiron/sqlx/master/LICENSE)
3+
[![CircleCI](https://dl.circleci.com/status-badge/img/gh/jmoiron/sqlx/tree/master.svg?style=shield)](https://dl.circleci.com/status-badge/redirect/gh/jmoiron/sqlx/tree/master) [![Coverage Status](https://coveralls.io/repos/github/jmoiron/sqlx/badge.svg?branch=master)](https://coveralls.io/github/jmoiron/sqlx?branch=master) [![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/jmoiron/sqlx) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/jmoiron/sqlx/master/LICENSE)
44

55
sqlx is a library which provides a set of extensions on go's standard
66
`database/sql` library. The sqlx versions of `sql.DB`, `sql.TX`, `sql.Stmt`,

Diff for: doc.go

-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@
88
// Additions include scanning into structs, named query support, rebinding
99
// queries for different drivers, convenient shorthands for common error handling
1010
// and more.
11-
//
1211
package sqlx

Diff for: named.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func bindArgs(names []string, arg interface{}, m *reflectx.Mapper) ([]interface{
174174
arglist := make([]interface{}, 0, len(names))
175175

176176
// grab the indirected value of arg
177-
v := reflect.ValueOf(arg)
177+
var v reflect.Value
178178
for v = reflect.ValueOf(arg); v.Kind() == reflect.Ptr; {
179179
v = v.Elem()
180180
}

Diff for: named_context.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build go1.8
12
// +build go1.8
23

34
package sqlx

Diff for: named_context_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build go1.8
12
// +build go1.8
23

34
package sqlx
@@ -18,12 +19,12 @@ func TestNamedContextQueries(t *testing.T) {
1819
ctx := context.Background()
1920

2021
// Check that invalid preparations fail
21-
ns, err = db.PrepareNamedContext(ctx, "SELECT * FROM person WHERE first_name=:first:name")
22+
_, err = db.PrepareNamedContext(ctx, "SELECT * FROM person WHERE first_name=:first:name")
2223
if err == nil {
2324
t.Error("Expected an error with invalid prepared statement.")
2425
}
2526

26-
ns, err = db.PrepareNamedContext(ctx, "invalid sql")
27+
_, err = db.PrepareNamedContext(ctx, "invalid sql")
2728
if err == nil {
2829
t.Error("Expected an error with invalid prepared statement.")
2930
}

Diff for: named_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,12 @@ func TestNamedQueries(t *testing.T) {
139139
var err error
140140

141141
// Check that invalid preparations fail
142-
ns, err = db.PrepareNamed("SELECT * FROM person WHERE first_name=:first:name")
142+
_, err = db.PrepareNamed("SELECT * FROM person WHERE first_name=:first:name")
143143
if err == nil {
144144
t.Error("Expected an error with invalid prepared statement.")
145145
}
146146

147-
ns, err = db.PrepareNamed("invalid sql")
147+
_, err = db.PrepareNamed("invalid sql")
148148
if err == nil {
149149
t.Error("Expected an error with invalid prepared statement.")
150150
}

Diff for: reflectx/reflect.go

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// allows for Go-compatible named attribute access, including accessing embedded
44
// struct attributes and the ability to use functions and struct tags to
55
// customize field names.
6-
//
76
package reflectx
87

98
import (

Diff for: reflectx/reflect_test.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ func TestFieldsEmbedded(t *testing.T) {
354354

355355
fi = fields.GetByPath("person.name")
356356
if fi == nil {
357-
t.Errorf("Expecting person.name to exist")
357+
t.Fatal("Expecting person.name to exist")
358358
}
359359
if fi.Path != "person.name" {
360360
t.Errorf("Expecting %s, got %s", "person.name", fi.Path)
@@ -365,15 +365,15 @@ func TestFieldsEmbedded(t *testing.T) {
365365

366366
fi = fields.GetByTraversal([]int{1, 0})
367367
if fi == nil {
368-
t.Errorf("Expecting traveral to exist")
368+
t.Fatal("Expecting traversal to exist")
369369
}
370370
if fi.Path != "name" {
371371
t.Errorf("Expecting %s, got %s", "name", fi.Path)
372372
}
373373

374374
fi = fields.GetByTraversal([]int{2})
375375
if fi == nil {
376-
t.Errorf("Expecting traversal to exist")
376+
t.Fatal("Expecting traversal to exist")
377377
}
378378
if _, ok := fi.Options["required"]; !ok {
379379
t.Errorf("Expecting required option to be set")
@@ -642,7 +642,6 @@ func TestMapperMethodsByName(t *testing.T) {
642642
A0 *B `db:"A0"`
643643
B `db:"A1"`
644644
A2 int
645-
a3 int
646645
}
647646

648647
val := &A{
@@ -847,22 +846,22 @@ func TestMustBe(t *testing.T) {
847846
valueErr, ok := r.(*reflect.ValueError)
848847
if !ok {
849848
t.Errorf("unexpected Method: %s", valueErr.Method)
850-
t.Error("expected panic with *reflect.ValueError")
851-
return
849+
t.Fatal("expected panic with *reflect.ValueError")
852850
}
853851
if valueErr.Method != "github.com/jmoiron/sqlx/reflectx.TestMustBe" {
852+
t.Fatalf("unexpected Method: %s", valueErr.Method)
854853
}
855854
if valueErr.Kind != reflect.String {
856-
t.Errorf("unexpected Kind: %s", valueErr.Kind)
855+
t.Fatalf("unexpected Kind: %s", valueErr.Kind)
857856
}
858857
} else {
859-
t.Error("expected panic")
858+
t.Fatal("expected panic")
860859
}
861860
}()
862861

863862
typ = reflect.TypeOf("string")
864863
mustBe(typ, reflect.Struct)
865-
t.Error("got here, didn't expect to")
864+
t.Fatal("got here, didn't expect to")
866865
}
867866

868867
type E1 struct {

Diff for: sqlx.go

+12-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"database/sql/driver"
66
"errors"
77
"fmt"
8-
98
"io/ioutil"
109
"path/filepath"
1110
"reflect"
@@ -51,9 +50,9 @@ func mapper() *reflectx.Mapper {
5150

5251
// isScannable takes the reflect.Type and the actual dest value and returns
5352
// whether or not it's Scannable. Something is scannable if:
54-
// * it is not a struct
55-
// * it implements sql.Scanner
56-
// * it has no exported fields
53+
// - it is not a struct
54+
// - it implements sql.Scanner
55+
// - it has no exported fields
5756
func isScannable(t reflect.Type) bool {
5857
if reflect.PtrTo(t).Implements(_scannerInterface) {
5958
return true
@@ -160,6 +159,8 @@ func mapperFor(i interface{}) *reflectx.Mapper {
160159
}
161160

162161
var _scannerInterface = reflect.TypeOf((*sql.Scanner)(nil)).Elem()
162+
163+
//lint:ignore U1000 ignoring this for now
163164
var _valuerInterface = reflect.TypeOf((*driver.Valuer)(nil)).Elem()
164165

165166
// Row is a reimplementation of sql.Row in order to gain access to the underlying
@@ -248,6 +249,8 @@ type DB struct {
248249

249250
// NewDb returns a new sqlx DB wrapper for a pre-existing *sql.DB. The
250251
// driverName of the original database is required for named query support.
252+
//
253+
//lint:ignore ST1003 changing this would break the package interface.
251254
func NewDb(db *sql.DB, driverName string) *DB {
252255
return &DB{DB: db, driverName: driverName, Mapper: mapper()}
253256
}
@@ -884,9 +887,9 @@ func structOnlyError(t reflect.Type) error {
884887
// then each row must only have one column which can scan into that type. This
885888
// allows you to do something like:
886889
//
887-
// rows, _ := db.Query("select id from people;")
888-
// var ids []int
889-
// scanAll(rows, &ids, false)
890+
// rows, _ := db.Query("select id from people;")
891+
// var ids []int
892+
// scanAll(rows, &ids, false)
890893
//
891894
// and ids will be a list of the id results. I realize that this is a desirable
892895
// interface to expose to users, but for now it will only be exposed via changes
@@ -935,9 +938,9 @@ func scanAll(rows rowsi, dest interface{}, structOnly bool) error {
935938
var values []interface{}
936939
var m *reflectx.Mapper
937940

938-
switch rows.(type) {
941+
switch rows := rows.(type) {
939942
case *Rows:
940-
m = rows.(*Rows).Mapper
943+
m = rows.Mapper
941944
default:
942945
m = mapper()
943946
}

0 commit comments

Comments
 (0)