Skip to content

Commit 4325236

Browse files
authored
Migrate to github actions (#122)
* ci: add github action * ci: remove travis ci * fix: gofmt * fix: flaky ExampleOrderedQuery_ThenByDescending * fix: lints * ci: setup dependabot to bump go version on CI.
1 parent 9b75bfd commit 4325236

File tree

11 files changed

+109
-55
lines changed

11 files changed

+109
-55
lines changed

.github/dependabot.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
commit-message:
8+
prefix: "ci"

.github/workflows/ci.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: ci.yml
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
- master
9+
10+
permissions:
11+
contents: read
12+
13+
env:
14+
GO111MODULE: on
15+
16+
jobs:
17+
golangci:
18+
name: lint
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v5
22+
23+
- uses: actions/setup-go@v6
24+
with:
25+
go-version: stable
26+
27+
- name: golangci-lint
28+
uses: golangci/golangci-lint-action@v8
29+
with:
30+
version: v2.1
31+
32+
build:
33+
name: Build and Test
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v5
37+
38+
- uses: actions/setup-go@v6
39+
with:
40+
go-version: 1.25
41+
42+
- name: go vet
43+
run: go vet -x ./...
44+
45+
- name: Check Formatting
46+
run: test -z "$(gofmt -s -l -w . | tee /dev/stderr)"
47+
48+
- name: Run Tests
49+
run: go test -v ./...
50+
51+
- name: Coverage (profile.cov)
52+
run: go test -covermode=count -coverprofile=profile.cov
53+
54+
- name: Coveralls
55+
uses: coverallsapp/github-action@v2
56+
with:
57+
github-token: ${{ secrets.GITHUB_TOKEN }}
58+
file: profile.cov
59+
format: golang

.travis.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# go-linq [![GoDoc](https://godoc.org/github.com/ahmetb/go-linq?status.svg)](https://godoc.org/github.com/ahmetb/go-linq) [![Build Status](https://travis-ci.org/ahmetb/go-linq.svg?branch=master)](https://travis-ci.org/ahmetb/go-linq) [![Coverage Status](https://coveralls.io/repos/github/ahmetb/go-linq/badge.svg?branch=master)](https://coveralls.io/github/ahmetb/go-linq?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/ahmetb/go-linq)](https://goreportcard.com/report/github.com/ahmetb/go-linq)
1+
# go-linq [![GoDoc](https://godoc.org/github.com/ahmetb/go-linq?status.svg)](https://godoc.org/github.com/ahmetb/go-linq) [![Build Status](https://github.com/ahmetb/go-linq/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/ahmetb/go-linq/actions/workflows/ci.yml) [![Coverage Status](https://coveralls.io/repos/github/ahmetb/go-linq/badge.svg?branch=master)](https://coveralls.io/github/ahmetb/go-linq?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/ahmetb/go-linq)](https://goreportcard.com/report/github.com/ahmetb/go-linq)
22

33
A powerful language integrated query (LINQ) library for Go.
44

compare.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@ type comparer func(interface{}, interface{}) int
66
// elements in order to work with linq.
77
//
88
// Example:
9-
// func (f foo) CompareTo(c Comparable) int {
10-
// a, b := f.f1, c.(foo).f1
119
//
12-
// if a < b {
13-
// return -1
14-
// } else if a > b {
15-
// return 1
16-
// }
10+
// func (f foo) CompareTo(c Comparable) int {
11+
// a, b := f.f1, c.(foo).f1
1712
//
18-
// return 0
19-
// }
13+
// if a < b {
14+
// return -1
15+
// } else if a > b {
16+
// return 1
17+
// }
18+
//
19+
// return 0
20+
// }
2021
type Comparable interface {
2122
CompareTo(Comparable) int
2223
}

example_test.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ func ExampleQuery_Append() {
326326
// 5
327327
}
328328

329-
//The following code example demonstrates how to use Average
330-
//to calculate the average of a slice of values.
329+
// The following code example demonstrates how to use Average
330+
// to calculate the average of a slice of values.
331331
func ExampleQuery_Average() {
332332
grades := []int{78, 92, 100, 37, 81}
333333
average := From(grades).Average()
@@ -360,8 +360,8 @@ func ExampleQuery_Contains() {
360360
// Does the slice contains 5? true
361361
}
362362

363-
//The following code example demonstrates how to use CountWith
364-
//to count the even numbers in an array.
363+
// The following code example demonstrates how to use CountWith
364+
// to count the even numbers in an array.
365365
func ExampleQuery_CountWith() {
366366
slice := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
367367

@@ -445,8 +445,8 @@ func ExampleQuery_DefaultIfEmpty() {
445445

446446
}
447447

448-
//The following code example demonstrates how to use Distinct
449-
//to return distinct elements from a slice of integers.
448+
// The following code example demonstrates how to use Distinct
449+
// to return distinct elements from a slice of integers.
450450
func ExampleQuery_Distinct() {
451451
ages := []int{21, 46, 46, 55, 17, 21, 55, 55}
452452

@@ -567,7 +567,7 @@ func ExampleQuery_First() {
567567

568568
}
569569

570-
//The following code example demonstrates how to use FirstWith
570+
// The following code example demonstrates how to use FirstWith
571571
// to return the first element of an array that satisfies a condition.
572572
func ExampleQuery_FirstWith() {
573573
numbers := []int{9, 34, 65, 92, 87, 435, 3, 54, 83, 23, 87, 435, 67, 12, 19}
@@ -583,8 +583,8 @@ func ExampleQuery_FirstWith() {
583583

584584
}
585585

586-
//The following code example demonstrates how to use Intersect
587-
//to return the elements that appear in each of two slices of integers.
586+
// The following code example demonstrates how to use Intersect
587+
// to return the elements that appear in each of two slices of integers.
588588
func ExampleQuery_Intersect() {
589589
id1 := []int{44, 26, 92, 30, 71, 38}
590590
id2 := []int{39, 59, 83, 47, 26, 4, 30}
@@ -603,8 +603,8 @@ func ExampleQuery_Intersect() {
603603

604604
}
605605

606-
//The following code example demonstrates how to use IntersectBy
607-
//to return the elements that appear in each of two slices of products with same Code.
606+
// The following code example demonstrates how to use IntersectBy
607+
// to return the elements that appear in each of two slices of products with same Code.
608608
func ExampleQuery_IntersectBy() {
609609
type Product struct {
610610
Name string
@@ -716,10 +716,10 @@ func ExampleQuery_OrderByDescending() {
716716
// The following code example demonstrates how to use ThenByDescending to perform
717717
// a secondary ordering of the elements in a slice in descending order.
718718
func ExampleOrderedQuery_ThenByDescending() {
719-
fruits := []string{"apPLe", "baNanA", "apple", "APple", "orange", "BAnana", "ORANGE", "apPLE"}
719+
fruits := []string{"apPLe", "baNanA", "apple", "APple", "orange", "BAnana", "ORANGE"}
720720

721721
// Sort the strings first ascending by their length and
722-
// then descending using a custom case insensitive comparer.
722+
// then descending using a custom case-insensitive comparer.
723723
var query []string
724724
From(fruits).
725725
OrderBy(
@@ -728,21 +728,22 @@ func ExampleOrderedQuery_ThenByDescending() {
728728
ThenByDescending(
729729
func(fruit interface{}) interface{} { return fruit.(string)[0] },
730730
).
731+
ThenByDescending(
732+
func(fruit interface{}) interface{} { return fruit.(string)[3] },
733+
).
731734
ToSlice(&query)
732735

733736
for _, fruit := range query {
734737
fmt.Println(fruit)
735738
}
736739
// Output:
737-
// apPLe
738-
// apPLE
739740
// apple
741+
// apPLe
740742
// APple
741743
// orange
742744
// baNanA
743745
// ORANGE
744746
// BAnana
745-
746747
}
747748

748749
// The following code example demonstrates how to use Concat
@@ -1281,7 +1282,7 @@ func ExampleQuery_SumUInts() {
12811282
}
12821283

12831284
// The following code example demonstrates how to use Take
1284-
// to return elements from the start of a slice.
1285+
// to return elements from the start of a slice.
12851286
func ExampleQuery_Take() {
12861287
grades := []int{59, 82, 70, 56, 92, 98, 85}
12871288

@@ -1910,7 +1911,7 @@ func ExampleQuery_GroupByT() {
19101911
}
19111912

19121913
// The following code example demonstrates how to use GroupJoinT
1913-
// to perform a grouped join on two slices.
1914+
// to perform a grouped join on two slices.
19141915
func ExampleQuery_GroupJoinT() {
19151916

19161917
type Person struct {
@@ -2405,7 +2406,7 @@ func ExampleQuery_SelectManyByIndexedT() {
24052406

24062407
}
24072408

2408-
//The following code example demonstrates how to use SingleWithT
2409+
// The following code example demonstrates how to use SingleWithT
24092410
// to select the only element of a slice that satisfies a condition.
24102411
func ExampleQuery_SingleWithT() {
24112412
fruits := []string{"apple", "banana", "mango", "orange", "passionfruit", "grape"}

genericfunc_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func TestNewGenericFunc(t *testing.T) {
6666

6767
for _, test := range tests {
6868
_, err := newGenericFunc(test.methodName, test.paramName, test.function, test.validationFunc)
69-
if !(err == test.exception || err.Error() == test.exception.Error()) {
69+
if err != test.exception && err.Error() != test.exception.Error() {
7070
t.Errorf("Validate expect error: %s, actual: %s", test.exception, err)
7171
}
7272
}
@@ -112,7 +112,7 @@ func TestCall(t *testing.T) {
112112
func() {
113113
defer func() {
114114
r := recover()
115-
if !(r == test.exception || r == test.exception.Error()) {
115+
if r != test.exception && r != test.exception.Error() {
116116
t.Errorf("expect error: nil, actual: %s", r)
117117
}
118118
}()

orderby.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func (q Query) OrderByDescending(selector func(interface{}) interface{}) Ordered
9191

9292
// OrderByDescendingT is the typed version of OrderByDescending.
9393
// - selectorFn is of type "func(TSource) TKey"
94+
//
9495
// NOTE: OrderByDescending has better performance than OrderByDescendingT.
9596
func (q Query) OrderByDescendingT(selectorFn interface{}) OrderedQuery {
9697
selectorGenericFunc, err := newGenericFunc(
@@ -138,6 +139,7 @@ func (oq OrderedQuery) ThenBy(
138139

139140
// ThenByT is the typed version of ThenBy.
140141
// - selectorFn is of type "func(TSource) TKey"
142+
//
141143
// NOTE: ThenBy has better performance than ThenByT.
142144
func (oq OrderedQuery) ThenByT(selectorFn interface{}) OrderedQuery {
143145
selectorGenericFunc, err := newGenericFunc(
@@ -184,6 +186,7 @@ func (oq OrderedQuery) ThenByDescending(selector func(interface{}) interface{})
184186

185187
// ThenByDescendingT is the typed version of ThenByDescending.
186188
// - selectorFn is of type "func(TSource) TKey"
189+
//
187190
// NOTE: ThenByDescending has better performance than ThenByDescendingT.
188191
func (oq OrderedQuery) ThenByDescendingT(selectorFn interface{}) OrderedQuery {
189192
selectorFunc, ok := selectorFn.(func(interface{}) interface{})
@@ -230,6 +233,7 @@ func (q Query) Sort(less func(i, j interface{}) bool) Query {
230233

231234
// SortT is the typed version of Sort.
232235
// - lessFn is of type "func(TSource,TSource) bool"
236+
//
233237
// NOTE: Sort has better performance than SortT.
234238
func (q Query) SortT(lessFn interface{}) Query {
235239
lessGenericFunc, err := newGenericFunc(

result_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func TestForEach(t *testing.T) {
220220

221221
func TestForEachT_PanicWhenActionFnIsInvalid(t *testing.T) {
222222
mustPanicWithError(t, "ForEachT: parameter [actionFn] has a invalid function signature. Expected: 'func(T)', actual: 'func(int,int)'", func() {
223-
From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).ForEachT(func(item, idx int) { item = item + 2 })
223+
From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).ForEachT(func(item, idx int) {})
224224
})
225225
}
226226

@@ -247,7 +247,7 @@ func TestForEachIndexed(t *testing.T) {
247247

248248
func TestForEachIndexedT_PanicWhenActionFnIsInvalid(t *testing.T) {
249249
mustPanicWithError(t, "ForEachIndexedT: parameter [actionFn] has a invalid function signature. Expected: 'func(int,T)', actual: 'func(int)'", func() {
250-
From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).ForEachIndexedT(func(item int) { item = item + 2 })
250+
From([]int{1, 1, 1, 2, 1, 2, 3, 4, 2}).ForEachIndexedT(func(item int) {})
251251
})
252252
}
253253

select.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func (q Query) Select(selector func(interface{}) interface{}) Query {
3232

3333
// SelectT is the typed version of Select.
3434
// - selectorFn is of type "func(TSource)TResult"
35+
//
3536
// NOTE: Select has better performance than SelectT.
3637
func (q Query) SelectT(selectorFn interface{}) Query {
3738

@@ -91,6 +92,7 @@ func (q Query) SelectIndexed(selector func(int, interface{}) interface{}) Query
9192

9293
// SelectIndexedT is the typed version of SelectIndexed.
9394
// - selectorFn is of type "func(int,TSource)TResult"
95+
//
9496
// NOTE: SelectIndexed has better performance than SelectIndexedT.
9597
func (q Query) SelectIndexedT(selectorFn interface{}) Query {
9698
selectGenericFunc, err := newGenericFunc(

0 commit comments

Comments
 (0)