Skip to content
This repository was archived by the owner on Feb 14, 2025. It is now read-only.

Commit b807d52

Browse files
authored
chore: update ci and linter (#9)
1 parent 9498f7f commit b807d52

File tree

8 files changed

+148
-59
lines changed

8 files changed

+148
-59
lines changed

.github/workflows/test.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
on:
2+
push:
3+
branches:
4+
- master
5+
pull_request:
6+
7+
name: run tests
8+
jobs:
9+
test:
10+
11+
strategy:
12+
matrix:
13+
go-version: [ 1.15, 1.16 ]
14+
runs-on: ubuntu-latest
15+
env:
16+
GOLANGCI_LINT_VERSION: v1.41.1
17+
18+
steps:
19+
- name: Install Go
20+
if: success()
21+
uses: actions/setup-go@v2
22+
with:
23+
go-version: ${{ matrix.go-version }}
24+
25+
- name: Checkout code
26+
uses: actions/checkout@v2
27+
28+
- name: Cache Go modules
29+
uses: actions/cache@v2
30+
with:
31+
path: ~/go/pkg/mod
32+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
33+
restore-keys: |
34+
${{ runner.os }}-go-
35+
- name: Run linter
36+
uses: golangci/golangci-lint-action@v2
37+
with:
38+
version: ${{ env.GOLANGCI_LINT_VERSION }}
39+
40+
- name: Run tests
41+
run: go test -covermode=count -coverprofile=coverage.out ./...
42+
43+
- name: Convert coverage.out to coverage.lcov
44+
uses: jandelgado/gcov2lcov-action@v1.0.6
45+
- name: Coveralls
46+
uses: coverallsapp/github-action@v1.1.2
47+
with:
48+
github-token: ${{ secrets.GITHUB_TOKEN }}
49+
path-to-lcov: coverage.lcov

.golangci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
run:
2+
tests: false
3+
timeout: 5m
4+
5+
linters-settings:
6+
cyclop:
7+
max-complexity: 12
8+
skip-tests: true
9+
funlen:
10+
lines: 80
11+
gofumpt:
12+
extra-rules: true
13+
gosec:
14+
excludes:
15+
- G103
16+
17+
linters:
18+
enable-all: true
19+
disable:
20+
- interfacer # deprecated
21+
- scopelint # deprecated
22+
- maligned # deprecated
23+
- golint # deprecated
24+
- exhaustive
25+
- exhaustivestruct
26+
- gci
27+
- gochecknoglobals
28+
- goerr113
29+
- gomnd
30+
- nlreturn
31+
- maligned
32+
- wrapcheck
33+
- wsl
34+
35+
issues:
36+
exclude-use-default: false

.travis.yml

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

LICENCE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 Nicholas Wiersma
3+
Copyright (c) 2021 Nicholas Wiersma
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
include github.com/hamba/make/golang
2+
3+
# Run benchmarks
4+
bench:
5+
@go test -bench . ./...
6+
.PHONY: bench

bench_test.go

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,60 +8,88 @@ import (
88
"github.com/hamba/timex/mono"
99
)
1010

11-
func BenchmarkMonoNow(b *testing.B) {
11+
func BenchmarkTimexMonoNow(b *testing.B) {
1212
b.ReportAllocs()
13-
for i := 0; i < b.N; i++ {
14-
_ = mono.Now()
15-
}
13+
b.ResetTimer()
14+
b.RunParallel(func(pb *testing.PB) {
15+
for pb.Next() {
16+
_ = mono.Now()
17+
}
18+
})
1619
}
1720

18-
func BenchmarkMonoSince(b *testing.B) {
21+
func BenchmarkTimexMonoSince(b *testing.B) {
1922
start := mono.Now()
2023

2124
b.ReportAllocs()
2225
b.ResetTimer()
23-
for i := 0; i < b.N; i++ {
24-
_ = mono.Since(start)
25-
}
26+
b.RunParallel(func(pb *testing.PB) {
27+
for pb.Next() {
28+
_ = mono.Since(start)
29+
}
30+
})
2631
}
2732

2833
func BenchmarkTimexNow(b *testing.B) {
2934
b.ReportAllocs()
30-
for i := 0; i < b.N; i++ {
31-
_ = timex.Now()
32-
}
35+
b.ResetTimer()
36+
b.RunParallel(func(pb *testing.PB) {
37+
for pb.Next() {
38+
_ = timex.Now()
39+
}
40+
})
3341
}
3442

3543
func BenchmarkTimexSince(b *testing.B) {
3644
start := timex.Now()
3745

3846
b.ReportAllocs()
3947
b.ResetTimer()
40-
for i := 0; i < b.N; i++ {
41-
_ = timex.Since(start)
42-
}
48+
b.RunParallel(func(pb *testing.PB) {
49+
for pb.Next() {
50+
_ = timex.Since(start)
51+
}
52+
})
4353
}
4454

4555
func BenchmarkTimexUnix(b *testing.B) {
4656
b.ReportAllocs()
47-
for i := 0; i < b.N; i++ {
48-
_ = timex.Unix()
49-
}
57+
b.ResetTimer()
58+
b.RunParallel(func(pb *testing.PB) {
59+
for pb.Next() {
60+
_ = timex.Unix()
61+
}
62+
})
5063
}
5164

52-
func BenchmarkWallTimeNow(b *testing.B) {
65+
func BenchmarkTimeNow(b *testing.B) {
5366
b.ReportAllocs()
54-
for i := 0; i < b.N; i++ {
55-
_ = time.Now().UnixNano()
56-
}
67+
b.ResetTimer()
68+
b.RunParallel(func(pb *testing.PB) {
69+
for pb.Next() {
70+
_ = time.Now().UnixNano()
71+
}
72+
})
5773
}
5874

59-
func BenchmarkWallTimeSince(b *testing.B) {
75+
func BenchmarkTimeSince(b *testing.B) {
6076
start := time.Now()
6177

6278
b.ReportAllocs()
6379
b.ResetTimer()
64-
for i := 0; i < b.N; i++ {
65-
_ = time.Since(start)
66-
}
80+
b.RunParallel(func(pb *testing.PB) {
81+
for pb.Next() {
82+
_ = time.Since(start)
83+
}
84+
})
85+
}
86+
87+
func BenchmarkTimeUnix(b *testing.B) {
88+
b.ReportAllocs()
89+
b.ResetTimer()
90+
b.RunParallel(func(pb *testing.PB) {
91+
for pb.Next() {
92+
_ = time.Now().Unix()
93+
}
94+
})
6795
}

mono/time.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ package mono
33

44
import (
55
"time"
6-
_ "unsafe" // Required in order to import nanotime
6+
// Required in order to import nanotime.
7+
_ "unsafe"
78
)
89

910
//go:linkname nanotime runtime.nanotime

time.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ package timex
33

44
import (
55
"time"
6-
_ "unsafe" // Required in order to import walltime
6+
// Required in order to import walltime.
7+
_ "unsafe"
78
)
89

910
//go:linkname walltime runtime.walltime

0 commit comments

Comments
 (0)