Skip to content

Commit 9c61840

Browse files
authored
Fix GitHub workflows for PR checks and releases (#3)
* fix(ci): fix GitHub workflows for PR checks and releases * upd golangci config Signed-off-by: Denis Panfilov <gh@flaticols.dev> * llinting Signed-off-by: Denis Panfilov <gh@flaticols.dev> * fix(test): make timeout test more tolerant of timing variations --------- Signed-off-by: Denis Panfilov <gh@flaticols.dev>
1 parent c0f7a40 commit 9c61840

6 files changed

Lines changed: 137 additions & 106 deletions

File tree

.github/workflows/ci.yml

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,57 @@
1-
name: Lint & Tests
1+
name: CI
22

33
on:
44
push:
5-
branches: [main]
5+
branches: [latest]
66
pull_request:
7-
branches: [main]
7+
branches: ['*']
88

99
jobs:
10-
test:
11-
name: Test and Lint
10+
lint:
11+
name: Lint
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v4
1515

1616
- name: Set up Go
1717
uses: actions/setup-go@v5
1818
with:
19-
go-version: 1.23
19+
go-version: '1.23'
2020

21-
- name: golangci-lint
21+
- name: Run golangci-lint
2222
uses: golangci/golangci-lint-action@v8
2323
with:
2424
version: v2.1
2525

26+
test:
27+
name: Test
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v4
31+
32+
- name: Set up Go
33+
uses: actions/setup-go@v5
34+
with:
35+
go-version: '1.23'
36+
2637
- name: Run tests
2738
run: go test -v ./...
39+
40+
- name: Run benchmarks
41+
run: go test -bench=. -benchmem ./...
42+
43+
ci-status:
44+
name: CI Status
45+
runs-on: ubuntu-latest
46+
needs: [lint, test]
47+
if: always()
48+
steps:
49+
- name: Check CI Status
50+
run: |
51+
if [ "${{ needs.lint.result }}" = "success" ] && [ "${{ needs.test.result }}" = "success" ]; then
52+
echo "All checks passed!"
53+
exit 0
54+
else
55+
echo "Some checks failed!"
56+
exit 1
57+
fi

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
uses: actions/checkout@v4
1919
with:
2020
fetch-depth: 0
21+
ref: ${{ github.event.ref }}
2122

2223
- name: Get previous tag
2324
id: previous_tag
@@ -34,6 +35,7 @@ jobs:
3435
skip-version-file: true
3536
skip-commit: true
3637
skip-tag: true
38+
skip-git-pull: true
3739
release-count: 0
3840
from-tag: ${{ steps.previous_tag.outputs.previous_tag }}
3941
to-tag: ${{ github.ref }}

.golangci.yml

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,25 @@
1-
version: 2
1+
version: "2"
22

33
linters:
4+
default: none
45
enable:
5-
- govet
6+
- bodyclose
7+
- dupl
8+
- asciicheck
9+
- errcheck
10+
- errchkjson
11+
- errname
12+
- errorlint
13+
- nilerr
14+
- nilnil
615
- staticcheck
7-
- gosec
16+
exclusions:
17+
paths-except:
18+
- examples/*
819

9-
linters-settings:
10-
gosec:
11-
excludes:
12-
- G404
13-
14-
issues:
15-
exclude-rules:
16-
# Exclude from examples
17-
- path: examples/
18-
linters:
19-
- all
20-
21-
# Exclude from tests
22-
- path: _test\.go
23-
linters:
24-
- gosec
20+
formatters:
21+
enable: []
2522

2623
run:
27-
timeout: 5m
28-
tests: true
29-
allow-parallel-runners: true
30-
skip-dirs:
31-
- examples
24+
build-tags:
25+
- mock

helpers_test.go

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,44 +18,44 @@ func TestRetryWithContext(t *testing.T) {
1818
t.Run("respects context cancellation", func(t *testing.T) {
1919
ctx, cancel := context.WithCancel(context.Background())
2020
attempts := 0
21-
21+
2222
// Cancel context after a short delay
2323
go func() {
2424
time.Sleep(10 * time.Millisecond)
2525
cancel()
2626
}()
27-
27+
2828
err := RetryWithContext(ctx, func() error {
2929
attempts++
3030
return errors.New("always fail")
3131
}, Initial(20*time.Millisecond))
32-
32+
3333
if !errors.Is(err, context.Canceled) {
3434
t.Errorf("expected context.Canceled error, got: %v", err)
3535
}
36-
36+
3737
// Should have only attempted once or twice before context was cancelled
3838
if attempts > 2 {
3939
t.Errorf("expected at most 2 attempts, got %d", attempts)
4040
}
4141
})
42-
42+
4343
t.Run("succeeds with active context", func(t *testing.T) {
4444
ctx := context.Background()
4545
attempts := 0
46-
46+
4747
err := RetryWithContext(ctx, func() error {
4848
attempts++
4949
if attempts < 3 {
5050
return errors.New("temporary error")
5151
}
5252
return nil
5353
}, Initial(10*time.Millisecond))
54-
54+
5555
if err != nil {
5656
t.Errorf("expected success, got error: %v", err)
5757
}
58-
58+
5959
if attempts != 3 {
6060
t.Errorf("expected 3 attempts, got %d", attempts)
6161
}
@@ -66,19 +66,19 @@ func TestRetryWithLogging(t *testing.T) {
6666
var buf bytes.Buffer
6767
logger := log.New(&buf, "", 0)
6868
attempts := 0
69-
69+
7070
err := RetryWithLogging(func() error {
7171
attempts++
7272
if attempts < 3 {
7373
return fmt.Errorf("attempt %d failed", attempts)
7474
}
7575
return nil
7676
}, logger, Initial(10*time.Millisecond))
77-
77+
7878
if err != nil {
7979
t.Errorf("expected success, got error: %v", err)
8080
}
81-
81+
8282
logs := buf.String()
8383
if !strings.Contains(logs, "Attempt 1 failed: attempt 1 failed") {
8484
t.Errorf("expected log for attempt 1, got: %s", logs)
@@ -95,26 +95,26 @@ func TestRetryWithCondition(t *testing.T) {
9595
t.Run("permanent errors not retried", func(t *testing.T) {
9696
attempts := 0
9797
permanentErr := errors.New("permanent error")
98-
98+
9999
err := RetryWithCondition(func() error {
100100
attempts++
101101
return permanentErr
102102
}, func(err error) bool {
103-
return err != permanentErr
103+
return !errors.Is(err, permanentErr)
104104
}, Tries(5))
105-
106-
if err != permanentErr {
105+
106+
if !errors.Is(err, permanentErr) {
107107
t.Errorf("expected permanent error, got: %v", err)
108108
}
109-
109+
110110
if attempts != 1 {
111111
t.Errorf("expected 1 attempt (no retry), got %d", attempts)
112112
}
113113
})
114-
114+
115115
t.Run("retryable errors are retried", func(t *testing.T) {
116116
attempts := 0
117-
117+
118118
err := RetryWithCondition(func() error {
119119
attempts++
120120
if attempts < 3 {
@@ -124,11 +124,11 @@ func TestRetryWithCondition(t *testing.T) {
124124
}, func(err error) bool {
125125
return err != nil && err.Error() == "temporary error"
126126
}, Initial(10*time.Millisecond))
127-
127+
128128
if err != nil {
129129
t.Errorf("expected success, got error: %v", err)
130130
}
131-
131+
132132
if attempts != 3 {
133133
t.Errorf("expected 3 attempts, got %d", attempts)
134134
}
@@ -147,7 +147,7 @@ func TestHTTPRetryTransport(t *testing.T) {
147147
_, _ = w.Write([]byte("success"))
148148
}))
149149
defer server.Close()
150-
150+
151151
client := &http.Client{
152152
Transport: &HTTPRetryTransport{
153153
Options: []Option{
@@ -156,22 +156,22 @@ func TestHTTPRetryTransport(t *testing.T) {
156156
},
157157
},
158158
}
159-
159+
160160
resp, err := client.Get(server.URL)
161161
if err != nil {
162162
t.Fatalf("expected success, got error: %v", err)
163163
}
164164
defer func() { _ = resp.Body.Close() }()
165-
165+
166166
if resp.StatusCode != http.StatusOK {
167167
t.Errorf("expected status 200, got %d", resp.StatusCode)
168168
}
169-
169+
170170
body, _ := io.ReadAll(resp.Body)
171171
if string(body) != "success" {
172172
t.Errorf("expected body 'success', got '%s'", body)
173173
}
174-
174+
175175
if attempts != 3 {
176176
t.Errorf("expected 3 attempts, got %d", attempts)
177177
}
@@ -188,22 +188,22 @@ func TestNewHTTPClient(t *testing.T) {
188188
w.WriteHeader(http.StatusOK)
189189
}))
190190
defer server.Close()
191-
191+
192192
client := NewHTTPClient(
193193
Initial(10*time.Millisecond),
194194
Tries(3),
195195
)
196-
196+
197197
resp, err := client.Get(server.URL)
198198
if err != nil {
199199
t.Fatalf("expected success, got error: %v", err)
200200
}
201201
defer func() { _ = resp.Body.Close() }()
202-
202+
203203
if resp.StatusCode != http.StatusOK {
204204
t.Errorf("expected status 200, got %d", resp.StatusCode)
205205
}
206-
206+
207207
if attempts != 2 {
208208
t.Errorf("expected 2 attempts, got %d", attempts)
209209
}
@@ -221,23 +221,23 @@ func TestHTTPDo(t *testing.T) {
221221
_, _ = w.Write([]byte("done"))
222222
}))
223223
defer server.Close()
224-
224+
225225
req, err := http.NewRequest("GET", server.URL, nil)
226226
if err != nil {
227227
t.Fatalf("failed to create request: %v", err)
228228
}
229-
229+
230230
resp, err := HTTPDo(req, nil, Initial(10*time.Millisecond))
231231
if err != nil {
232232
t.Fatalf("expected success, got error: %v", err)
233233
}
234234
defer func() { _ = resp.Body.Close() }()
235-
235+
236236
if resp.StatusCode != http.StatusOK {
237237
t.Errorf("expected status 200, got %d", resp.StatusCode)
238238
}
239-
239+
240240
if attempts != 2 {
241241
t.Errorf("expected 2 attempts, got %d", attempts)
242242
}
243-
}
243+
}

0 commit comments

Comments
 (0)