Skip to content

Commit af3166f

Browse files
committed
ci: add workflows and go mod
Add GitHub workflows to lint and test the code and fix lint issues. Add go mod definition.
1 parent bd2f021 commit af3166f

File tree

7 files changed

+161
-11
lines changed

7 files changed

+161
-11
lines changed

.github/workflows/go.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Go build, test and lint
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
branches:
8+
- main
9+
pull_request:
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
go:
15+
strategy:
16+
matrix:
17+
go: [1.20]
18+
golangcli: [1.52.2]
19+
os: [ubuntu-latest, macos-latest, windows-latest]
20+
name: lint
21+
runs-on: ${{ matrix.os }}
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v3
25+
26+
- name: Setup
27+
uses: actions/setup-go@v4
28+
with:
29+
go-version: ${{ matrix.go }}
30+
cache: false
31+
32+
- name: Validate go generate / mod
33+
if: runner.os != 'Windows'
34+
run: |
35+
go mod tidy
36+
git --no-pager diff && [[ 0 -eq $(git status --porcelain | wc -l) ]]
37+
38+
- name: Go Lint Standard
39+
if: runner.os != 'Windows'
40+
uses: golangci/golangci-lint-action@v3
41+
with:
42+
version: ${{ matrix.golangci }}
43+
args: "--out-${NO_FUTURE}format colored-line-number"
44+
45+
- name: Go Lint Windows
46+
if: runner.os == 'Windows'
47+
uses: golangci/golangci-lint-action@v3
48+
env:
49+
outformat: out-format
50+
with:
51+
version: ${{ matrix.golangci }}
52+
args: "--%outformat% colored-line-number"
53+
54+
- name: Go Test
55+
run: go test -race ./...

.golangci.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
run:
2+
concurrency: 4
3+
deadline: 5m
4+
5+
linters-settings:
6+
govet:
7+
check-shadowing: false
8+
gocyclo:
9+
min-complexity: 20
10+
maligned:
11+
suggest-new: true
12+
dupl:
13+
threshold: 100
14+
goconst:
15+
min-len: 2
16+
min-occurrences: 4
17+
cyclop:
18+
max-complexity: 15
19+
misspell:
20+
ignore-words:
21+
- ect
22+
ireturn:
23+
allow:
24+
- anon
25+
- error
26+
- empty
27+
- stdlib
28+
- (or|er)$
29+
- tempFile
30+
31+
linters:
32+
enable-all: true
33+
disable:
34+
- interfacer
35+
- gas
36+
- megacheck
37+
- structcheck
38+
- staticcheck
39+
- varnamelen
40+
- gochecknoglobals
41+
- scopelint
42+
- funlen
43+
- godox
44+
- exhaustivestruct
45+
- goerr113
46+
- wsl
47+
- nlreturn
48+
- gomnd
49+
- paralleltest
50+
- wrapcheck
51+
- testpackage
52+
- golint
53+
- maligned
54+
- gofumpt
55+
- forbidigo
56+
- exhaustruct
57+
- nonamedreturns
58+
- tagliatelle
59+
- gomoddirectives
60+
- ifshort
61+
- ireturn
62+
- nosnakecase
63+
- deadcode
64+
- varcheck
65+
- rowserrcheck
66+
- sqlclosecheck
67+
- wastedassign
68+
69+
issues:
70+
exclude-use-default: false
71+
max-same-issues: 0

example_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import (
77
"github.com/multiplay/go-cticker"
88
)
99

10-
// TODO(steve): remove this nolint when go tool vet is fixed.
11-
// nolint: vet
1210
func ExampleTicker() {
11+
// Create a ticker that ticks on the minute with 1 second accuracy.
1312
t := cticker.New(time.Minute, time.Second)
14-
for tick := range t.C {
15-
// Process tick
16-
fmt.Println("tick:", tick)
17-
}
13+
defer t.Stop()
14+
15+
<-t.C
16+
17+
// Process tick
18+
fmt.Println("tick")
19+
// Output: tick
1820
}

go.mod

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module github.com/multiplay/go-cticker
2+
3+
go 1.20
4+
5+
require github.com/stretchr/testify v1.8.3
6+
7+
require (
8+
github.com/davecgh/go-spew v1.1.1 // indirect
9+
github.com/pmezard/go-difflib v1.0.0 // indirect
10+
gopkg.in/yaml.v3 v3.0.1 // indirect
11+
)

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5+
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
6+
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
7+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
8+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
9+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
10+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

ticker.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ func New(d, accuracy time.Duration) *Ticker {
8484
t.ticker = newTicker(accuracy)
8585
go t.tick(c)
8686
}
87-
8887
}()
8988

9089
return t

ticker_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestTickerDrift(t *testing.T) {
6161
ticks := make([]time.Time, 0, 4)
6262
ticks = addTicks(ticks, now, now.Add(time.Minute*3), d, a)
6363

64-
last := testTicker(t, now, d, a, times, ticks)
64+
last := testTicker(t, d, a, times, ticks)
6565
now = time.Now()
6666
assert.True(t, now.Before(last), fmt.Sprintln(now, "is not before", last))
6767
}
@@ -79,7 +79,7 @@ func TestTickerAdjustment(t *testing.T) {
7979
ticks = append(ticks, now.Truncate(d).Add(d))
8080
ticks = addTicks(ticks, summer.Add(d*2), summer.Add(d*4), d, a)
8181

82-
last := testTicker(t, now, d, a, times, ticks)
82+
last := testTicker(t, d, a, times, ticks)
8383
now = time.Now()
8484
assert.True(t, now.After(last), fmt.Sprintln(now, "is not after", last))
8585
}
@@ -104,7 +104,7 @@ func TestTickerLostTick(t *testing.T) {
104104
}
105105
}
106106

107-
last := testTicker(t, now, d, a, times, ticks)
107+
last := testTicker(t, d, a, times, ticks)
108108
now = time.Now()
109109
assert.True(t, now.Before(last), fmt.Sprintln(now, "is not before", last))
110110
}
@@ -133,7 +133,9 @@ func addTicks(ticks []time.Time, start, end time.Time, d, a time.Duration) []tim
133133
return ticks
134134
}
135135

136-
func testTicker(t *testing.T, now time.Time, d, a time.Duration, times, ticks []time.Time) time.Time {
136+
func testTicker(t *testing.T, d, a time.Duration, times, ticks []time.Time) time.Time {
137+
t.Helper()
138+
137139
newTicker = func(d time.Duration) ticker {
138140
t := &mockTicker{
139141
c: make(chan time.Time, 4),

0 commit comments

Comments
 (0)