Skip to content

Commit

Permalink
Introduce CircleCI (#922)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dlsniper committed Apr 15, 2024
1 parent 28212d4 commit dcafbc9
Show file tree
Hide file tree
Showing 18 changed files with 236 additions and 84 deletions.
140 changes: 140 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
version: 2.1

"-": &go-versions
[ "1.18.10", "1.19.13", "1.20.14", "1.21.9", "1.22.2" ]

executors:
go_executor:
parameters:
version:
type: string
docker:
- image: cimg/go:<< parameters.version >>

jobs:
test:
parameters:
go_version:
type: string
executor:
name: go_executor
version: << parameters.go_version >>
steps:
- checkout
- restore_cache:
keys:
- go-mod-v4-{{ checksum "go.sum" }}
- run:
name: Install Dependencies
command: go mod download
- save_cache:
key: go-mod-v4-{{ checksum "go.sum" }}
paths:
- "/go/pkg/mod"
- run:
name: Run tests
command: |
mkdir -p /tmp/test-reports
gotestsum --junitfile /tmp/test-reports/unit-tests.xml
- store_test_results:
path: /tmp/test-reports
test-race:
parameters:
go_version:
type: string
executor:
name: go_executor
version: << parameters.go_version >>
steps:
- checkout
- restore_cache:
keys:
- go-mod-v4-{{ checksum "go.sum" }}
- run:
name: Install Dependencies
command: go mod download
- save_cache:
key: go-mod-v4-{{ checksum "go.sum" }}
paths:
- "/go/pkg/mod"
- run:
name: Run tests with race detector
command: make test-race
lint:
parameters:
go_version:
type: string
executor:
name: go_executor
version: << parameters.go_version >>
steps:
- checkout
- restore_cache:
keys:
- go-mod-v4-{{ checksum "go.sum" }}
- run:
name: Install Dependencies
command: go mod download
- run:
name: Install tooling
command: |
make tooling
- save_cache:
key: go-mod-v4-{{ checksum "go.sum" }}
paths:
- "/go/pkg/mod"
- run:
name: Linting
command: make lint
- run:
name: Running vulncheck
command: make vuln-check
fmt:
parameters:
go_version:
type: string
executor:
name: go_executor
version: << parameters.go_version >>
steps:
- checkout
- restore_cache:
keys:
- go-mod-v4-{{ checksum "go.sum" }}
- run:
name: Install Dependencies
command: go mod download
- run:
name: Install tooling
command: |
make tooling
- save_cache:
key: go-mod-v4-{{ checksum "go.sum" }}
paths:
- "/go/pkg/mod"
- run:
name: Running formatting
command: |
make fmt
make has-changes
workflows:
version: 2
build-and-test:
jobs:
- test:
matrix:
parameters:
go_version: *go-versions
- test-race:
matrix:
parameters:
go_version: *go-versions
- lint:
matrix:
parameters:
go_version: *go-versions
- fmt:
matrix:
parameters:
go_version: *go-versions
26 changes: 0 additions & 26 deletions .travis.yml

This file was deleted.

30 changes: 30 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.ONESHELL:
SHELL = /bin/sh
.SHELLFLAGS = -ec

BASE_PACKAGE := github.com/jmoiron/sqlx

tooling:
go install honnef.co/go/tools/cmd/staticcheck@v0.4.7
go install golang.org/x/vuln/cmd/govulncheck@v1.0.4
go install golang.org/x/tools/cmd/goimports@v0.20.0

has-changes:
git diff --exit-code --quiet HEAD --

lint:
go vet ./...
staticcheck -checks=all ./...

fmt:
go list -f '{{.Dir}}' ./... | xargs -I {} goimports -local $(BASE_PACKAGE) -w {}

vuln-check:
govulncheck ./...

test-race:
go test -v -race -count=1 ./...

update-dependencies:
go get -u -t -v ./...
go mod tidy
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# sqlx

[![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)
[![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)

sqlx is a library which provides a set of extensions on go's standard
`database/sql` library. The sqlx versions of `sql.DB`, `sql.TX`, `sql.Stmt`,
Expand Down
1 change: 0 additions & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@
// Additions include scanning into structs, named query support, rebinding
// queries for different drivers, convenient shorthands for common error handling
// and more.
//
package sqlx
2 changes: 1 addition & 1 deletion named.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func bindArgs(names []string, arg interface{}, m *reflectx.Mapper) ([]interface{
arglist := make([]interface{}, 0, len(names))

// grab the indirected value of arg
v := reflect.ValueOf(arg)
var v reflect.Value
for v = reflect.ValueOf(arg); v.Kind() == reflect.Ptr; {
v = v.Elem()
}
Expand Down
1 change: 1 addition & 0 deletions named_context.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build go1.8
// +build go1.8

package sqlx
Expand Down
5 changes: 3 additions & 2 deletions named_context_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build go1.8
// +build go1.8

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

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

ns, err = db.PrepareNamedContext(ctx, "invalid sql")
_, err = db.PrepareNamedContext(ctx, "invalid sql")
if err == nil {
t.Error("Expected an error with invalid prepared statement.")
}
Expand Down
4 changes: 2 additions & 2 deletions named_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ func TestNamedQueries(t *testing.T) {
var err error

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

ns, err = db.PrepareNamed("invalid sql")
_, err = db.PrepareNamed("invalid sql")
if err == nil {
t.Error("Expected an error with invalid prepared statement.")
}
Expand Down
1 change: 0 additions & 1 deletion reflectx/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// allows for Go-compatible named attribute access, including accessing embedded
// struct attributes and the ability to use functions and struct tags to
// customize field names.
//
package reflectx

import (
Expand Down
17 changes: 8 additions & 9 deletions reflectx/reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func TestFieldsEmbedded(t *testing.T) {

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

fi = fields.GetByTraversal([]int{1, 0})
if fi == nil {
t.Errorf("Expecting traveral to exist")
t.Fatal("Expecting traversal to exist")
}
if fi.Path != "name" {
t.Errorf("Expecting %s, got %s", "name", fi.Path)
}

fi = fields.GetByTraversal([]int{2})
if fi == nil {
t.Errorf("Expecting traversal to exist")
t.Fatal("Expecting traversal to exist")
}
if _, ok := fi.Options["required"]; !ok {
t.Errorf("Expecting required option to be set")
Expand Down Expand Up @@ -642,7 +642,6 @@ func TestMapperMethodsByName(t *testing.T) {
A0 *B `db:"A0"`
B `db:"A1"`
A2 int
a3 int
}

val := &A{
Expand Down Expand Up @@ -847,22 +846,22 @@ func TestMustBe(t *testing.T) {
valueErr, ok := r.(*reflect.ValueError)
if !ok {
t.Errorf("unexpected Method: %s", valueErr.Method)
t.Error("expected panic with *reflect.ValueError")
return
t.Fatal("expected panic with *reflect.ValueError")
}
if valueErr.Method != "github.com/jmoiron/sqlx/reflectx.TestMustBe" {
t.Fatalf("unexpected Method: %s", valueErr.Method)
}
if valueErr.Kind != reflect.String {
t.Errorf("unexpected Kind: %s", valueErr.Kind)
t.Fatalf("unexpected Kind: %s", valueErr.Kind)
}
} else {
t.Error("expected panic")
t.Fatal("expected panic")
}
}()

typ = reflect.TypeOf("string")
mustBe(typ, reflect.Struct)
t.Error("got here, didn't expect to")
t.Fatal("got here, didn't expect to")
}

type E1 struct {
Expand Down
21 changes: 12 additions & 9 deletions sqlx.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"database/sql/driver"
"errors"
"fmt"

"io/ioutil"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -51,9 +50,9 @@ func mapper() *reflectx.Mapper {

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

var _scannerInterface = reflect.TypeOf((*sql.Scanner)(nil)).Elem()

//lint:ignore U1000 ignoring this for now
var _valuerInterface = reflect.TypeOf((*driver.Valuer)(nil)).Elem()

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

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

switch rows.(type) {
switch rows := rows.(type) {
case *Rows:
m = rows.(*Rows).Mapper
m = rows.Mapper
default:
m = mapper()
}
Expand Down
Loading

0 comments on commit dcafbc9

Please sign in to comment.