Debian上Rust项目的持续集成实践
一、方案总览
二、GitHub Actions模板
示例:
name: Rust CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup default stable
- name: Check formatting
run: cargo fmt -- --check
- name: Lint with clippy
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
要点:
三、GitLab CI模板
示例:
stages:
- check
- test
variables:
CARGO_HOME: $CI_PROJECT_DIR/.cargo
before_script:
- rustup toolchain add stable
- rustup default stable
- cargo --version
- rustc --version
fmt:
stage: check
script:
- cargo fmt -- --check
clippy:
stage: check
script:
- cargo clippy --all-targets --all-features -- -D warnings
build:
stage: test
script:
- cargo build --verbose
test:
stage: test
script:
- cargo test --verbose
要点:
四、质量门禁与扩展