vm/.github/workflows/ci.yml

328 lines
8.7 KiB
YAML

name: FVP VM CI/CD Pipeline
on:
push:
branches: [ main, master, develop ]
pull_request:
branches: [ main, master, develop ]
schedule:
# 每天UTC 02:00运行完整测试套件
- cron: '0 2 * * *'
env:
RUST_BACKTRACE: 1
CARGO_TERM_COLOR: always
jobs:
# 代码质量检查
lint:
name: Code Quality
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Check code formatting
run: cargo fmt --all -- --check
- name: Run Clippy
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Check documentation
run: cargo doc --no-deps --all-features --document-private-items
# 单元测试
test:
name: Unit Tests
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
rust: [stable, beta, nightly]
exclude:
# 排除一些组合以节省CI时间
- os: windows-latest
rust: beta
- os: macos-latest
rust: beta
steps:
- uses: actions/checkout@v4
- name: Install Rust (${{ matrix.rust }})
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-${{ matrix.rust }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Build debug
run: cargo build --verbose --all-features
- name: Run unit tests
run: cargo test --verbose --all-features
- name: Run doc tests
run: cargo test --doc --all-features
# 性能测试
performance:
name: Performance Tests
runs-on: ubuntu-latest
needs: [lint, test]
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-performance-${{ hashFiles('**/Cargo.lock') }}
- name: Build release optimized
run: cargo build --release --all-features
- name: Run JIT performance tests
run: cargo test --release --package vm-tests --test jit_performance_tests -- --nocapture
- name: Run TLB performance tests
run: cargo test --release --package vm-tests --test tlb_performance_tests -- --nocapture
- name: Run system performance tests
run: cargo test --release --package vm-tests --test system_performance_tests -- --nocapture
- name: Run parallel performance tests
run: cargo test --release --package vm-tests --test multi_vcpu_performance -- --nocapture
- name: Run performance regression tests
run: cargo test --release --test performance_regression -- --nocapture
continue-on-error: false
- name: Run E2E tests
run: cargo test --release --test e2e_test_suite -- --nocapture
continue-on-error: false
- name: Generate performance report
run: |
echo "## Performance Test Results" > performance-report.md
echo "Generated on: $(date)" >> performance-report.md
echo "" >> performance-report.md
cargo test --release --package vm-tests --all-features -- --format json | jq '.test_results[] | select(.status == "passed") | {name: .test, duration: .duration}' >> performance-report.md
- name: Upload performance report
uses: actions/upload-artifact@v4
with:
name: performance-report
path: performance-report.md
# 集成测试
integration:
name: Integration Tests
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-integration-${{ hashFiles('**/Cargo.lock') }}
- name: Build all packages
run: cargo build --release --all-features
- name: Run integration tests
run: |
# 模拟完整的VM启动和执行流程
echo "Running VM integration tests..."
cargo test --release --package vm-tests --test integration -- --test-threads=1
- name: Run E2E tests
run: cargo test --release --test e2e_test_suite -- --nocapture
continue-on-error: false
- name: Test dashboard build
run: |
cd vm-monitor
cargo check --features dashboard
- name: Test all features
run: cargo test --release --all-features --workspace
# 安全扫描
security:
name: Security Scan
runs-on: ubuntu-latest
needs: [lint]
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Install cargo-audit
run: cargo install cargo-audit
- name: Run security audit
run: cargo audit
- name: Run cargo-deny
uses: EmbarkStudios/cargo-deny-action@v1
- name: Check for secrets
uses: trufflesecurity/trufflehog@main
with:
path: ./
base: main
head: HEAD
# 构建和打包
build:
name: Build Artifacts
runs-on: ${{ matrix.os }}
needs: [performance, integration]
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact: fvp-vm-linux
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact: fvp-vm-windows.exe
- os: macos-latest
target: x86_64-apple-darwin
artifact: fvp-vm-macos
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Build release
run: cargo build --release --target ${{ matrix.target }} --all-features
- name: Strip binary (Unix)
if: matrix.os != 'windows-latest'
run: strip target/${{ matrix.target }}/release/fvp
- name: Package binary
run: |
mkdir -p dist
if [ "${{ matrix.os }}" = "windows-latest" ]; then
cp target/${{ matrix.target }}/release/fvp.exe dist/${{ matrix.artifact }}
else
cp target/${{ matrix.target }}/release/fvp dist/${{ matrix.artifact }}
fi
cp README.md LICENSE dist/
tar -czf ${{ matrix.artifact }}.tar.gz -C dist .
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact }}
path: ${{ matrix.artifact }}.tar.gz
# 发布
release:
name: Release
runs-on: ubuntu-latest
needs: [build, security]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
- name: Create Release
uses: softprops/action-gh-release@v2
with:
files: |
fvp-vm-linux/fvp-vm-linux.tar.gz
fvp-vm-windows.exe/fvp-vm-windows.exe.tar.gz
fvp-vm-macos/fvp-vm-macos.tar.gz
generate_release_notes: true
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# 部署文档
docs:
name: Deploy Documentation
runs-on: ubuntu-latest
needs: [build]
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Generate documentation
run: |
cargo doc --no-deps --all-features --document-private-items
echo "<meta http-equiv='refresh' content='0; url=vm_core/index.html'>" > target/doc/index.html
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./target/doc
destination_dir: docs