-
Notifications
You must be signed in to change notification settings - Fork 3
309 lines (272 loc) · 10.2 KB
/
ci.yaml
File metadata and controls
309 lines (272 loc) · 10.2 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
name: CI
on:
workflow_call:
pull_request:
types: [ opened, synchronize, reopened, ready_for_review ]
workflow_dispatch:
push:
paths-ignore:
- '**.md'
- '**.kf'
branches:
- main
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
if: ${{ !github.event.pull_request.draft }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.25.3'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v8
with:
# Require: The version of golangci-lint to use.
version: v2.10.1
args: --timeout=30m --issues-exit-code=0 --verbose
acceptance-test:
runs-on: ubuntu-latest
if: ${{ !github.event.pull_request.draft }}
steps:
- name: Clear cache and show disk space
if: ${{ !env.ACT }} # skip during local actions testing
run: |
echo "Initial disk space:"
df -h /
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
# Additional cleanup for Android, Azure, and other pre-installed tools
sudo rm -rf /usr/local/lib/android || true
sudo rm -rf /usr/local/.ghcup || true
sudo rm -rf /usr/share/swift || true
echo "Disk space after cleanup:"
df -h /
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.25.3'
- name: Install Taskfile
uses: arduino/setup-task@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Run Taskfile
run: task build
- name: Clean caches to free disk space
run: |
# Clean Go build cache to free space before test compilation
# NOTE: Keep .build/ directory - needed later for single-node stack
go clean -cache -testcache -fuzzcache || true
# Remove Docker build cache and images
docker builder prune -af || true
docker image prune -af || true
# Show remaining disk space
df -h /
- name: Run Go Tests (with retry)
run: |
set -o errexit -o nounset -o pipefail
attempt=1
max_attempts=3
backoff=10
# Ensure Docker daemon is ready before first attempt (max 60s)
wait_count=0
max_wait=30
until docker info >/dev/null 2>&1; do
if [ $wait_count -ge $max_wait ]; then
echo "❌ Docker daemon failed to become ready after ${max_wait} attempts"
exit 1
fi
echo "Waiting for Docker daemon to be ready... (attempt $((wait_count + 1))/${max_wait})"
sleep 2
wait_count=$((wait_count + 1))
done
echo "✅ Docker daemon is ready"
while [ $attempt -le $max_attempts ]; do
echo "Test attempt $attempt of $max_attempts"
# Always try to cleanup lingering Kwil DB resources before each attempt
bash scripts/ci-cleanup.sh || true
# Additional cleanup only on retries
if [ $attempt -gt 1 ]; then
docker compose -f compose.yaml down -v || true
docker system prune -af --volumes || true
sleep 5
fi
# Run unit tests only on PRs (skip integration tests and benchmarks to avoid disk space issues)
# Integration tests create Docker containers which rapidly fill disk (~50+ containers)
# Benchmarks are long-running performance tests (not needed for every PR)
# Full integration suite runs on main branch via slow-integration-tests job
if go test -failfast -p 1 -timeout=15m -count=1 -tags=kwiltest \
$(go list -tags=kwiltest ./... | grep -v -E '^github\.com/trufnetwork/node/(tests/(streams|database_size|extensions/(erc20|database-size))|internal/benchmark)'); then
echo "✅ Tests passed on attempt $attempt"
break
else
echo "❌ Tests failed on attempt $attempt"
# Surface Docker diagnostics
echo "::group::Docker diagnostics"
docker ps -a || true
docker system df || true
docker info || true
echo "::endgroup::"
if [ $attempt -eq $max_attempts ]; then
echo "All test attempts failed"
exit 1
fi
attempt=$((attempt + 1))
echo "Waiting ${backoff}s before retry..."
sleep "$backoff"
backoff=$((backoff * 2))
fi
done
- name: Cleanup Docker resources before acceptance test
run: |
docker compose -f compose.yaml down -v || true
docker system prune -af --volumes || true
- name: Start Single-Node Stack
run: task single:start
- name: Wait for node to warm up
run: |
echo "⏳ giving the node 10s to initialize…"
sleep 10
- name: Run CI Tests Script
run: |
scripts/ci-tests.sh
check-slow-test-paths:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
outputs:
slow_tests_changed: ${{ steps.filter.outputs.slow_tests }}
steps:
- uses: actions/checkout@v4
- name: Check for affected paths
uses: dorny/paths-filter@v3
id: filter
with:
filters: |
slow_tests:
- 'tests/streams/**'
- 'tests/database_size/**'
- 'tests/extensions/erc20/**'
- 'tests/extensions/database-size/**'
slow-integration-tests:
runs-on: ubuntu-latest
needs: check-slow-test-paths
# Runs on:
# - main branch (always)
# - workflow_dispatch (manual trigger)
# - pull_request when:
# * Label "run-slow-tests" is added to the PR, OR
# * Files in order_book/, digest/, erc20/, or streams/ directories are modified
#
# To trigger on a PR:
# 1. Add label "run-slow-tests" to the PR, OR
# 2. Modify files in tests/streams/order_book/, tests/streams/digest/,
# tests/extensions/erc20/, or tests/streams/ directories
if: |
always() && (
github.event_name == 'workflow_dispatch' ||
github.ref == 'refs/heads/main' ||
(
github.event_name == 'pull_request' &&
(
contains(github.event.pull_request.labels.*.name, 'run-slow-tests') ||
needs.check-slow-test-paths.outputs.slow_tests_changed == 'true'
)
)
)
steps:
- uses: actions/checkout@v4
- name: Clear cache and show disk space
run: |
echo "Initial disk space:"
df -h /
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo rm -rf /usr/local/lib/android || true
sudo rm -rf /usr/local/.ghcup || true
sudo rm -rf /usr/share/swift || true
echo "Disk space after cleanup:"
df -h /
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.25.3'
- name: Install Taskfile
uses: arduino/setup-task@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Run Taskfile
run: task build
- name: Clean build artifacts to free disk space
run: |
sudo rm -rf .build/ || true
go clean -cache -testcache -fuzzcache || true
docker builder prune -af || true
docker image prune -af || true
df -h /
- name: Run Slow Integration Tests (with retry)
run: |
set -o errexit -o nounset -o pipefail
attempt=1
max_attempts=3
backoff=10
# Ensure Docker daemon is ready before first attempt (max 60s)
wait_count=0
max_wait=30
until docker info >/dev/null 2>&1; do
if [ $wait_count -ge $max_wait ]; then
echo "❌ Docker daemon failed to become ready after ${max_wait} attempts"
exit 1
fi
echo "Waiting for Docker daemon to be ready... (attempt $((wait_count + 1))/${max_wait})"
sleep 2
wait_count=$((wait_count + 1))
done
echo "✅ Docker daemon is ready"
while [ $attempt -le $max_attempts ]; do
echo "Integration test attempt $attempt of $max_attempts"
# Always cleanup lingering resources before each attempt
bash scripts/ci-cleanup.sh || true
# Additional cleanup only on retries
if [ $attempt -gt 1 ]; then
docker compose -f compose.yaml down -v || true
docker system prune -af --volumes || true
sleep 5
fi
# Run ALL integration tests (everything excluded from PR fast tests)
# These create Docker containers and need significant disk space
if go test -v -p 1 -timeout=120m -count=1 -tags=kwiltest \
./tests/streams/... \
./tests/database_size \
./tests/extensions/erc20 \
./tests/extensions/database-size; then
echo "✅ Integration tests passed on attempt $attempt"
break
else
echo "❌ Integration tests failed on attempt $attempt"
# Surface Docker diagnostics
echo "::group::Docker diagnostics"
docker ps -a || true
docker system df || true
docker info || true
echo "::endgroup::"
if [ $attempt -eq $max_attempts ]; then
echo "All integration test attempts failed"
exit 1
fi
attempt=$((attempt + 1))
echo "Waiting ${backoff}s before retry..."
sleep "$backoff"
backoff=$((backoff * 2))
fi
done