-
Notifications
You must be signed in to change notification settings - Fork 24
582 lines (513 loc) · 17.7 KB
/
ci-enhanced.yml
File metadata and controls
582 lines (513 loc) · 17.7 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
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
name: Enhanced CI/CD Pipeline
on:
push:
branches: [ main, develop ]
tags: [ 'v*' ]
pull_request:
branches: [ main, develop ]
schedule:
# Run security audit daily at 2 AM UTC
- cron: '0 2 * * *'
workflow_dispatch:
inputs:
rust_version:
description: 'Rust version to test'
required: false
default: 'stable'
type: choice
options:
- stable
- beta
- nightly
- '1.70.0'
- '1.75.0'
- '1.80.0'
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
RUSTUP_MAX_RETRIES: 10
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# Pre-check job for basic validation
pre-check:
name: Pre-flight Checks
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
has-changes: ${{ steps.changes.outputs.has-changes }}
should-test: ${{ steps.changes.outputs.should-test }}
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Check for relevant changes
id: changes
run: |
if [[ "${{ github.event_name }}" == "schedule" || "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "has-changes=true" >> $GITHUB_OUTPUT
echo "should-test=true" >> $GITHUB_OUTPUT
exit 0
fi
# Check for Rust/Cargo changes
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }}..${{ github.sha }} 2>/dev/null || git diff --name-only HEAD~1..HEAD)
if echo "$CHANGED_FILES" | grep -qE '\.(rs|toml)$|^\.github/workflows/|Dockerfile|\.dockerignore$'; then
echo "has-changes=true" >> $GITHUB_OUTPUT
echo "should-test=true" >> $GITHUB_OUTPUT
else
echo "has-changes=false" >> $GITHUB_OUTPUT
echo "should-test=false" >> $GITHUB_OUTPUT
fi
- name: Validate workflow files
run: |
# Basic YAML validation
for file in .github/workflows/*.yml .github/workflows/*.yaml; do
if [ -f "$file" ]; then
echo "Validating $file"
python3 -c "import yaml; yaml.safe_load(open('$file'))"
fi
done
# Security audit job
security-audit:
name: Security Audit
runs-on: ubuntu-latest
timeout-minutes: 15
needs: pre-check
if: needs.pre-check.outputs.should-test == 'true'
outputs:
audit-passed: ${{ steps.audit.outcome == 'success' }}
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
- name: Install cargo-audit
run: cargo install cargo-audit --locked
- name: Cache Cargo audit database
uses: actions/cache@v4
with:
path: ~/.cargo/advisory-db
key: cargo-audit-db-${{ github.run_id }}
restore-keys: cargo-audit-db-
- name: Run security audit
id: audit
run: |
echo "Running security audit..."
if ! cargo audit --deny warnings --deny unmaintained --deny unsound --deny yanked; then
echo "Security audit failed! Check the output above for vulnerabilities."
echo "audit-result=failed" >> $GITHUB_OUTPUT
exit 1
else
echo "Security audit passed!"
echo "audit-result=passed" >> $GITHUB_OUTPUT
fi
- name: Generate audit report
if: always()
run: |
cargo audit --json > audit-report.json || true
echo "## Security Audit Report" >> $GITHUB_STEP_SUMMARY
if [ -f audit-report.json ] && [ -s audit-report.json ]; then
echo "```json" >> $GITHUB_STEP_SUMMARY
cat audit-report.json >> $GITHUB_STEP_SUMMARY
echo "```" >> $GITHUB_STEP_SUMMARY
else
echo "No security issues found." >> $GITHUB_STEP_SUMMARY
fi
- name: Upload audit report
if: always()
uses: actions/upload-artifact@v5
with:
name: security-audit-report
path: audit-report.json
retention-days: 30
# Matrix testing job
test-matrix:
name: Test Suite
runs-on: ${{ matrix.os }}
timeout-minutes: 45
needs: [pre-check, security-audit]
if: needs.pre-check.outputs.should-test == 'true'
strategy:
fail-fast: false
matrix:
include:
# Stable Rust on all platforms
- os: ubuntu-latest
rust: stable
target: x86_64-unknown-linux-gnu
features: ''
- os: ubuntu-latest
rust: stable
target: x86_64-unknown-linux-gnu
features: '--all-features'
- os: windows-latest
rust: stable
target: x86_64-pc-windows-msvc
features: ''
- os: macos-latest
rust: stable
target: x86_64-apple-darwin
features: ''
# Beta Rust (Linux only)
- os: ubuntu-latest
rust: beta
target: x86_64-unknown-linux-gnu
features: ''
# Nightly Rust (Linux only, allow failures)
- os: ubuntu-latest
rust: nightly
target: x86_64-unknown-linux-gnu
features: ''
experimental: true
# MSRV (Minimum Supported Rust Version)
- os: ubuntu-latest
rust: '1.70.0'
target: x86_64-unknown-linux-gnu
features: ''
continue-on-error: ${{ matrix.experimental == true }}
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Install Rust ${{ matrix.rust }}
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
targets: ${{ matrix.target }}
components: rustfmt, clippy
- name: Install system dependencies (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y build-essential pkg-config libssl-dev protobuf-compiler
- name: Install system dependencies (macOS)
if: matrix.os == 'macos-latest'
run: |
brew install pkg-config protobuf
- name: Install system dependencies (Windows)
if: matrix.os == 'windows-latest'
run: |
choco install protoc
- name: Setup Cargo cache
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ matrix.rust }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-${{ matrix.rust }}-
${{ runner.os }}-cargo-
- name: Check formatting (stable only)
if: matrix.rust == 'stable' && matrix.os == 'ubuntu-latest' && matrix.features == ''
run: cargo fmt --all -- --check
- name: Run Clippy
if: matrix.rust == 'stable' || matrix.rust == 'beta'
run: |
if [ -n "${{ matrix.features }}" ]; then
cargo clippy --workspace --all-targets ${{ matrix.features }} --target ${{ matrix.target }} -- -D warnings -W clippy::pedantic
else
cargo clippy --workspace --all-targets --target ${{ matrix.target }} -- -D warnings -W clippy::pedantic
fi
- name: Build
run: |
if [ -n "${{ matrix.features }}" ]; then
cargo build --workspace --target ${{ matrix.target }} ${{ matrix.features }} --verbose
else
cargo build --workspace --target ${{ matrix.target }} --verbose
fi
- name: Run tests
run: |
if [ -n "${{ matrix.features }}" ]; then
cargo test --workspace --target ${{ matrix.target }} ${{ matrix.features }} --verbose
else
cargo test --workspace --target ${{ matrix.target }} --verbose
fi
- name: Run doc tests
if: matrix.target == 'x86_64-unknown-linux-gnu'
run: |
if [ -n "${{ matrix.features }}" ]; then
cargo test --workspace --doc ${{ matrix.features }}
else
cargo test --workspace --doc
fi
# Code coverage job
coverage:
name: Code Coverage
runs-on: ubuntu-latest
timeout-minutes: 30
needs: [pre-check, security-audit]
if: needs.pre-check.outputs.should-test == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools-preview
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential pkg-config libssl-dev protobuf-compiler
- name: Setup Cargo cache
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ubuntu-latest-cargo-coverage-${{ hashFiles('**/Cargo.lock') }}
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Generate code coverage
run: |
cargo llvm-cov --workspace --lcov --output-path lcov.info --ignore-filename-regex "(tests?/|benches?/|examples?/)"
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: lcov.info
fail_ci_if_error: false # Don't fail CI on codecov issues
verbose: true
# Advanced linting job
advanced-linting:
name: Advanced Linting
runs-on: ubuntu-latest
timeout-minutes: 20
needs: [pre-check, security-audit]
if: needs.pre-check.outputs.should-test == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Install additional tools
run: |
cargo install cargo-machete cargo-udeps --locked
- name: Setup Cargo cache
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ubuntu-latest-cargo-linting-${{ hashFiles('**/Cargo.lock') }}
- name: Check for unused dependencies
run: |
echo "## Unused Dependencies Check" >> $GITHUB_STEP_SUMMARY
cargo machete --with-metadata || true
- name: Check for unnecessary dependencies (nightly required)
continue-on-error: true
run: |
# Install nightly for cargo-udeps
rustup toolchain install nightly
cargo +nightly udeps --workspace || echo "cargo-udeps check failed (requires nightly features)"
# Build release artifacts
build-release:
name: Build Release
runs-on: ${{ matrix.os }}
timeout-minutes: 45
needs: [test-matrix]
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact_name: codegraph-linux-amd64
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact_name: codegraph-windows-amd64.exe
- os: macos-latest
target: x86_64-apple-darwin
artifact_name: codegraph-macos-amd64
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install system dependencies (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y build-essential pkg-config libssl-dev protobuf-compiler
- name: Install system dependencies (macOS)
if: matrix.os == 'macos-latest'
run: |
brew install pkg-config protobuf
- name: Install system dependencies (Windows)
if: matrix.os == 'windows-latest'
run: |
choco install protoc
- name: Setup Cargo cache
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }}
- name: Build release
run: |
cargo build --workspace --release --target ${{ matrix.target }}
- name: Run release tests
run: |
cargo test --workspace --release --target ${{ matrix.target }}
- name: Prepare release artifacts
run: |
mkdir -p release-artifacts
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
cp target/${{ matrix.target }}/release/codegraph-api.exe release-artifacts/${{ matrix.artifact_name }}
else
cp target/${{ matrix.target }}/release/codegraph-api release-artifacts/${{ matrix.artifact_name }}
fi
- name: Upload release artifacts
uses: actions/upload-artifact@v5
with:
name: release-${{ matrix.target }}
path: release-artifacts/
retention-days: 7
# Docker build and push job
docker:
name: Docker Build & Push
runs-on: ubuntu-latest
timeout-minutes: 30
needs: [test-matrix, security-audit]
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: ghcr.io/${{ github.repository }}:${{ github.sha }}
format: sarif
output: trivy-results.sarif
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: trivy-results.sarif
# Benchmark job (if benchmarks exist)
benchmark:
name: Performance Benchmarks
runs-on: ubuntu-latest
timeout-minutes: 30
needs: [test-matrix]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential pkg-config libssl-dev protobuf-compiler
- name: Setup Cargo cache
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ubuntu-latest-cargo-bench-${{ hashFiles('**/Cargo.lock') }}
- name: Run benchmarks
run: |
if find . -name "*.rs" -path "*/benches/*" | grep -q .; then
echo "Running benchmarks..."
cargo bench --workspace 2>&1 | tee benchmark-results.txt
else
echo "No benchmarks found, skipping..."
touch benchmark-results.txt
fi
- name: Upload benchmark results
uses: actions/upload-artifact@v5
with:
name: benchmark-results
path: benchmark-results.txt
retention-days: 30
# Summary job
ci-success:
name: CI Success
runs-on: ubuntu-latest
timeout-minutes: 5
needs: [pre-check, security-audit, test-matrix, coverage, advanced-linting]
if: always()
steps:
- name: Check job results
run: |
echo "## CI/CD Pipeline Results" >> $GITHUB_STEP_SUMMARY
echo "| Job | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-----|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Pre-checks | ${{ needs.pre-check.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Security Audit | ${{ needs.security-audit.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Test Matrix | ${{ needs.test-matrix.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Coverage | ${{ needs.coverage.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Advanced Linting | ${{ needs.advanced-linting.result }} |" >> $GITHUB_STEP_SUMMARY
# Check if any required job failed
if [[ "${{ needs.security-audit.result }}" == "failure" ]] ||
[[ "${{ needs.test-matrix.result }}" == "failure" ]]; then
echo "❌ CI pipeline failed - check individual job results above"
exit 1
else
echo "✅ CI pipeline completed successfully"
fi
- name: Report status to dev guild
if: always()
run: |
status="${{ job.status }}"
if [[ "$status" == "success" ]]; then
echo "CI/CD pipeline completed successfully for ${{ github.ref }}"
else
echo "CI/CD pipeline failed for ${{ github.ref }}"
fi