-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (85 loc) · 2.88 KB
/
test.yml
File metadata and controls
99 lines (85 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
name: Go Tests (PG ${{ matrix.postgres }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
postgres: ["16", "17", "18"]
services:
postgres:
image: postgres:${{ matrix.postgres }}
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 5s
--health-timeout 5s
--health-retries 10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Lint
uses: golangci/golangci-lint-action@v6
continue-on-error: true
with:
version: latest
args: --timeout=5m
- name: Unit tests
run: go test ./...
- name: E2E tests
env:
PGHOST: 127.0.0.1
PGPORT: 5432
PGUSER: postgres
PGPASSWORD: postgres
PGDATABASE: postgres
run: go test ./e2e -v -count=1
- name: Run examples
run: |
set -e
for dir in examples/composite_unique \
examples/decimal \
examples/fk_actions \
examples/ignore_field \
examples/index_partial \
examples/keyset_pagination \
examples/soft_delete \
examples/tx \
examples/uuid; do
echo "=== Running $dir ==="
go run "./$dir"
done
echo "=== Running examples/main.go ==="
go run ./examples
echo "=== Running examples/sql_migrations ==="
(cd examples/sql_migrations && go run .)
echo "=== Running examples/blog (timeout 5s) ==="
timeout 5 go run ./examples/blog || [ $? -eq 124 ] && echo "blog: OK (timed out as expected)"
echo "=== Running examples/observability (timeout 5s) ==="
timeout 5 go run ./examples/observability || [ $? -eq 124 ] && echo "observability: OK (timed out as expected)"
- name: Test coverage
env:
PGHOST: 127.0.0.1
PGPORT: 5432
PGUSER: postgres
PGPASSWORD: postgres
PGDATABASE: postgres
run: |
go test -coverpkg=./... ./... -coverprofile=coverage.out -covermode=atomic
coverage=$(go tool cover -func=coverage.out | awk '/total:/ {print $3}' | sed 's/%//')
echo "Coverage: ${coverage}%"
threshold=80
awk -v c=$coverage -v t=$threshold 'BEGIN { if (c+0 < t) { printf("Coverage %.1f%% is below threshold %d%%\n", c, t); exit 1 } else { printf("Coverage OK: %.1f%% (threshold %d%%)\n", c, t); exit 0 } }'