forked from one-covenant/basilica
-
Notifications
You must be signed in to change notification settings - Fork 0
504 lines (472 loc) · 16.5 KB
/
Copy pathci.yml
File metadata and controls
504 lines (472 loc) · 16.5 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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
name: CI
on:
push:
branches: [main, develop]
pull_request:
workflow_dispatch:
inputs:
build_images:
description: Build and push all Docker images
required: false
default: "false"
image_tag:
description: Tag to apply to images when building via workflow_dispatch
required: false
default: "k3_test"
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
RUSTUP_MAX_RETRIES: 10
RUSTFLAGS: "-Clink-arg=-fuse-ld=mold"
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER: "clang"
permissions:
contents: read
pull-requests: read
jobs:
# Detect changes to determine which services need building
changes:
runs-on: blacksmith-32vcpu-ubuntu-2404
outputs:
validator: ${{ steps.changes.outputs.validator }}
miner: ${{ steps.changes.outputs.miner }}
basilica-cli: ${{ steps.changes.outputs.basilica-cli }}
basilica-sdk-python: ${{ steps.changes.outputs.basilica-sdk-python }}
workspace: ${{ steps.changes.outputs.workspace }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v2
id: changes
with:
filters: |
validator:
- 'crates/basilica-validator/**'
- 'crates/basilica-common/**'
- 'crates/basilica-protocol/**'
- 'scripts/validator/**'
- 'Cargo.toml'
- 'Cargo.lock'
miner:
- 'crates/basilica-miner/**'
- 'crates/basilica-common/**'
- 'crates/basilica-protocol/**'
- 'scripts/miner/**'
- 'Cargo.toml'
- 'Cargo.lock'
basilica-cli:
- 'crates/basilica-cli/**'
- 'crates/basilica-common/**'
- 'crates/basilica-protocol/**'
- 'scripts/cli/**'
- 'Cargo.toml'
- 'Cargo.lock'
basilica-sdk-python:
- 'crates/basilica-sdk-python/**'
- 'crates/basilica-sdk/**'
- 'crates/basilica-common/**'
- 'Cargo.toml'
- 'Cargo.lock'
workspace:
- 'Cargo.toml'
- 'Cargo.lock'
- '.github/workflows/**'
quick-checks:
runs-on: blacksmith-32vcpu-ubuntu-2404
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
with:
shared-key: "shared-cache"
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Install protoc
uses: arduino/setup-protoc@v3
with:
version: "25.x"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Cache and install system dependencies
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: pkg-config libssl-dev xxd mold clang python3-dev
version: 1.0
- name: Install cargo-nextest
uses: taiki-e/install-action@v2
with:
tool: nextest
- name: Check formatting
run: cargo fmt --all -- --check
- name: Quick check builds
run: |
cargo check -p basilica-common -p basilica-protocol
- name: Run clippy on core packages
run: |
cargo clippy -p basilica-common -p basilica-protocol --all-targets -- -D warnings
# Lint complex packages
lint-complex:
runs-on: blacksmith-32vcpu-ubuntu-2404
needs: quick-checks
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
with:
shared-key: "shared-cache"
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Install protoc
uses: arduino/setup-protoc@v3
with:
version: "25.x"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Cache and install system dependencies
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: pkg-config libssl-dev xxd mold clang python3-dev
version: 1.0
- name: Install cargo-nextest
uses: taiki-e/install-action@v2
with:
tool: nextest
- name: Run clippy on complex packages
run: |
cargo clippy -p basilica-miner --all-targets --all-features -- -D warnings
cargo clippy -p basilica-validator --all-targets --all-features -- -D warnings
cargo clippy -p basilica-cli --all-targets --all-features -- -D warnings
cargo clippy -p basilica-sdk --all-targets --all-features -- -D warnings
# Build and test validator
build-validator:
runs-on: blacksmith-32vcpu-ubuntu-2404
needs: changes
if: needs.changes.outputs.validator == 'true' || needs.changes.outputs.workspace == 'true'
strategy:
matrix:
rust-version: [stable]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust-version }}
components: rustfmt
- uses: Swatinem/rust-cache@v2
with:
shared-key: "shared-cache"
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Install protoc
uses: arduino/setup-protoc@v3
with:
version: "25.x"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Cache and install system dependencies
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: pkg-config libssl-dev xxd mold clang
version: 1.0
- name: Install cargo-nextest
uses: taiki-e/install-action@v2
with:
tool: nextest
- name: Setup Blacksmith Builder
uses: useblacksmith/setup-docker-builder@v1
- name: Generate test key
run: |
chmod +x scripts/gen-key.sh
./scripts/gen-key.sh
- name: Build and test validator
run: |
export VALIDATOR_PUBLIC_KEY=$(cat public_key.hex)
cargo build -p basilica-validator
cargo nextest run -p basilica-validator --all-features --no-fail-fast
./target/debug/basilica-validator --help
- name: Clean up space before Docker build
run: |
docker system prune -af
df -h
- name: Test Docker build script
run: |
chmod +x scripts/validator/build.sh
BITTENSOR_NETWORK=finney ./scripts/validator/build.sh --no-extract
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: basilica/validator:latest
format: 'table'
severity: 'CRITICAL,HIGH'
exit-code: '0'
trivyignores: '.trivyignore.yaml'
# Build and test miner
build-miner:
runs-on: blacksmith-32vcpu-ubuntu-2404
needs: changes
if: needs.changes.outputs.miner == 'true' || needs.changes.outputs.workspace == 'true'
strategy:
matrix:
rust-version: [stable]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust-version }}
components: rustfmt
- uses: Swatinem/rust-cache@v2
with:
shared-key: "shared-cache"
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Install protoc
uses: arduino/setup-protoc@v3
with:
version: "25.x"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Cache and install system dependencies
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: pkg-config libssl-dev xxd mold clang python3-dev
version: 1.0
- name: Install cargo-nextest
uses: taiki-e/install-action@v2
with:
tool: nextest
- name: Setup Blacksmith Builder
uses: useblacksmith/setup-docker-builder@v1
- name: Generate test key
run: |
chmod +x scripts/gen-key.sh
./scripts/gen-key.sh
- name: Build and test miner
run: |
export VALIDATOR_PUBLIC_KEY=$(cat public_key.hex)
cargo build -p basilica-miner
cargo nextest run -p basilica-miner --lib --no-fail-fast
./target/debug/basilica-miner --help
- name: Clean up space before Docker build
run: |
docker system prune -af
df -h
- name: Test Docker build script
run: |
chmod +x scripts/miner/build.sh
BITTENSOR_NETWORK=finney ./scripts/miner/build.sh --no-extract
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: basilica/miner:latest
format: 'table'
severity: 'CRITICAL,HIGH'
exit-code: '0'
trivyignores: '.trivyignore.yaml'
# Build and test basilica-cli
build-cli:
runs-on: blacksmith-32vcpu-ubuntu-2404
needs: changes
if: needs.changes.outputs.basilica-cli == 'true' || needs.changes.outputs.workspace == 'true'
strategy:
matrix:
rust-version: [stable]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust-version }}
components: rustfmt
- uses: Swatinem/rust-cache@v2
with:
shared-key: "shared-cache"
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Install protoc
uses: arduino/setup-protoc@v3
with:
version: "25.x"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Cache and install system dependencies
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: pkg-config libssl-dev xxd mold clang python3-dev
version: 1.0
- name: Install cargo-nextest
uses: taiki-e/install-action@v2
with:
tool: nextest
- name: Build and test basilica-cli
run: |
cargo build -p basilica-cli
cargo nextest run -p basilica-cli --all-features --no-fail-fast
./target/debug/basilica --help
# Build and test Python SDK
test-python-sdk:
runs-on: blacksmith-32vcpu-ubuntu-2404
needs: changes
if: needs.changes.outputs.basilica-sdk-python == 'true' || needs.changes.outputs.workspace == 'true'
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12', '3.13']
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
shared-key: "shared-cache"
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Install protoc
uses: arduino/setup-protoc@v3
with:
version: "25.x"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Cache and install system dependencies
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: pkg-config libssl-dev xxd mold clang python3-dev
version: 1.0
- name: Create virtual environment
run: python -m venv .venv
- name: Install maturin
run: |
source .venv/bin/activate
pip install maturin pytest pytest-asyncio
- name: Build and install Python SDK
run: |
source .venv/bin/activate
cd crates/basilica-sdk-python
maturin develop --release
- name: Run Python tests
run: |
source .venv/bin/activate
cd crates/basilica-sdk-python
python -m pytest tests/ -v || echo "No tests found yet"
- name: Test examples (syntax check)
run: |
source .venv/bin/activate
cd crates/basilica-sdk-python/examples
for example in *.py; do
echo "Checking $example..."
python -m py_compile "$example"
done
- name: Test import
run: |
source .venv/bin/activate
python -c 'import basilica; print(f"SDK imported successfully. API URL: {basilica.DEFAULT_API_URL}")'
# Final status check
ci-success:
runs-on: blacksmith-32vcpu-ubuntu-2404
needs:
- quick-checks
- lint-complex
- build-validator
- build-miner
- build-cli
- test-python-sdk
if: always()
steps:
- name: Check if all jobs succeeded
run: |
if [[ "${{ needs.quick-checks.result }}" == "success" && \
"${{ needs.lint-complex.result }}" == "success" && \
("${{ needs.build-validator.result }}" == "success" || "${{ needs.build-validator.result }}" == "skipped") && \
("${{ needs.build-miner.result }}" == "success" || "${{ needs.build-miner.result }}" == "skipped") && \
("${{ needs.build-cli.result }}" == "success" || "${{ needs.build-cli.result }}" == "skipped") && \
("${{ needs.test-python-sdk.result }}" == "success" || "${{ needs.test-python-sdk.result }}" == "skipped") ]]; then
echo "All CI checks passed!"
exit 0
else
echo "Some CI checks failed!"
exit 1
fi
# Manual: Build and push all images (workflow_dispatch only)
build-images:
if: |
(github.event_name == 'workflow_dispatch' && github.event.inputs.build_images == 'true') ||
(github.event_name == 'pull_request' && (
contains(github.event.pull_request.title, 'build-images') ||
contains(github.event.pull_request.body, 'build-images') ||
contains(join(github.event.pull_request.labels.*.name, ' '), 'build-images')
))
runs-on: blacksmith-32vcpu-ubuntu-2404
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Blacksmith Builder
uses: useblacksmith/setup-docker-builder@v1
- name: Resolve image tag
shell: bash
run: |
TAG="${{ github.event.inputs.image_tag }}"
if [[ "$TAG" == TAG=* ]]; then TAG="${TAG#TAG=}"; fi
if [[ -z "$TAG" ]]; then TAG="k3_test"; fi
echo "TAG=$TAG" >> $GITHUB_ENV
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build validator image
env:
BITTENSOR_NETWORK: finney
run: |
./scripts/validator/build.sh \
--image-name ghcr.io/one-covenant/basilica/validator \
--image-tag "$TAG" \
--no-extract
- name: Scan validator image
uses: aquasecurity/trivy-action@master
with:
image-ref: ghcr.io/one-covenant/basilica/validator:${{ env.TAG }}
format: 'table'
severity: 'CRITICAL,HIGH'
exit-code: '0'
trivyignores: '.trivyignore.yaml'
- name: Push validator image
run: |
./scripts/validator/push.sh \
--source-image ghcr.io/one-covenant/basilica/validator \
--target-image ghcr.io/one-covenant/basilica/validator \
--tag "$TAG"
- name: Build miner image
env:
BITTENSOR_NETWORK: finney
run: |
./scripts/miner/build.sh \
--image-name ghcr.io/one-covenant/basilica/miner \
--image-tag "$TAG" \
--no-extract
- name: Scan miner image
uses: aquasecurity/trivy-action@master
with:
image-ref: ghcr.io/one-covenant/basilica/miner:${{ env.TAG }}
format: 'table'
severity: 'CRITICAL,HIGH'
exit-code: '0'
trivyignores: '.trivyignore.yaml'
- name: Push miner image
run: |
./scripts/miner/push.sh \
--source-image ghcr.io/one-covenant/basilica/miner \
--target-image ghcr.io/one-covenant/basilica/miner \
--tag "$TAG"
- name: Build CLI image (single-arch)
run: |
./scripts/cli/build.sh \
--single-arch \
--image-name ghcr.io/one-covenant/basilica/cli \
--image-tag "$TAG" \
--no-extract
- name: Scan CLI image
uses: aquasecurity/trivy-action@master
with:
image-ref: ghcr.io/one-covenant/basilica/cli:${{ env.TAG }}
format: 'table'
severity: 'CRITICAL,HIGH'
exit-code: '0'
trivyignores: '.trivyignore.yaml'
- name: Push CLI image
run: |
docker push ghcr.io/one-covenant/basilica/cli:"$TAG"