Skip to content

Commit 1375e15

Browse files
authored
Merge pull request elqsar#5 from TeneficGames/trduong/add-github-ci
ci: add GitHub Actions for lint, test, build, and integration
2 parents b641ec8 + 6c9a6a2 commit 1375e15

11 files changed

Lines changed: 143 additions & 14 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- uses: actions/setup-go@v5
19+
with:
20+
go-version-file: go.mod
21+
22+
- name: Check go mod tidy
23+
run: |
24+
go mod tidy
25+
if ! git diff --exit-code go.mod go.sum; then
26+
echo "::error::go.mod or go.sum is not tidy. Run 'go mod tidy' and commit."
27+
exit 1
28+
fi
29+
30+
- name: Build
31+
run: go build ./...
32+
33+
- name: Run govulncheck
34+
continue-on-error: true
35+
run: |
36+
go install golang.org/x/vuln/cmd/govulncheck@latest
37+
govulncheck ./...

‎.github/workflows/integration.yml‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Integration Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
integration-test:
15+
runs-on: ubuntu-latest
16+
timeout-minutes: 10
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- uses: actions/setup-go@v5
21+
with:
22+
go-version-file: go.mod
23+
24+
- name: Run integration tests
25+
run: go test -tags=integration -v -timeout=3m ./tests/integration/

‎.github/workflows/lint.yml‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
lint:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- uses: actions/setup-go@v5
19+
with:
20+
go-version-file: go.mod
21+
22+
- name: Check gofmt
23+
run: |
24+
unformatted=$(gofmt -l .)
25+
if [ -n "$unformatted" ]; then
26+
echo "::error::Files not formatted with gofmt:"
27+
echo "$unformatted"
28+
exit 1
29+
fi
30+
31+
- name: Run go vet
32+
run: go vet ./...
33+
34+
- name: Run golangci-lint
35+
uses: golangci/golangci-lint-action@v7
36+
with:
37+
version: latest

‎.github/workflows/test.yml‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
unit-test:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- uses: actions/setup-go@v5
19+
with:
20+
go-version-file: go.mod
21+
22+
- name: Run unit tests
23+
run: go test -race -coverprofile=coverage.out ./...
24+
25+
- name: Upload coverage
26+
uses: actions/upload-artifact@v4
27+
with:
28+
name: coverage
29+
path: coverage.out

‎internal/checkpoint/slot_store.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (s *SlotStore) Load(ctx context.Context) (model.WALPosition, error) {
3232
if err != nil {
3333
return model.WALPosition{}, fmt.Errorf("slot store connect: %w", err)
3434
}
35-
defer conn.Close(ctx)
35+
defer conn.Close(ctx) //nolint:errcheck
3636

3737
result := conn.ExecParams(
3838
ctx,

‎internal/engine/engine.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (e *Engine) Run(ctx context.Context, start model.WALPosition) error {
9595
if err := e.publisher.Connect(); err != nil {
9696
return fmt.Errorf("publisher connect: %w", err)
9797
}
98-
defer e.publisher.Close()
98+
defer e.publisher.Close() //nolint:errcheck
9999

100100
return e.runBatched(ctx, parsedStream)
101101
}
@@ -398,7 +398,7 @@ func (e *Engine) publishWithRetry(ctx context.Context, batchPub publisher.BatchP
398398
}
399399

400400
// Wait for acks
401-
result, err := batchPub.WaitForAcks(ctx, pending, pubItems, timeout)
401+
result, _ := batchPub.WaitForAcks(ctx, pending, pubItems, timeout)
402402

403403
// Context cancelled - return what we have
404404
if ctx.Err() != nil {

‎internal/health/server_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func TestStart_ReturnsErrorWhenAddrInUse(t *testing.T) {
100100
if err != nil {
101101
t.Fatalf("listen: %v", err)
102102
}
103-
defer ln.Close()
103+
defer ln.Close() //nolint:errcheck
104104

105105
ctx, cancel := context.WithCancel(context.Background())
106106
defer cancel()
@@ -131,7 +131,7 @@ func TestStart_ServesHealthEndpoint(t *testing.T) {
131131
for time.Now().Before(deadline) {
132132
resp, err := client.Get("http://" + addr + "/health")
133133
if err == nil {
134-
defer resp.Body.Close()
134+
defer resp.Body.Close() //nolint:errcheck
135135
if resp.StatusCode != http.StatusOK {
136136
t.Fatalf("expected 200, got %d", resp.StatusCode)
137137
}

‎internal/metrics/prometheus.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ func (g *PrometheusGauge) Get() int64 {
6262
// PrometheusHistogram wraps prometheus.Histogram with the same interface as Histogram.
6363
type PrometheusHistogram struct {
6464
histogram prometheus.Histogram
65-
sum float64
66-
count uint64
65+
sum float64 //nolint:unused
66+
count uint64 //nolint:unused
6767
}
6868

6969
// NewPrometheusHistogram creates a new Prometheus histogram with the given buckets.

‎internal/parser/wal2json_test.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ func TestPgTime_UnmarshalJSON(t *testing.T) {
7171
if err != nil {
7272
t.Fatalf("unexpected error: %v", err)
7373
}
74-
if tt.isZero && !v.Time.IsZero() {
74+
if tt.isZero && !v.IsZero() {
7575
t.Fatalf("expected zero time, got %v", v.Time)
7676
}
77-
if !tt.isZero && v.Time.IsZero() {
77+
if !tt.isZero && v.IsZero() {
7878
t.Fatal("expected non-zero time, got zero")
7979
}
8080
})
@@ -89,7 +89,7 @@ func TestPgTime_InStruct(t *testing.T) {
8989
if err := json.Unmarshal([]byte(raw), &msg); err != nil {
9090
t.Fatalf("unmarshal with null timestamp: %v", err)
9191
}
92-
if !msg.Timestamp.Time.IsZero() {
92+
if !msg.Timestamp.IsZero() {
9393
t.Fatalf("expected zero time for null timestamp, got %v", msg.Timestamp.Time)
9494
}
9595

@@ -98,11 +98,11 @@ func TestPgTime_InStruct(t *testing.T) {
9898
if err := json.Unmarshal([]byte(raw), &msg); err != nil {
9999
t.Fatalf("unmarshal with real timestamp: %v", err)
100100
}
101-
if msg.Timestamp.Time.IsZero() {
101+
if msg.Timestamp.IsZero() {
102102
t.Fatal("expected non-zero time, got zero")
103103
}
104104
expected := time.Date(2024, 1, 15, 15, 30, 0, 123456000, time.UTC)
105-
if !msg.Timestamp.Time.Equal(expected) {
105+
if !msg.Timestamp.Equal(expected) {
106106
t.Fatalf("expected %v, got %v", expected, msg.Timestamp.Time)
107107
}
108108
}

‎internal/publisher/publisher.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package publisher
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"strings"
78
"sync"
@@ -185,7 +186,7 @@ func (p *NoopPublisher) PublishWithRetries(ctx context.Context, subject string,
185186

186187
func (p *NoopPublisher) Close() error { return nil }
187188

188-
func (p *NoopPublisher) Ready(context.Context) error { return fmt.Errorf(noopPublisherReadyError) }
189+
func (p *NoopPublisher) Ready(context.Context) error { return errors.New(noopPublisherReadyError) }
189190

190191
// SubjectForEvent builds subject cdc.{database}.{schema}.{table}.
191192
func SubjectForEvent(database string, evt *model.CDCEvent) (string, error) {

0 commit comments

Comments
 (0)