Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from Travis CI to GitHub Actions #89

Merged
merged 2 commits into from Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
@@ -0,0 +1,2 @@
*.go text eol=lf

46 changes: 46 additions & 0 deletions .github/workflows/ci.yaml
@@ -0,0 +1,46 @@
name: Go

on: [push, pull_request]

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
fail-fast: false

steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17.1

- name: Setup gotestsum
uses: autero1/action-gotestsum@v1.0.0
with:
gotestsum_version: 1.7.0

- name: Test
run: gotestsum --format short-verbose -- -race -timeout=20m -coverprofile=coverage_txt -covermode=atomic ./...

- uses: codecov/codecov-action@v2
with:
files: coverage_txt

lint:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
fail-fast: false

steps:
- uses: actions/checkout@v2
- uses: golangci/golangci-lint-action@v2
with:
args: --timeout=5m
31 changes: 0 additions & 31 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions bson.go
Expand Up @@ -39,10 +39,10 @@ func IsBSONObjectID(str string) bool {
// ObjectId represents a BSON object ID (alias to go.mongodb.org/mongo-driver/bson/primitive.ObjectID)
//
// swagger:strfmt bsonobjectid
type ObjectId bsonprim.ObjectID
type ObjectId bsonprim.ObjectID //nolint:revive

// NewObjectId creates a ObjectId from a Hex String
func NewObjectId(hex string) ObjectId {
func NewObjectId(hex string) ObjectId { //nolint:revive
oid, err := bsonprim.ObjectIDFromHex(hex)
if err != nil {
panic(err)
Expand Down
8 changes: 8 additions & 0 deletions default_test.go
Expand Up @@ -345,6 +345,8 @@ type testableFormat interface {
}

func testStringFormat(t *testing.T, what testableFormat, format, with string, validSamples, invalidSamples []string) {
t.Helper()

// text encoding interface
b := []byte(with)
err := what.UnmarshalText(b)
Expand Down Expand Up @@ -422,6 +424,8 @@ func testStringFormat(t *testing.T, what testableFormat, format, with string, va
}

func resetValue(t *testing.T, format string, what encoding.TextUnmarshaler) {
t.Helper()

err := what.UnmarshalText([]byte("reset value"))
assert.NoError(t, err)
val := reflect.Indirect(reflect.ValueOf(what))
Expand All @@ -430,13 +434,17 @@ func resetValue(t *testing.T, format string, what encoding.TextUnmarshaler) {
}

func testValid(t *testing.T, name, value string) {
t.Helper()

ok := Default.Validates(name, value)
if !ok {
t.Errorf("expected %q of type %s to be valid", value, name)
}
}

func testInvalid(t *testing.T, name, value string) {
t.Helper()

ok := Default.Validates(name, value)
if ok {
t.Errorf("expected %q of type %s to be invalid", value, name)
Expand Down
4 changes: 4 additions & 0 deletions duration_test.go
Expand Up @@ -75,6 +75,8 @@ func TestDuration(t *testing.T) {
}

func testDurationParser(t *testing.T, toParse string, expected time.Duration) {
t.Helper()

r, e := ParseDuration(toParse)
assert.NoError(t, e)
assert.Equal(t, expected, r)
Expand All @@ -91,6 +93,8 @@ func TestIsDuration_Failed(t *testing.T) {
}

func testDurationSQLScanner(t *testing.T, dur time.Duration) {
t.Helper()

values := []interface{}{int64(dur), float64(dur)}
for _, value := range values {
var result Duration
Expand Down
59 changes: 32 additions & 27 deletions format.go
Expand Up @@ -93,75 +93,80 @@ func NewSeededFormats(seeds []knownFormat, normalizer NameNormalizer) Registry {
}

// MapStructureHookFunc is a decode hook function for mapstructure
func (f *defaultFormats) MapStructureHookFunc() mapstructure.DecodeHookFunc {
return func(from reflect.Type, to reflect.Type, data interface{}) (interface{}, error) {
func (f *defaultFormats) MapStructureHookFunc() mapstructure.DecodeHookFunc { //nolint:gocyclo,cyclop
return func(from reflect.Type, to reflect.Type, obj interface{}) (interface{}, error) {
if from.Kind() != reflect.String {
return data, nil
return obj, nil
}
data, ok := obj.(string)
if !ok {
return nil, fmt.Errorf("failed to cast %+v to string", obj)
}

for _, v := range f.data {
tpe, _ := f.GetType(v.Name)
if to == tpe {
switch v.Name {
case "date":
d, err := time.Parse(RFC3339FullDate, data.(string))
d, err := time.Parse(RFC3339FullDate, data)
if err != nil {
return nil, err
}
return Date(d), nil
case "datetime":
input := data.(string)
input := data
if len(input) == 0 {
return nil, fmt.Errorf("empty string is an invalid datetime format")
}
return ParseDateTime(input)
case "duration":
dur, err := ParseDuration(data.(string))
dur, err := ParseDuration(data)
if err != nil {
return nil, err
}
return Duration(dur), nil
case "uri":
return URI(data.(string)), nil
return URI(data), nil
case "email":
return Email(data.(string)), nil
return Email(data), nil
case "uuid":
return UUID(data.(string)), nil
return UUID(data), nil
case "uuid3":
return UUID3(data.(string)), nil
return UUID3(data), nil
case "uuid4":
return UUID4(data.(string)), nil
return UUID4(data), nil
case "uuid5":
return UUID5(data.(string)), nil
return UUID5(data), nil
case "hostname":
return Hostname(data.(string)), nil
return Hostname(data), nil
case "ipv4":
return IPv4(data.(string)), nil
return IPv4(data), nil
case "ipv6":
return IPv6(data.(string)), nil
return IPv6(data), nil
case "cidr":
return CIDR(data.(string)), nil
return CIDR(data), nil
case "mac":
return MAC(data.(string)), nil
return MAC(data), nil
case "isbn":
return ISBN(data.(string)), nil
return ISBN(data), nil
case "isbn10":
return ISBN10(data.(string)), nil
return ISBN10(data), nil
case "isbn13":
return ISBN13(data.(string)), nil
return ISBN13(data), nil
case "creditcard":
return CreditCard(data.(string)), nil
return CreditCard(data), nil
case "ssn":
return SSN(data.(string)), nil
return SSN(data), nil
case "hexcolor":
return HexColor(data.(string)), nil
return HexColor(data), nil
case "rgbcolor":
return RGBColor(data.(string)), nil
return RGBColor(data), nil
case "byte":
return Base64(data.(string)), nil
return Base64(data), nil
case "password":
return Password(data.(string)), nil
return Password(data), nil
case "ulid":
ulid, err := ParseULID(data.(string))
ulid, err := ParseULID(data)
if err != nil {
return nil, err
}
Expand Down
8 changes: 6 additions & 2 deletions ulid.go
Expand Up @@ -32,7 +32,7 @@ var (
}

ULIDScanDefaultFunc = func(raw interface{}) (ULID, error) {
var u ULID = NewULIDZero()
u := NewULIDZero()
switch x := raw.(type) {
case nil:
// zerp ulid
Expand Down Expand Up @@ -90,7 +90,11 @@ func NewULIDZero() ULID {

// NewULID generates new unique ULID value and a error if any
func NewULID() (u ULID, err error) {
entropy := ulidEntropyPool.Get().(io.Reader)
obj := ulidEntropyPool.Get()
entropy, ok := obj.(io.Reader)
if !ok {
return u, fmt.Errorf("failed to cast %+v to io.Reader", obj)
}

id, err := ulid.New(ulid.Now(), entropy)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion ulid_test.go
Expand Up @@ -195,7 +195,7 @@ func TestFormatULID_Scan(t *testing.T) {
assert.NoError(t, err)

ULIDScanOverrideFunc = func(raw interface{}) (ULID, error) {
var u ULID = NewULIDZero()
u := NewULIDZero()
switch x := raw.(type) {
case [16]byte:
return u, u.ULID.UnmarshalBinary(x[:])
Expand Down